-
-
Notifications
You must be signed in to change notification settings - Fork 21.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GDScript segmentation fault cyclic reference #43529
Comments
Some IRC chat, that may be useful to fix this issue: odino: vnen, During the parsing of the member, that has the resource type, the following line is executed: https://github.com/godotengine/godot/blob/master/modules/gdscript/gdscript_compiler.cpp#L131 Even if that's not the cause, I still think that the reference should be stored anyway (at least into I've just converted diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp
index 6b74abf15d..e557fda522 100644
--- a/modules/gdscript/gdscript.cpp
+++ b/modules/gdscript/gdscript.cpp
@@ -604,7 +604,7 @@ Error GDScript::reload(bool p_keep_state) {
if (!source_path.empty()) {
MutexLock lock(GDScriptCache::singleton->lock);
if (!GDScriptCache::singleton->shallow_gdscript_cache.has(source_path)) {
- GDScriptCache::singleton->shallow_gdscript_cache[source_path] = this;
+ GDScriptCache::singleton->shallow_gdscript_cache[source_path] = Ref<GDScript>(this);
}
}
}
diff --git a/modules/gdscript/gdscript_cache.cpp b/modules/gdscript/gdscript_cache.cpp
index 95d24a8b08..b1df599195 100644
--- a/modules/gdscript/gdscript_cache.cpp
+++ b/modules/gdscript/gdscript_cache.cpp
@@ -185,7 +185,7 @@ Ref<GDScript> GDScriptCache::get_shallow_script(const String &p_path, const Stri
script->set_script_path(p_path);
script->load_source_code(p_path);
- singleton->shallow_gdscript_cache[p_path] = script.ptr();
+ singleton->shallow_gdscript_cache[p_path] = script;
return script;
}
@@ -213,7 +213,7 @@ Ref<GDScript> GDScriptCache::get_full_script(const String &p_path, Error &r_erro
return script;
}
- singleton->full_gdscript_cache[p_path] = script.ptr();
+ singleton->full_gdscript_cache[p_path] = script;
singleton->shallow_gdscript_cache.erase(p_path);
return script;
@@ -222,7 +222,7 @@ Ref<GDScript> GDScriptCache::get_full_script(const String &p_path, Error &r_erro
Error GDScriptCache::finish_compiling(const String &p_owner) {
// Mark this as compiled.
Ref<GDScript> script = get_shallow_script(p_owner);
- singleton->full_gdscript_cache[p_owner] = script.ptr();
+ singleton->full_gdscript_cache[p_owner] = script;
singleton->shallow_gdscript_cache.erase(p_owner);
Set<String> depends = singleton->dependencies[p_owner];
diff --git a/modules/gdscript/gdscript_cache.h b/modules/gdscript/gdscript_cache.h
index 90c5884985..36a8112d44 100644
--- a/modules/gdscript/gdscript_cache.h
+++ b/modules/gdscript/gdscript_cache.h
@@ -71,8 +71,8 @@ public:
class GDScriptCache {
// String key is full path.
HashMap<String, GDScriptParserRef *> parser_map;
- HashMap<String, GDScript *> shallow_gdscript_cache;
- HashMap<String, GDScript *> full_gdscript_cache;
+ HashMap<String, Ref<GDScript>> shallow_gdscript_cache;
+ HashMap<String, Ref<GDScript>> full_gdscript_cache;
HashMap<String, Set<String>> dependencies;
friend class GDScript; reduz: scripts can get hooked up to the refcounting, we already use this for mono |
I'm unable to reproduce this bug on Godot master ( 85186bc ) @AndreaCatania if you are unable to reproduce this issue, we should close it. |
Assuming fixed based on the comment above (if not, it's likely reported with a new issue from a more recent version). |
Godot version:
f733746
OS/device including version:
Fedora 32
Issue description:
When you have a cyclic reference using
class_name
and one of the file is aResource
a segmentation fault is raised.Steps to reproduce:
Just launch this: TestCrash.zip
The text was updated successfully, but these errors were encountered: