-
-
Notifications
You must be signed in to change notification settings - Fork 21.3k
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
Calling a method on variable properties crashes with infinite recursion #52757
Comments
This code is indeed invalid as it creates infinite recursion, but maybe the GDScript analyser could figure it out and throw a helpful error. |
Tested with a simpler script:
godot/modules/gdscript/gdscript_vm.cpp Lines 540 to 545 in 44b1143
godot/modules/gdscript/gdscript.h Lines 365 to 370 in 44b1143
Although this makes sense IMO, shouldn't the engine avoid crashing at all costs on normal builds? master in the meantime.EDIT: This script doesn't crash on |
|
As of 6b0b1a4 this is still an issue. It causes the editor on Windows 10 to crash if a script such as this is attached to a node in a Scene that is open in the editor:
|
The proper way to use method setter is
The only thing that could be improved here is leading the user to the correct syntax instead of hard crashing. |
In 3.5 setting/getting a variable from the same "class" as the variable doesn't call the setter/getter function; to intentionally do so simply required a self.variable syntax. This always seemed pretty intuitive to me, is there some reason for this to no longer be the case? That is to say: # outside the variable's parent object:
object .property = value # triggers setter, no infinite recursion
# inside the variable's parent object:
property = value # does not trigger setter, no infinite recursion
self.property = value # triggers setter, infinite recursion It seems to me like OP's original example shouldn't have led to an infinite recursion in the first place, therefore making this a bug or a missing feature. Just figured I'd bring that functionality up since I didn't see anyone mention it in the thread so far. The way it is now I'm forced to mimic C#'s set/get properties with an extra variable to store values on the side... which feels a bit silly to be honest. |
@cullumi This is intentional. The old different behavior of
There was a suggestion/comment to add an annotation and my proposal. But they didn't get support. |
Godot version
4.0.dev latest
System information
Arch Linux
Issue description
When doing some quick refactoring for a project in 3.2 to 4.0, I tried to cut corners and refactored the old
setget
behavior like this:However when running this script it crashes with a segfault. Looking at
gdb
there seems to be infinite recursion:I don't know if this usage of properties is valid per se, but it certainly shouldn't segfault 🙂
Steps to reproduce
Minimal reproduction project
MRP.zip
The text was updated successfully, but these errors were encountered: