Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dangling raw_ptr in OSRWHV destructor #41088

Merged
merged 1 commit into from Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 6 additions & 7 deletions shell/browser/osr/osr_render_widget_host_view.cc
Expand Up @@ -187,6 +187,12 @@ OffScreenRenderWidgetHostView::OffScreenRenderWidgetHostView(
frame_rate_(frame_rate),
size_(initial_size),
painting_(painting),
delegated_frame_host_client_{
std::make_unique<ElectronDelegatedFrameHostClient>(this)},
delegated_frame_host_{std::make_unique<content::DelegatedFrameHost>(
AllocateFrameSinkId(),
delegated_frame_host_client_.get(),
true /* should_register_frame_sink_id */)},
cursor_manager_(std::make_unique<content::CursorManager>(this)),
mouse_wheel_phase_handler_(this),
backing_(std::make_unique<SkBitmap>()) {
Expand All @@ -205,12 +211,6 @@ OffScreenRenderWidgetHostView::OffScreenRenderWidgetHostView(
compositor_allocator_.GenerateId();
compositor_surface_id_ = compositor_allocator_.GetCurrentLocalSurfaceId();

delegated_frame_host_client_ =
std::make_unique<ElectronDelegatedFrameHostClient>(this);
delegated_frame_host_ = std::make_unique<content::DelegatedFrameHost>(
AllocateFrameSinkId(), delegated_frame_host_client_.get(),
true /* should_register_frame_sink_id */);

root_layer_ = std::make_unique<ui::Layer>(ui::LAYER_SOLID_COLOR);

bool opaque = SkColorGetA(background_color_) == SK_AlphaOPAQUE;
Expand Down Expand Up @@ -247,7 +247,6 @@ OffScreenRenderWidgetHostView::~OffScreenRenderWidgetHostView() {
content::DelegatedFrameHost::HiddenCause::kOther);
delegated_frame_host_->DetachFromCompositor();

delegated_frame_host_.reset();
compositor_.reset();
root_layer_.reset();
Comment on lines 250 to 251
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do these two calls need to be explicit in the destructor ?

Copy link
Member Author

@ckerr ckerr Jan 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@deepak1556 good catch, I was going to remove them for that reason: you're right, they're entirely redundant.

I decided to leave them alone here because it's a little off-topic for this bugfix PR, and I have another cleanup PR in mind where it's a better fit.

}
Expand Down
13 changes: 9 additions & 4 deletions shell/browser/osr/osr_render_widget_host_view.h
Expand Up @@ -279,17 +279,22 @@ class OffScreenRenderWidgetHostView : public content::RenderWidgetHostViewBase,
viz::ParentLocalSurfaceIdAllocator compositor_allocator_;

std::unique_ptr<ui::Layer> root_layer_;

// depends-on: root_layer_
std::unique_ptr<ui::Compositor> compositor_;
std::unique_ptr<content::DelegatedFrameHost> delegated_frame_host_;

// depends-on: render_widget_host_, root_layer_
const std::unique_ptr<ElectronDelegatedFrameHostClient>
delegated_frame_host_client_;

// depends-on: delegated_frame_host_client_
const std::unique_ptr<content::DelegatedFrameHost> delegated_frame_host_;

std::unique_ptr<content::CursorManager> cursor_manager_;

raw_ptr<OffScreenHostDisplayClient> host_display_client_;
std::unique_ptr<OffScreenVideoConsumer> video_consumer_;

std::unique_ptr<ElectronDelegatedFrameHostClient>
delegated_frame_host_client_;

content::MouseWheelPhaseHandler mouse_wheel_phase_handler_;

// Latest capture sequence number which is incremented when the caller
Expand Down