godotengine / godotengine/godot-cpp

Mac Editor Crash When Exposing Resource in Inspector from GDExtension

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

Description

### Godot version

4.2.1.stable

### godot-cpp version

godot-4.2.1-stable

### System information

macOS 14.4.1 - Vulkan (Mobile) - integrated Apple M3 Max - Apple M3 Max (16 Threads)

### Issue description

I am writing some game code in C++ using GDExtension. As part of this, I have a custom manager class (set up as an Autoload) that exposes a custom Resource in the Inspector.

On Mac, every time I recompile the dylib and the editor does the hot reload process, the editor crashes with this stack trace:
[CrashReport.txt](https://github.com/godotengine/godot-cpp/files/14923341/CrashReport.txt)

The crash report appears to point to destructing a Resource inside my Autoload manager class as the culprit for the crash. In my testing, I found that if this field is set to an object (either on-disk or embedded in the manager scene), I get the crash. If the field is null/empty, I do not get a crash. If I remove the _bind_methods code to expose the field in the Inspector, I do not get a crash.

I see this behavior when compiling on Mac via Xcode or CLion. I haven't yet seen this issue on Windows.

I believe the method I'm using to expose the Resource is correct, but there isn't a huge amount of GDExtension documentation, so I'm not 100% sure. My expectation would be that the current code doesn't crash the editor when hot reloading.

### Steps to reproduce

In the provided project, I believe you can reproduce the crash using these steps:

1. Open the provided C++ project (in "Cpp" folder) in either CLion or Xcode on Mac. It is configured using CMake. Build in debug mode.
2. Open the Godot project in the Res folder. Note that there is a "SceneManager.tscn" with a GameSettings Resource that is embedded in the scene directly. Also note that this SceneManager scene is hooked up as an Autoload in the project. You should also see a log output about the Resource.
3. Make a small change to the C++ code and rebuild the library in debug mode.
4. Focus the Godot Editor, which will then try to hot reload the GDExtension's updated dylib. However, the Editor will beach-ball and then crash.

### Minimal reproduction project

[ResourceBug.zip](https://github.com/godotengine/godot-cpp/files/14923404/ResourceBug.zip)

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.