diff --git a/ui/ozone/platform/x11/x11_window.cc b/ui/ozone/platform/x11/x11_window.cc index eddc5aee9e633..faa43761a6894 100644 --- a/ui/ozone/platform/x11/x11_window.cc +++ b/ui/ozone/platform/x11/x11_window.cc @@ -540,10 +540,19 @@ void X11Window::SetBoundsInPixels(const gfx::Rect& bounds) { gfx::Rect new_bounds_in_pixels(bounds.origin(), AdjustSizeForDisplay(bounds.size())); + // GetBoundsInPixels() may synchronously dispatch X11 replies via + // GeometryCache::GetBoundsPx() → DispatchNow(), which can re-enter the + // delegate and delete |this| (see crbug.com/1068755). Guard with a weak + // pointer and bail out if that happens. + auto weak_this = weak_ptr_factory_.GetWeakPtr(); + const gfx::Rect current_bounds = GetBoundsInPixels(); + if (!weak_this) { + return; + } const bool size_changed = - GetBoundsInPixels().size() != new_bounds_in_pixels.size(); + current_bounds.size() != new_bounds_in_pixels.size(); const bool origin_changed = - GetBoundsInPixels().origin() != new_bounds_in_pixels.origin(); + current_bounds.origin() != new_bounds_in_pixels.origin(); // Assume that the resize will go through as requested, which should be the // case if we're running without a window manager. If there's a window