diff --git a/Generals/Code/GameEngine/Include/Common/GameMemory.h b/Generals/Code/GameEngine/Include/Common/GameMemory.h index 03dd4d109a9..bef6f4208ba 100644 --- a/Generals/Code/GameEngine/Include/Common/GameMemory.h +++ b/Generals/Code/GameEngine/Include/Common/GameMemory.h @@ -758,7 +758,8 @@ class MemoryPoolObject void deleteInstance() { - if (this) + void * volatile checkThisPtr = this; // mitigate undefined behavior because this function is called on nullptrs + if (checkThisPtr) { MemoryPool *pool = this->getObjectMemoryPool(); // save this, since the dtor will nuke our vtbl this->~MemoryPoolObject(); // it's virtual, so the right one will be called. diff --git a/GeneralsMD/Code/GameEngine/Include/Common/GameMemory.h b/GeneralsMD/Code/GameEngine/Include/Common/GameMemory.h index 95c5ff12d0e..66fa0b59085 100644 --- a/GeneralsMD/Code/GameEngine/Include/Common/GameMemory.h +++ b/GeneralsMD/Code/GameEngine/Include/Common/GameMemory.h @@ -757,7 +757,8 @@ class MemoryPoolObject void deleteInstance() { - if (this) + void * volatile checkThisPtr = this; // mitigate undefined behavior because this function is called on nullptrs + if (checkThisPtr) { MemoryPool *pool = this->getObjectMemoryPool(); // save this, since the dtor will nuke our vtbl this->~MemoryPoolObject(); // it's virtual, so the right one will be called.