Crash in Variant Destructor if given incomplete type
Godot version
4.4.1.stable.arch_linux
godot-cpp version
4.4
System information
Arch Linux
Issue description
If passing a pointer to an incomplete/forwarded type that inherits from refcounted into a variant, it will happily accept that with no errors and then crash in the destructor.
Discovered this as I was passing a pointer from a ref counted c++ class as an argument into a call(), which would pass it into a std:array of variants. When they went out of scope it would promptly crash. Crash went away when I included the appropriate header.
It was quite unclear what was wrong, I'd have expected a compile-time error when doing this. Could probably be done by always converting the pointer to a Ref as it's passed to the variant? The compiler would start complaining about incomplete type then.
Steps to reproduce
- Create class
Foothat inherits fromRefCounted - Create second class
Fizzwith functionbuzzthat takes in aFooargument as a pointer. - Try and do a
call()insidebuzzpassing the Foo argument. - Should get a sigfault as you exit the
call()function.
Minimal reproduction project
If the steps are not considered trivial or you can't reproduce it let me know and I'll produce a sample project.
Hi, please add a minimal production project.
So, is the issue that you have forward declared Foo, and it crashes unless you include the header with full definition?
Hi, please add a minimal production project.
Will do! Might need to wait until the weekend for it though.
So, is the issue that you have forward declared
Foo, and it crashes unless you include the header with full definition?
Exactly, I'd have expected it to give me the usual compiler error of that I am trying to do something with an incomplete type.
Just need to run git submodule update --init --recursive to initialize godot_cpp as usual. The script in the scene will demonstrate the crash, it looks a bit contrived as a minimal example.