diff --git a/ui/aura/window.cc b/ui/aura/window.cc index c61f31605f309..81923cf2a2d13 100644 --- a/ui/aura/window.cc +++ b/ui/aura/window.cc @@ -184,10 +184,20 @@ class ScopedCursorHider { // Update the device scale factor of the cursor client only when the last // mouse location is on this root window. if (hid_cursor_) { + // On X11, GetDisplayNearestWindow() reaches + // X11Window::GetBoundsInPixels() which may synchronously dispatch + // pending X events and destroy the root window (and with it the + // CursorClient it owns). Guard against that by tracking |window_| and + // re-resolving the CursorClient after the call returns. + WindowTracker tracker; + tracker.Add(window_); + const display::Display& display = + display::Screen::Get()->GetDisplayNearestWindow(window_); + if (tracker.windows().empty()) { + return; + } client::CursorClient* cursor_client = client::GetCursorClient(window_); if (cursor_client) { - const display::Display& display = - display::Screen::Get()->GetDisplayNearestWindow(window_); cursor_client->SetDisplay(display); cursor_client->ShowCursor(); }