diff --git a/ui/ozone/platform/x11/x11_window.cc b/ui/ozone/platform/x11/x11_window.cc index b4c92dd8f3b15..85d8172299c08 100644 --- a/ui/ozone/platform/x11/x11_window.cc +++ b/ui/ozone/platform/x11/x11_window.cc @@ -1381,8 +1381,14 @@ void X11Window::DispatchUiEvent(ui::Event* event, const x11::Event& xev) { auto* window_manager = X11WindowManager::GetInstance(); DCHECK(window_manager); - // Process X11-specific bits + // Process X11-specific bits. HandleEvent → OnCrossingEvent/OnFocusEvent → + // OnActivationChanged can synchronously close the widget and destroy |this| + // (see DesktopWindowTreeHostPlatform::OnActivationChanged). + auto weak_this = weak_ptr_factory_.GetWeakPtr(); HandleEvent(xev); + if (!weak_this) { + return; + } x11::Event last_xev; std::unique_ptr last_motion;