Skip to content

WIP: wgl: fix DLL unload crash

Erik Faye-Lund requested to merge kusma/mesa:wgl-fix_dll_unload_crash into master

We currently fail to deinitialize all threads that we've set up window-hooks for when a multi-threaded WGL application unloads mesa's opengl32.dll. The Quake 3 Arena engine does this, and we currently suffer a crash at exit as a result, because we still have a window-hook installed that points to code in the unloaded DLL, and gets called.

It's tricky to fix this in the obvious way, because TLS-values needs to be get and set from their respective thread. There's simply no Win32 API to get the TLS values for a given thread-id. Which sorta makes sense; things that were otherwise thread-safe might no longer be thread-safe if such an API was called.

So instead, let's turn this around and simply install a hook that applies to all threads. It's not like we do anything thread-specific with these hooks anyway. This massively simplifies things, and simply makes the problem go away.

/cc @jenatali @brianp @sroland @jrfonseca

WIP because it needs to be completely reworked, see comments ;)

Edited by Erik Faye-Lund

Merge request reports