From a79e71ad5870659f4b2ba18334ab058a92a2b1ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20J=2E=20Est=C3=A9banez?= Date: Wed, 26 Apr 2023 10:44:03 +0200 Subject: [PATCH] Add peace-of-mind checks to API hash caching --- core/object/class_db.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/object/class_db.cpp b/core/object/class_db.cpp index d920ae6ca05b..760f3bfd0c9b 100644 --- a/core/object/class_db.cpp +++ b/core/object/class_db.cpp @@ -56,6 +56,7 @@ ClassDB::APIType ClassDB::current_api = API_CORE; HashMap ClassDB::api_hashes_cache; void ClassDB::set_current_api(APIType p_api) { + DEV_ASSERT(!api_hashes_cache.has(p_api)); // This API type may not be suitable for caching of hash if it can change later. current_api = p_api; } @@ -296,7 +297,12 @@ uint64_t ClassDB::get_api_hash(APIType p_api) { } hash = hash_fmix32(hash); - api_hashes_cache[p_api] = hash; + + // Extension API changes at runtime; let's just not cache them by now. + if (p_api != API_EXTENSION && p_api != API_EDITOR_EXTENSION) { + api_hashes_cache[p_api] = hash; + } + return hash; #else return 0;