godot-cpp icon indicating copy to clipboard operation
godot-cpp copied to clipboard

Crash in Variant Destructor if given incomplete type

Open Groogy opened this issue 5 months ago • 4 comments

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

  1. Create class Foo that inherits from RefCounted
  2. Create second class Fizz with function buzz that takes in a Foo argument as a pointer.
  3. Try and do a call() inside buzz passing the Foo argument.
  4. 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.

Groogy avatar Jun 24 '25 22:06 Groogy

Hi, please add a minimal production project.

Ivorforce avatar Jul 10 '25 12:07 Ivorforce

So, is the issue that you have forward declared Foo, and it crashes unless you include the header with full definition?

dsnopek avatar Aug 20 '25 15:08 dsnopek

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.

Groogy avatar Sep 10 '25 13:09 Groogy

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.

VariantCrashRepro.zip

Groogy avatar Sep 25 '25 08:09 Groogy