Pārlūkot izejas kodu

Fix font textures leaked during Rml::Shutdown due to wrong order of shutdown calls. Log an error in debug mode if any textures leak after shutdown. See #133.

Michael Ragazzon 5 gadi atpakaļ
vecāks
revīzija
db4ee749ed
2 mainītis faili ar 31 papildinājumiem un 7 dzēšanām
  1. 13 7
      Source/Core/Core.cpp
  2. 18 0
      Source/Core/TextureDatabase.cpp

+ 13 - 7
Source/Core/Core.cpp

@@ -78,6 +78,10 @@ static ContextMap contexts;
 
 bool Initialise()
 {
+	RMLUI_ASSERTMSG(!initialised, "Rml::Initialise() called, but RmlUi is already initialised!");
+
+	Log::Initialise();
+
 	// Check for valid interfaces, or install default interfaces as appropriate.
 	if (!system_interface)
 	{	
@@ -96,8 +100,6 @@ bool Initialise()
 #endif
 	}
 
-	Log::Initialise();
-
 	EventSpecificationInterface::Initialize();
 
 	TextureDatabase::Initialise();
@@ -130,29 +132,33 @@ bool Initialise()
 
 void Shutdown()
 {
+	RMLUI_ASSERTMSG(initialised, "Rml::Shutdown() called, but RmlUi is not initialised!");
+
 	// Clear out all contexts, which should also clean up all attached elements.
 	contexts.clear();
 
 	// Notify all plugins we're being shutdown.
 	PluginRegistry::NotifyShutdown();
 
+	Factory::Shutdown();
 	TemplateCache::Shutdown();
 	StyleSheetFactory::Shutdown();
 	StyleSheetSpecification::Shutdown();
-	TextureDatabase::Shutdown();
-	Factory::Shutdown();
 
-	Log::Shutdown();
+	font_interface = nullptr;
+	default_font_interface.reset();
+
+	TextureDatabase::Shutdown();
 
 	initialised = false;
 
 	render_interface = nullptr;
 	file_interface = nullptr;
 	system_interface = nullptr;
-	font_interface = nullptr;
 
 	default_file_interface.reset();
-	default_font_interface.reset();
+
+	Log::Shutdown();
 }
 
 // Returns the version of this RmlUi library.

+ 18 - 0
Source/Core/TextureDatabase.cpp

@@ -45,6 +45,24 @@ TextureDatabase::TextureDatabase()
 TextureDatabase::~TextureDatabase()
 {
 	RMLUI_ASSERT(texture_database == this);
+
+#ifdef RMLUI_DEBUG
+	// All textures not owned by the database should have been released at this point.
+	int num_leaks_file = 0;
+	
+	for (auto& texture : textures)
+		num_leaks_file += (texture.second.use_count() > 1);
+
+	const int num_leaks_callback = (int)callback_textures.size();
+	const int total_num_leaks = num_leaks_file + num_leaks_callback;
+
+	if (total_num_leaks > 0)
+	{
+		Log::Message(Log::LT_ERROR, "Textures leaked during shutdown. Total: %d  From file: %d  Generated: %d.",
+			total_num_leaks, num_leaks_file, num_leaks_callback);
+	}
+#endif
+
 	texture_database = nullptr;
 }