Close the stop and pause results the recorder gets from MediaCapture - #3431
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reported by crash telemetry on 12.10.5.0 (X64), on the finalizer thread.
Cause
OpusRecorder.StopAsyncstops the recording withLowLagMediaRecording.StopWithResultAsync,reads
RecordDurationoff theMediaCaptureStopResultand drops it, then disposesMediaCapturein the samefinally. The result is never closed, so it stays alive until theGC gets to it, and with it the
VideoFrameit owns — a wrapper over a sample from the capturepipeline's pool.
When the finalizer eventually releases the async operation that still held the result, the
whole chain is destroyed: the result, the video frame, its property set, and finally the
Media Foundation sample. Clearing the sample's attributes calls
Releasethrough a vtablethat belonged to the capture pipeline — long since torn down — and the read faults. The fault
address is in the image range, not the heap: the object's memory was still readable, its
vtable's module was not.
The report's log agrees with the stack. A video message was recorded and discarded, and the
crash landed 160 seconds later with nothing in between but a periodic timer — a delay only the
GC explains.
MediaCapturePauseResultis the same object with the same owner and the samelast frame, so it has the same problem.
Fix
Read the duration, close the last frame and close the result, while the device is still open.
Both result types are
IClosableprecisely so this doesn't have to wait for a finalizer; thelast frame is the only thing either of them owns, and nothing here ever wanted it.
StopAsyncandPauseAsyncnow hand back aTimeSpan?rather than the projection, so thereis no result left for a caller to leak.
Not built: no UWP/.NET Native build environment here. The file parses clean under Roslyn,
which catches typos and nothing more.