godot-rust / gdext

Rust bindings for Godot 4
https://mastodon.gamedev.place/@GodotRust
Mozilla Public License 2.0
3.09k stars 196 forks source link

Godot editor crashes when hot reloading gdext library with custom resources #582

Open tomdedecker opened 9 months ago

tomdedecker commented 9 months ago

A few days ago I started experimenting with custom resources for my gdext project and noticed that I started getting editor crashes every time (or at least most of the time) when I made a change to a node using a custom resource. Fast forward a bit and I was able to make a minimal reproducible example using a single node and resource. You can find it here or in the attached zip file.

gdext-reload-crash-master.zip

The scenario is as follows:

  1. Download the project
  2. Compile the rust code (cargo build inside /rust)
  3. Open the project in the Godot editor
  4. Run the game
  5. Open rust/src/node.rs
  6. Uncomment the second print line in ready()
  7. Build the module again
  8. Re-run the game in the editor

At this point the editor typically crashes for me, producing one of 3 stack traces (as far as I encountered), which I've also added to the root of the repository. Two of these crashed in Godot's source code and the other inside the gdext project. I considered opening an issue with Godot's as I assumed that this might be a problem on their end, but I wanted to check here first.

I haven't tested this on any other platforms yet, but I can consistently reproduce it on my Linux (x86-64) install with Godot 4.2.1.

If you need any other info or if this is an issue I should check with Godot itself, please let me know.

Kind regards, Tom

lilizoey commented 9 months ago

Does this still happen if the resource is declared as

#[export]
resource: Option<Gd<MyResource>>,

?

tomdedecker commented 9 months ago

So far I haven't been able to reproduce it when wrapped in an Option, but even after making it required again I'm still having a hard time reproducing it. I'll experiment with it a bit and see if I can get it to crash when the resource is optional.

Are resources expected to always be optional or is this just to help diagnose the issue?

tomdedecker commented 9 months ago

I was able to reproduce the crash in my actual project when I made my custom resource optional, but after restarting the editor I have yet to experience a new crash. Assuming the first crash was due to a limitation of the current hot reloading system, making the resource optional might indeed fix the issue. I'll keep you posted if I encounter it again.

Bromeon commented 9 months ago

@tomdedecker any updates yet? 🙂

tomdedecker commented 9 months ago

As far as I can tell the issue remains as before. As long as the resource is not marked as optional, the editor seems to frequently crash when hot reloading. Marking the resource as optional and restarting the editor seems to avoid/bypass the issue, making subsequent hot reloads work as expected. I'm not sure if this is an issue on Godot's end or in gdext, but if there's any extra information I can provide I'd be happy to help.

Bromeon commented 8 months ago

Might also be fixed by #636.