-
- pipe_mutex_lock( stw_dev->ctx_mutex );
- {
- /* Ensure all contexts are destroyed */
- i = handle_table_get_first_handle(stw_dev->ctx_table);
- while (i) {
- DrvDeleteContext(i);
- i = handle_table_get_next_handle(stw_dev->ctx_table, i);
- }
- handle_table_destroy(stw_dev->ctx_table);
+
+ /*
+ * Abort cleanup if there are still active contexts. In some situations
+ * this DLL may be unloaded before the DLL that is using GL contexts is.
+ */
+ stw_lock_contexts(stw_dev);
+ dhglrc = handle_table_get_first_handle(stw_dev->ctx_table);
+ stw_unlock_contexts(stw_dev);
+ if (dhglrc) {
+ debug_printf("%s: contexts still active -- cleanup aborted\n", __FUNCTION__);
+ stw_dev = NULL;
+ return;