-
-
Notifications
You must be signed in to change notification settings - Fork 210
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
ERROR: Condition "!success" is true when returning an Array from gdextension #138
Comments
Some more details that might help:
|
Thank you! We'll try to reproduce the behavior in tests. I would personally even consider "printing an error message" a bug, although it's sometimes hard to avoid with Godot, or only possible with performance penalties (checking the same operation twice). Minor request, could you in the future use code tags with the corresponding language? The syntax is as follows (and |
Didn't even know this was something GitHub supported. Will do. Thanks for letting me know 👍 |
Before 42f12f5 I had been using the old implementation for arrays and it was working fine. I'll look and see if I can spot something obvious in the diff. |
So i can reproduce it, but only when i attach a script to the node that has this function, and call the function from the script attached to the node. if i call the function from outside that script it works fine. This also works in the itests, but you need to specifically:
|
Hello, today i did run into probably similar issue with strings. They either get into gdscript as empty or crash over all.
Minimal repro project: From what i see there are 2 possible things that happen.
Only way how to make it work is part of repro as well, see
So my guess is that memory with string gets freed and then passed to Godot. Script sees it as empty and crashes on trying to free it again. Over all i would expect even super simple case like: #[func]
fn get_text(&self) -> GodotString {
GodotString::from("test")
} or similar to "simply work" |
The following code causes a crash for me: #[func]
pub fn get_buildings(&mut self) -> PackedStringArray {
let mut arr = PackedStringArray::new();
arr.push(GodotString::from("apt"));
arr
} Godot: extends Control
# Called when the node enters the scene tree for the first time.
func _ready():
var buildings = Global.get_buildings()
print(buildings) |
I'm running into a similar issue with Strings. This function does not work (it says it doesn't exist when I try to call it from Godot) #[func]
pub fn set_building_mode(&mut self, building:GodotString) {
godot_print!("worked! {:?}", building);
} This function, on the other hand, does work and I can call it from Godot: #[func]
pub fn set_building_mode(&mut self, building:Variant) {
let building_name = building.to_string();
godot_print!("worked! {:?}", building);
} |
So the sanitizer build of godot is complaining about a use-after-free. And it appears that |
This reverts commit 3321bca.
-Add tests that would trigger godot-rust#138 before this fix.
-Add integration tests.
The same issue seems to happen when returning refcounted objects from virtual methods. This isn't really possible to trigger yet because of #190, but attempting to do so will hit the same bug. It does seem like it has the same solution as what is being proposed in #165 though, just for virtual method calls as well. |
165: Fix early destruction of objects returned from Rust (#138) r=Bromeon a=thebigG Hi there, I probably need to test this more thoroughly. Just opening a pull request for collaboration and such. Basically it came down to for some reason(I'm still learning about this rust port of godot) ac02be1 triggers this behavior. And this PR reverts that commit(except for the tests). This patch fixes my use case, but I'll try to write unit tests and test in general to make sure we don't miss any other edge cases. Hope this PR is clear enough. Thanks Lorenzo Co-authored-by: thebigG <[email protected]>
This was fixed in #204, so closing. |
[Edit bromeon: syntax highlighting]
Hi there,
I have the following function in my gdextension:
My gdscript:
Output from godot:
Here is the code from Godot:
It seems like all this triggers
ERR_FAIL_COND(!success);
. Which if you follow the code means the following:Which says to me that return count.conditional_increment() != 0; is false and "conditional_increment()" returns 0. Does that mean that the current array implementation has a reference count of 0?
I know there are certain things in Godot that are ref-counted, so it would make sense if this fails given that the array has a ref count of zero. I'm not sure how gdextension objects map to ref-counter objects in the Godot side... So I was wondering if you guys had more insight into how to tackle this issue. Maybe I'm missing something obvious here,...
Thanks in advance
The text was updated successfully, but these errors were encountered: