-
-
Notifications
You must be signed in to change notification settings - Fork 21k
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
It is not possible to send null
as the last argument of an UndoRedo method
#36895
Comments
Related to #29204 |
I've been working on this bug. For now, I only managed to solve this issue by having map in UndoRedo class with argc for current functions, but I would like to do some more, so feedback would be great. I don't see how to apply reflection to this problem, nor what exactly do you mean by reflection in c++ (until recently it wasn't included afaik). Here is basic project reproducing the bug. |
…toring" This reverts commit 93bc60c.
… after reloading plugin
Added map with <function, argc> pairing used to determine the proper argc.
Minimal reproduction project I made for #43141: Note that |
just faced this too, so I do it in my own functions like undo.add_do_method(self, "_do") |
Fixed by #66070. Edit: Not sure actually, based on #43872 (comment). |
This was actually resolved by #58929 |
Godot 3.2
To register a method to be executed when doing or undoing a change,
UndoRedo.add_do_method()
orUndoRedo.add_undo_method()
have to be used.Those methods were implemented by declaring 5
Variant
arguments, allnull
by default.Unfortunately, the argument count is then determined by checking how many remaining arguments are null, including cases where you want to call the method with
null
.That means it is impossible to write this:
Because the
null
at the end will be confused as absence of argument. Then when committing the action, undoing or redoing it, it won't work and this kind of error will be printed:See
godot/core/undo_redo.cpp
Line 284 in 78adce8
I had to workaround this limitation by binding extra methods in my objects, and check if variants are null before using
add_do_method
andadd_undo_method
.To fix this,
UndoRedo
should not determine argument count in this way. Instead, it should use reflection to query how many arguments the called method actually has. Other solutions include sending an array explicitely, adding a count argument, or having aVariant::UNDEFINED
type, but that would break compatibility.The text was updated successfully, but these errors were encountered: