gdext icon indicating copy to clipboard operation
gdext copied to clipboard

`#[class(no_init)]` makes extension non-reloadable

Open snatvb opened this issue 5 months ago • 4 comments

[!note] Edit bromeon: updated problem description.

When disabling the default constructor via #[class(no_init)], the class can no longer be reloaded. Godot uses this as a reason to disable reloading for the entire extension, with the following error:

Extension marked as reloadable, but attempted to register class 'MyClass' which doesn't support reloading. Perhaps your language binding don't support it? Reloading disabled for this extension.

It looks like the problem arises in the following part:

https://github.com/godot-rust/gdext/blob/6e6889adedfd273fcd185faa06a57891f2f71a13/godot-macros/src/class/derive_godot_class.rs#L78-L105

If no_init is specified, the init strategy will be Absent, and neither create nor recreate functions are set. I think particularly the latter causes problems, although this needs to be confirmed. The class is also marked abstract, but I'm not sure if that interferes with it.

We would need to see how we can enable reloading in the absence of a default constructor. If there are no instances of a class to be reloaded, there shouldn't be a problem -- so maybe Godot is overzealous at forbidding reloading if there is no constructor?

Update: there's now an upstream issue to enable this workflow in Godot:

  • https://github.com/godotengine/godot/issues/96823

Original message:

Hello,

I've noticed that when I've updated gdext and godot on 4.3 I got broken reload. I used gdext_coroutines. After disable this part on another project that I've created for testing - reloadable starts work fine. After I read the library and didn't notice any specific cases and tried to add imports coroutines into my extenstion directrly and got same issue.

Reproduce:

  1. Use nightly rust (coroutines is unstable feature)
  2. Add #![feature(coroutines, coroutine_trait)]
  3. Add use std::ops::{Coroutine, CoroutineState};

Read more: https://github.com/Houtamelo/gdext_coroutines/issues/2 showcase.zip

snatvb avatar Aug 26 '24 17:08 snatvb