[Scummvm-git-logs] scummvm master -> 9cd2deb3203ae271d2e6938b848ce2c61c26b9c6

grisenti noreply at scummvm.org
Mon Jan 30 22:04:31 UTC 2023


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
9cd2deb320 HPL1: fix global destructor warning


Commit: 9cd2deb3203ae271d2e6938b848ce2c61c26b9c6
    https://github.com/scummvm/scummvm/commit/9cd2deb3203ae271d2e6938b848ce2c61c26b9c6
Author: grisenti (emanuele at grisenti.net)
Date: 2023-01-30T23:04:17+01:00

Commit Message:
HPL1: fix global destructor warning

Changed paths:
    engines/hpl1/engine/impl/LowLevelPhysicsNewton.cpp
    engines/hpl1/engine/libraries/newton/Newton.cpp
    engines/hpl1/engine/libraries/newton/Newton.h
    engines/hpl1/engine/libraries/newton/core/dgMemory.cpp
    engines/hpl1/engine/libraries/newton/core/dgMemory.h


diff --git a/engines/hpl1/engine/impl/LowLevelPhysicsNewton.cpp b/engines/hpl1/engine/impl/LowLevelPhysicsNewton.cpp
index 5b8ee16d9dd..0874ff26404 100644
--- a/engines/hpl1/engine/impl/LowLevelPhysicsNewton.cpp
+++ b/engines/hpl1/engine/impl/LowLevelPhysicsNewton.cpp
@@ -39,11 +39,13 @@ namespace hpl {
 //-----------------------------------------------------------------------
 
 cLowLevelPhysicsNewton::cLowLevelPhysicsNewton() {
+	NewtonInitGlobals();
 }
 
 //-----------------------------------------------------------------------
 
 cLowLevelPhysicsNewton::~cLowLevelPhysicsNewton() {
+	NewtonDestroyGlobals();
 }
 
 //-----------------------------------------------------------------------
diff --git a/engines/hpl1/engine/libraries/newton/Newton.cpp b/engines/hpl1/engine/libraries/newton/Newton.cpp
index 795451e8ecc..58171c64580 100644
--- a/engines/hpl1/engine/libraries/newton/Newton.cpp
+++ b/engines/hpl1/engine/libraries/newton/Newton.cpp
@@ -24,6 +24,15 @@
 #include "NewtonClass.h"
 #include "NewtonStdAfx.h"
 
+void NewtonInitGlobals() {
+	dgInitMemoryGlobals();
+}
+
+void NewtonDestroyGlobals() {
+	dgDestroyMemoryGlobals();
+}
+
+
 #ifdef _WIN32
 #ifdef _DEBUG
 //#define DG_USED_DEBUG_EXCEPTIONS
diff --git a/engines/hpl1/engine/libraries/newton/Newton.h b/engines/hpl1/engine/libraries/newton/Newton.h
index c918d5b1a4e..30beb420b48 100644
--- a/engines/hpl1/engine/libraries/newton/Newton.h
+++ b/engines/hpl1/engine/libraries/newton/Newton.h
@@ -323,6 +323,10 @@ typedef void (*NewtonConstraintDestructor)(const NewtonJoint *const  me);
 //	typedef void (*NewtonVehicleTireUpdate) (const NewtonJoint* const vehicle, dFloat timestep);
 
 
+void NewtonInitGlobals();
+
+void NewtonDestroyGlobals();
+
 // **********************************************************************************************
 //
 // world control functions
diff --git a/engines/hpl1/engine/libraries/newton/core/dgMemory.cpp b/engines/hpl1/engine/libraries/newton/core/dgMemory.cpp
index 225d650d2fa..7209e7b8253 100644
--- a/engines/hpl1/engine/libraries/newton/core/dgMemory.cpp
+++ b/engines/hpl1/engine/libraries/newton/core/dgMemory.cpp
@@ -58,17 +58,26 @@ public:
 		return mem;
 	}
 
-	static dgGlobalAllocator m_globalAllocator;
+	static dgGlobalAllocator *m_globalAllocator;
 };
 
-dgGlobalAllocator dgGlobalAllocator::m_globalAllocator;
+dgGlobalAllocator *dgGlobalAllocator::m_globalAllocator = nullptr;
+
+void dgInitMemoryGlobals() {
+	dgGlobalAllocator::m_globalAllocator = ::new dgGlobalAllocator();
+}
+
+void dgDestroyMemoryGlobals() {
+	::delete dgGlobalAllocator::m_globalAllocator;
+}
+
 
 dgMemoryAllocator::dgMemoryAllocator() {
 	m_memoryUsed = 0;
 	m_emumerator = 0;
-	SetAllocatorsCallback(dgGlobalAllocator::m_globalAllocator.m_malloc, dgGlobalAllocator::m_globalAllocator.m_free);
+	SetAllocatorsCallback(dgGlobalAllocator::m_globalAllocator->m_malloc, dgGlobalAllocator::m_globalAllocator->m_free);
 	memset(m_memoryDirectory, 0, sizeof(m_memoryDirectory));
-	dgGlobalAllocator::m_globalAllocator.Append(this);
+	dgGlobalAllocator::m_globalAllocator->Append(this);
 }
 
 dgMemoryAllocator::dgMemoryAllocator(dgMemAlloc memAlloc, dgMemFree memFree) {
@@ -79,7 +88,7 @@ dgMemoryAllocator::dgMemoryAllocator(dgMemAlloc memAlloc, dgMemFree memFree) {
 }
 
 dgMemoryAllocator::~dgMemoryAllocator() {
-	dgGlobalAllocator::m_globalAllocator.Remove(this);
+	dgGlobalAllocator::m_globalAllocator->Remove(this);
 	NEWTON_ASSERT(m_memoryUsed == 0);
 }
 
@@ -359,11 +368,11 @@ void dgMemoryAllocator::dgMemoryLeaksTracker::RemoveBlock(void *const ptr) {
 
 // Set the pointer of memory allocation functions
 void dgSetGlobalAllocators(dgMemAlloc malloc, dgMemFree free) {
-	dgGlobalAllocator::m_globalAllocator.SetAllocatorsCallback(malloc, free);
+	dgGlobalAllocator::m_globalAllocator->SetAllocatorsCallback(malloc, free);
 }
 
 dgInt32 dgGetMemoryUsed() {
-	return dgGlobalAllocator::m_globalAllocator.GetMemoryUsed();
+	return dgGlobalAllocator::m_globalAllocator->GetMemoryUsed();
 }
 
 // this can be used by function that allocates large memory pools memory locally on the stack
@@ -371,11 +380,11 @@ dgInt32 dgGetMemoryUsed() {
 // this was using virtual memory on windows but
 // but because of many complaint I changed it to use malloc and free
 void *dgApi dgMallocStack(size_t size) {
-	return dgGlobalAllocator::m_globalAllocator.MallocLow(dgInt32(size));
+	return dgGlobalAllocator::m_globalAllocator->MallocLow(dgInt32(size));
 }
 
 void *dgApi dgMallocAligned(size_t size, dgInt32 align) {
-	return dgGlobalAllocator::m_globalAllocator.MallocLow(dgInt32(size), align);
+	return dgGlobalAllocator::m_globalAllocator->MallocLow(dgInt32(size), align);
 }
 
 // this can be used by function that allocates large memory pools memory locally on the stack
@@ -383,7 +392,7 @@ void *dgApi dgMallocAligned(size_t size, dgInt32 align) {
 // this was using virtual memory on windows but
 // but because of many complaint I changed it to use malloc and free
 void  dgApi dgFreeStack(void *const ptr) {
-	dgGlobalAllocator::m_globalAllocator.FreeLow(ptr);
+	dgGlobalAllocator::m_globalAllocator->FreeLow(ptr);
 }
 
 // general memory allocation for all data in the library
diff --git a/engines/hpl1/engine/libraries/newton/core/dgMemory.h b/engines/hpl1/engine/libraries/newton/core/dgMemory.h
index cd3c2126085..2045a66784a 100644
--- a/engines/hpl1/engine/libraries/newton/core/dgMemory.h
+++ b/engines/hpl1/engine/libraries/newton/core/dgMemory.h
@@ -30,6 +30,10 @@
 
 class dgMemoryAllocator;
 
+void dgInitMemoryGlobals();
+
+void dgDestroyMemoryGlobals();
+
 void *dgApi dgMalloc(size_t size, dgMemoryAllocator *const allocator);
 void  dgApi dgFree(void *const ptr);
 




More information about the Scummvm-git-logs mailing list