godotengine / godotengine/godot-cpp

Crash in Variant Destructor if given incomplete type

Open
#1,806 4 comments 0 reactions 0 assignees View on GitHub
bug crash
Dominant language
C++
Stars
2.7k
Forks
809
Avg merge
1d 3h
Merged PRs (30d)
8

Description

### 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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.