Parcourir la source

Fix crash when deallocating named colors map

Fixes #18216
Bojidar Marinov il y a 7 ans
Parent
commit
7a4b8c82f9
3 fichiers modifiés avec 10 ajouts et 0 suppressions
  1. 4 0
      core/color.cpp
  2. 4 0
      core/color.h
  3. 2 0
      core/register_core_types.cpp

+ 4 - 0
core/color.cpp

@@ -344,6 +344,10 @@ Color Color::named(const String &p_name) {
 	}
 }
 
+void Color::cleanup() {
+	_named_colors.clear();
+}
+
 String _to_hex(float p_val) {
 
 	int v = p_val * 255;

+ 4 - 0
core/color.h

@@ -135,6 +135,10 @@ struct Color {
 		b = p_b;
 		a = p_a;
 	}
+
+private:
+	friend void unregister_core_types();
+	static void cleanup();
 };
 
 bool Color::operator<(const Color &p_color) const {

+ 2 - 0
core/register_core_types.cpp

@@ -32,6 +32,7 @@
 #include "bind/core_bind.h"
 #include "compressed_translation.h"
 #include "core/io/xml_parser.h"
+#include "color.h"
 #include "core_string_names.h"
 #include "func_ref.h"
 #include "geometry.h"
@@ -199,6 +200,7 @@ void unregister_core_types() {
 
 	unregister_variant_methods();
 
+	Color::cleanup();
 	ObjectTypeDB::cleanup();
 	ResourceCache::clear();
 	CoreStringNames::free();