diff --git a/modules/desktop_capture/linux/screen_capturer_x11.cc b/modules/desktop_capture/linux/screen_capturer_x11.cc index 63c5abfff8..1b17071411 100644 --- a/modules/desktop_capture/linux/screen_capturer_x11.cc +++ b/modules/desktop_capture/linux/screen_capturer_x11.cc @@ -243,7 +243,7 @@ void ScreenCapturerX11::CaptureFrame() { return; } - // If the current frame is from an older generation then allocate a new one. + // Allocate the current frame buffer only if it is not already allocated. // Note that we can't reallocate other buffers at this point, since the caller // may still be reading from them. if (!queue_.current_frame()) { @@ -293,6 +293,12 @@ bool ScreenCapturerX11::GetSourceList(SourceList* sources) { } bool ScreenCapturerX11::SelectSource(SourceId id) { + // Prevent the reuse of any frame buffers allocated for a previously selected + // source. This is required to stop crashes, or old data from appearing in + // a captured frame, when the new source is sized differently then the source + // that was selected at the time a reused frame buffer was created. + queue_.Reset(); + if (!use_randr_ || id == kFullDesktopScreenId) { selected_monitor_name_ = kFullDesktopScreenId; selected_monitor_rect_ =