Fix T99078: Crash closing the file selector in Wayland

Ensure wayland handlers run that clear the window immediately after
the window has been removed so dangling pointers to the window
aren't left set.
This commit is contained in:
Campbell Barton 2022-06-22 13:08:55 +10:00
parent c08fda3a6b
commit 8fab580949
Notes: blender-bot 2023-02-14 01:11:05 +01:00
Referenced by issue #99078, Closing the file selector crashes with Wayland
1 changed files with 14 additions and 0 deletions

View File

@ -586,6 +586,20 @@ GHOST_WindowWayland::~GHOST_WindowWayland()
xdg_surface_destroy(w->xdg_surface);
wl_surface_destroy(w->wl_surface);
/* NOTE(@campbellbarton): This is needed so the appropriate handlers event
* (#wl_surface_listener.leave in particular) run to prevent access to the freed surfaces.
* Without this round-trip, calling #getCursorPosition immediately after closing a window
* causes dangling #wl_surface pointers to be accessed
* (since the window is used for scaling the cursor position).
*
* An alternative solution would be to clear all internal pointers that reference this window.
* Even though this is reasonable it introduces a 3rd state that needs to be accounted for,
* where values are cleared before they have been set to their new values.
* Any information requested in this state (such as the cursor position) won't be valid and
* could cause difficult to reproduce bugs. So perform a round-trip as closing a window isn't
* an action that runs continuously & isn't likely to cause unnecessary overhead. See: T99078. */
wl_display_roundtrip(m_system->display());
delete w;
}