mirror of
https://github.com/melonDS-emu/melonDS.git
synced 2025-07-24 14:49:53 -06:00
Make the NDS teardown more robust (#1798)
* Make cleanup a little more robust to mitigate undefined behavior - Add some null checks before cleaning up the GPU3D renderer - Make sure that all deleted objects are null - Move cleanup logic out of an assert call - Note that deleting a null pointer is a no-op, so there's no need to check for null beforehand - Use RAII for GLCompositor instead of Init/DeInit methods * Replace a DeInit call that I missed * Make ARMJIT_Memory less likely to generate errors - Set FastMem7/9Start to nullptr at the end - Only close and unmap the file if it's initialized * Make Renderer3D manage its resources with RAII * Don't try to deallocate frontend resources that aren't loaded * Make ARMJIT_Memory::DeInit more robust on the Switch * Reset MemoryFile on Windows to INVALID_HANDLE_VALUE, not nullptr - There is a difference * Don't explicitly store a Valid state in GLCompositor or the 3D renderers - Instead, create them with static methods while making the actual constructors private * Make initialization of OpenGL resources fail if OpenGL isn't loaded * assert that OpenGL is loaded instead of returning failure
This commit is contained in:

committed by
GitHub

parent
1aaf22d181
commit
db963aa002
@ -334,12 +334,17 @@ void Init()
|
||||
void DeInit()
|
||||
{
|
||||
if (audioDevice) SDL_CloseAudioDevice(audioDevice);
|
||||
audioDevice = 0;
|
||||
MicClose();
|
||||
|
||||
SDL_DestroyCond(audioSync);
|
||||
SDL_DestroyMutex(audioSyncLock);
|
||||
if (audioSync) SDL_DestroyCond(audioSync);
|
||||
audioSync = nullptr;
|
||||
|
||||
if (audioSyncLock) SDL_DestroyMutex(audioSyncLock);
|
||||
audioSyncLock = nullptr;
|
||||
|
||||
if (micWavBuffer) delete[] micWavBuffer;
|
||||
micWavBuffer = nullptr;
|
||||
}
|
||||
|
||||
void AudioSync()
|
||||
|
@ -297,16 +297,21 @@ bool Init()
|
||||
|
||||
void DeInit()
|
||||
{
|
||||
MPQueue->lock();
|
||||
MPQueueHeader* header = (MPQueueHeader*)MPQueue->data();
|
||||
header->ConnectedBitmask &= ~(1 << InstanceID);
|
||||
header->InstanceBitmask &= ~(1 << InstanceID);
|
||||
header->NumInstances--;
|
||||
MPQueue->unlock();
|
||||
if (MPQueue)
|
||||
{
|
||||
MPQueue->lock();
|
||||
MPQueueHeader* header = (MPQueueHeader*)MPQueue->data();
|
||||
header->ConnectedBitmask &= ~(1 << InstanceID);
|
||||
header->InstanceBitmask &= ~(1 << InstanceID);
|
||||
header->NumInstances--;
|
||||
MPQueue->unlock();
|
||||
|
||||
SemPoolDeinit();
|
||||
SemPoolDeinit();
|
||||
|
||||
MPQueue->detach();
|
||||
MPQueue->detach();
|
||||
}
|
||||
|
||||
MPQueue = nullptr;
|
||||
delete MPQueue;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user