Fix segmentation fault when using Ref#346
Conversation
|
Weird change, can you elaborate why this fixes the issue? |
|
@PhilWun @BastiaanOlij very odd, but nice, thanks for the fix..., been trying to get Ref(T::_new()) working all day. Seems like something is broken with the instancing in 3.2 for custom classes, not built-in classes which do not use the GODOT_CLASS() macro. |
|
I have manually merged this request on local and I can confirm that it indeed fixes the issue. A quite critical issue if you ask me. |
|
Adding my voice here, too. This should definitely be merged. |
|
The fix (making Name *instance = godot::as<Name>(script->new_());
// │ │
// │ └─> returns Variant: ref-count is 1
// └─> returns Name*: ref-count drops to 0 when the Variant is destroyedOtherwise Also, the Ref itself leaks now too. The Reference *r = Reference::_new(); // refcount = 1, refcount_init = 1
Ref<Reference> r_ref(r); // refcount = 1, refcount_init = 0
CustomResource *c = CustomResource::_new(); // refcount = 1, refcount_init = 0
Ref<CustomResource> c_ref(c); // refcount = 2, refcount_init = 0So, the CustomResource leaks. #350 fixes this too, but requires changes to Godot. Maybe we can find a cleaner solution that doesn't require it? But we have no access to |
|
You aren't wrong, but a memory leak (especially as there is seemingly a workaround for it) is preferable to an outright "you cannot use this fairly important class at all because it crashes". After all, this has to move ahead somehow and some of these issues have been out for 2+ years :/ |
|
Alright, you have a good point. And this has been one of the most mentioned issues in the Hopefully afterwards we can find a way to fix the |
|
Should no longer be needed after #408 |
|
For the sake of completeness: I just noticed the following comment which may go some way to explain this commit: #343 (comment)
But as Zylann mentioned, after #408 this shouldn't be necessary. |
|
Closing since the cause of the leak was fixed. |
This should fix #343