-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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 crash when extending taken-over named class #84148
Fix crash when extending taken-over named class #84148
Conversation
Thanks for your first PR! If we merge this PR, I'm wondering if we should update the GDScriptCache when a path is taken over by a new script. |
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.
Seems fine!
Thank you again for your first PR!
@@ -2647,7 +2647,10 @@ Error GDScriptCompiler::_prepare_compilation(GDScript *p_script, const GDScriptP | |||
|
|||
GDScriptDataType base_type = _gdtype_from_datatype(p_class->base_type, p_script, false); | |||
|
|||
ERR_FAIL_COND_V_MSG(base_type.native_type == StringName(), ERR_BUG, vformat(R"(Failed to get base class for "%s")", p_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.
Should this be an engine-level error (ERR_BUG
), or a user-level error (_set_error
+ returning the most relevant error code)?
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 think it's fine, this should not happen as a result of user error, it's an analyzer/compiler bug.
modules/gdscript/gdscript.cpp
Outdated
} else if (path.begins_with(get_root_script()->path)) { | ||
class_names = path.trim_prefix(get_root_script()->path).split("::"); | ||
result = get_root_script(); |
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'm not sure, but the condition looks as always true to me. p_qualified_name
is not used at all in the branch, this is weird.
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.
Thanks for looking at this! I tried to explain what I found while debugging here.
If you can provide more details, I can dive back in.
"The condition looks as always true" - Which condition?
"p_qualified_name
is not used" - What exactly do you mean by "not used" and what is weird about it?
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.
Which condition?
path.begins_with(get_root_script()->path)
. path
is the script path, for inner classes it may additionally contain suffixes. get_root_script()
returns the topmost script that owns the inner class scripts.
What exactly do you mean by "not used" and what is weird about it?
This method checks p_qualified_name
, every other branch has p_qualified_name
, but not this one, that's weird. I haven't tested this, but it might break the _owner != nullptr
branch.
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.
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.
Successful tests do not guarantee the absence of regressions, since the tests do not cover all possible scenarios. I added this PR for discussion at the GDScript team meeting or maybe @vnen will review it offline.
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.
It is odd to me as well. This is a function to find a class identified by p_qualified_name
, so the branch not checking the argument cannot reliably find the requested class. As @dalexeev said, this will always be true (the path of an inner class will always start with the path of its root script), so the other conditions will never be checked.
Given that, I don't think this is a proper solution.
87db92f
to
ddea67e
Compare
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.
See comment
ddea67e
to
fd6fcc6
Compare
@vnen i've been talking with Kana and further analyzed the root cause for this issue. Should we close this PR, and address the root problem in a new PR? |
@pirey0 if the |
Added error handling in `_prepare_compilation()` to address cases where the `base_type` cannot be found, preventing a crash.
fd6fcc6
to
f4192aa
Compare
This seems good as crash prevention, but the bug still exsits. Do we have an open bug report with a MRP keeping track of it? |
#83542 (if this is not what you meant, let me know :) ) |
Thanks! And congrats for your first merged Godot contribution 🎉 |
Added error handling in
_prepare_compilation()
to address cases where thebase_type
cannot be found, preventing a crash.Added an additional if statement to
find_class()
to check the script path.I expect this to not be the ideal solution, as I stated in my issue comment.
But this PR might be a better place to discuss code changes, and I'm looking forward to any feedback.
Nonetheless, I ran all the GDScript tests and tried this fix in the MRP and two bigger projects with success and no obvious side effects.
Cheers.
Note
This now only contains the crash prevention. Future debugging is needed. #83542 will stay open.