Browse Source

Added UnregisterTypes function (#456)

Fixes #454
Jorrit Rouwe 2 years ago
parent
commit
49a2cfb66c

+ 3 - 0
HelloWorld/HelloWorld.cpp

@@ -352,6 +352,9 @@ int main(int argc, char** argv)
 	body_interface.RemoveBody(floor->GetID());
 	body_interface.RemoveBody(floor->GetID());
 	body_interface.DestroyBody(floor->GetID());
 	body_interface.DestroyBody(floor->GetID());
 
 
+	// Unregisters all types with the factory and cleans up the default material
+	UnregisterTypes();
+
 	// Destroy the factory
 	// Destroy the factory
 	delete Factory::sInstance;
 	delete Factory::sInstance;
 	Factory::sInstance = nullptr;
 	Factory::sInstance = nullptr;

+ 10 - 0
Jolt/RegisterTypes.cpp

@@ -153,4 +153,14 @@ void RegisterTypes()
 		PhysicsMaterial::sDefault = new PhysicsMaterialSimple("Default", Color::sGrey);
 		PhysicsMaterial::sDefault = new PhysicsMaterialSimple("Default", Color::sGrey);
 }
 }
 
 
+void UnregisterTypes()
+{
+	// Unregister all types
+	if (Factory::sInstance != nullptr)
+		Factory::sInstance->Clear();
+
+	// Delete default physics material
+	PhysicsMaterial::sDefault = nullptr;
+}
+
 JPH_NAMESPACE_END
 JPH_NAMESPACE_END

+ 3 - 0
Jolt/RegisterTypes.h

@@ -9,4 +9,7 @@ JPH_NAMESPACE_BEGIN
 /// Register all physics types with the factory
 /// Register all physics types with the factory
 extern void RegisterTypes();
 extern void RegisterTypes();
 
 
+/// Unregisters all types with the factory and cleans up the default material
+extern void UnregisterTypes();
+
 JPH_NAMESPACE_END
 JPH_NAMESPACE_END

+ 3 - 0
PerformanceTest/PerformanceTest.cpp

@@ -430,6 +430,9 @@ int main(int argc, char** argv)
 	NarrowPhaseStat::sReportStats();
 	NarrowPhaseStat::sReportStats();
 #endif // JPH_TRACK_NARROWPHASE_STATS
 #endif // JPH_TRACK_NARROWPHASE_STATS
 
 
+	// Unregisters all types with the factory and cleans up the default material
+	UnregisterTypes();
+
 	// Destroy the factory
 	// Destroy the factory
 	delete Factory::sInstance;
 	delete Factory::sInstance;
 	Factory::sInstance = nullptr;
 	Factory::sInstance = nullptr;

+ 3 - 0
TestFramework/Application/Application.cpp

@@ -99,6 +99,9 @@ Application::~Application()
 		delete mRenderer;
 		delete mRenderer;
 	}
 	}
 
 
+	// Unregisters all types with the factory and cleans up the default material
+	UnregisterTypes();
+
 	delete Factory::sInstance;
 	delete Factory::sInstance;
 	Factory::sInstance = nullptr;
 	Factory::sInstance = nullptr;
 }
 }

+ 9 - 0
UnitTests/UnitTestFramework.cpp

@@ -148,6 +148,9 @@ struct App : implements<App, IFrameworkViewSource, IFrameworkView>
 		// Run the tests
 		// Run the tests
 		int rv = Context().run();
 		int rv = Context().run();
 
 
+		// Unregisters all types with the factory and cleans up the default material
+		UnregisterTypes();
+
 		// Destroy the factory
 		// Destroy the factory
 		delete Factory::sInstance;
 		delete Factory::sInstance;
 		Factory::sInstance = nullptr;
 		Factory::sInstance = nullptr;
@@ -202,6 +205,9 @@ int main(int argc, char** argv)
 
 
 	int rv = Context(argc, argv).run();
 	int rv = Context(argc, argv).run();
 
 
+	// Unregisters all types with the factory and cleans up the default material
+	UnregisterTypes();
+
 	// Destroy the factory
 	// Destroy the factory
 	delete Factory::sInstance;
 	delete Factory::sInstance;
 	Factory::sInstance = nullptr;
 	Factory::sInstance = nullptr;
@@ -316,6 +322,9 @@ void AndroidInitialize(android_app *inApp)
 	ANativeWindow_unlockAndPost(inApp->window);
 	ANativeWindow_unlockAndPost(inApp->window);
 	ANativeWindow_release(inApp->window);
 	ANativeWindow_release(inApp->window);
 
 
+	// Unregisters all types with the factory and cleans up the default material
+	UnregisterTypes();
+
 	// Destroy the factory
 	// Destroy the factory
 	delete Factory::sInstance;
 	delete Factory::sInstance;
 	Factory::sInstance = nullptr;
 	Factory::sInstance = nullptr;