-
-
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
Fix preload cyclic references #65672
Fix preload cyclic references #65672
Conversation
97c07a5
to
402c3a1
Compare
402c3a1
to
b04a70f
Compare
@@ -3192,8 +3192,7 @@ void GDScriptAnalyzer::reduce_preload(GDScriptParser::PreloadNode *p_preload) { | |||
if (!FileAccess::exists(p_preload->resolved_path)) { | |||
push_error(vformat(R"(Preload file "%s" does not exist.)", p_preload->resolved_path), p_preload->path); | |||
} else { | |||
// TODO: Don't load if validating: use completion cache. | |||
p_preload->resource = ResourceLoader::load(p_preload->resolved_path); | |||
p_preload->resource = GDScriptCache::get_shallow_script(p_preload->resolved_path, parser->script_path); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know that I need to add a check to see if the preloaded path is a script or not before using GDScriptCache.
bf9d8c1
to
8c9a65c
Compare
@@ -3192,8 +3192,7 @@ void GDScriptAnalyzer::reduce_preload(GDScriptParser::PreloadNode *p_preload) { | |||
if (!FileAccess::exists(p_preload->resolved_path)) { | |||
push_error(vformat(R"(Preload file "%s" does not exist.)", p_preload->resolved_path), p_preload->path); | |||
} else { | |||
// TODO: Don't load if validating: use completion cache. | |||
p_preload->resource = ResourceLoader::load(p_preload->resolved_path); | |||
p_preload->resource = GDScriptCache::get_shallow_script(p_preload->resolved_path, parser->script_path); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is where it gets weird. There's two behaviors, depending on the code on this line.
- With
GDScriptCache::get_shallow_script()
as is:- my minimal reproduction project ✔️ ;
- the new test cases ❌ ;
modules/gdscript/tests/scripts/analyzer/features/preload_constant_types_are_inferred.gd
❌ ;- build does not fail due to memory leaks ✔️ .
- With
ResourceLoader::load()
and thenGDScriptCache::get_shallow_script()
ifp_preload->resource.is_null()
:- my minimal reproduction project ❌ ;
- the new test cases ✔️ ;
modules/gdscript/tests/scripts/analyzer/features/preload_constant_types_are_inferred.gd
✔️ ;- build fails due to memory leaks
⚠️
8c9a65c
to
98ce4b2
Compare
98ce4b2
to
22a09fe
Compare
@Calinou Could you reopen my PR? I messed up my rebases and erased my code, even force pushed it. I recovered it, but I cannot reopen my PR myself. |
It can't be reopened because at some time the contents of your branch were identical to the That's actually a bug because I see you did fix the branch already and there's now a commit, but GitHub doesn't notice. So you'll have to open a new PR. |
#67714 This is the current PR with this. |
Edit: This PR has been replaced with #67714
Edit: Currently not working as intended. Will post updates.This simple PR makes it possible to use cyclic references with preloaded scripts.
After trying to load completely a script using
ResourceLoader::load()
(that calls down the lineResourceFormatLoaderGDScript::load()
then right afterGDScriptCache::get_full_script()
), if the reference is null (which means that the script is not yet compiled), then we use instead theGDScriptCache::get_shallow_script()
.The beauty of
GDScriptCache::get_shallow_script()
is that it gives back the result ofGDScriptCache::get_full_script()
if it has been fully loaded once.So, this code works with this PR, which returns this error on
master
:Constant value uses script from "res://b.gd" which is loaded but not compiled.
:Minimal reproduction project:
cyclic3.zip
Fixes #58181, fixes #61043, fixes #32165