Move the GFX_LOCK/GFX_UNLOCK call for disposing into disposable.h.

It's currently not (much of) a problem because few or no games use multiple threads, but I believe that ruby can run its garbage collector while the GVL is released, which means that Graphics.update and Graphics.wait are currently not thread safe.

Moving the call to GFX_LOCK into dispose() should fix this.
This commit is contained in:
Wayward Heart 2024-05-23 04:16:47 -05:00
parent 477162d1d3
commit 23e9f6cb1c
2 changed files with 10 additions and 9 deletions

View file

@ -36,13 +36,7 @@ RB_METHOD(disposableDispose)
if (!d)
return Qnil;
/* Nothing to do if already disposed */
if (d->isDisposed())
return Qnil;
GFX_LOCK;
d->dispose();
GFX_UNLOCK;
return Qnil;
}

View file

@ -50,9 +50,16 @@ public:
if (disposed)
return;
releaseResources();
disposed = true;
wasDisposed();
GFX_LOCK;
try {
releaseResources();
disposed = true;
wasDisposed();
} catch (Exception &e) {
GFX_UNLOCK;
throw e;
}
GFX_UNLOCK;
}
bool isDisposed() const