diff --git a/ui/ozone/platform/wayland/host/wayland_popup.cc b/ui/ozone/platform/wayland/host/wayland_popup.cc index c19d680a1ae84..cde6259e25461 100644 --- a/ui/ozone/platform/wayland/host/wayland_popup.cc +++ b/ui/ozone/platform/wayland/host/wayland_popup.cc @@ -180,7 +180,16 @@ void WaylandPopup::SetBoundsInDIP(const gfx::Rect& bounds_dip) { } auto old_bounds_dip = GetBoundsInDIP(); + // WaylandWindow::SetBoundsInDIP() synchronously dispatches + // delegate()->OnStateUpdate(), which may delete |this| (e.g. an observer + // closes the popup during its own bounds-change notification). Guard with a + // weak pointer, mirroring MaybeApplyLatestStateRequest() and the sibling + // HeadlessWindow backend. + auto weak_this = weak_ptr_factory_.GetWeakPtr(); WaylandWindow::SetBoundsInDIP(bounds_dip); + if (!weak_this) { + return; + } // The shell popup can be null if bounds are being fixed during // the initialization. See WaylandPopup::CreateShellPopup.