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

Add hot reload support when building with GCC and CMake

Open ytnuf opened this issue 1 year ago • 10 comments
trafficstars

This is a small continuation to PR #1330 which adds hot reloading options for CMake

However when compiling with GCC, the option -fno-gnu-unique must also be enabled to allow hot reloading. This is done in the SCons script: https://github.com/godotengine/godot-cpp/blob/9b98377a62ae456b0ee082062dbe98d1a13e7bda/tools/linux.py#L20

ytnuf avatar Aug 13 '24 18:08 ytnuf

Even with this, it still does not work for me. Maybe i'm missing something? image

jpxaraujo avatar Aug 20 '24 10:08 jpxaraujo

@jpxaraujo:

Even with this, it still does not work for me. Maybe i'm missing something?

That error is usually caused by not having HOT_RELOAD_ENABLED defined, which I think is set via calling cmake with -DGODOT_ENABLE_HOT_RELOAD.

dsnopek avatar Aug 22 '24 20:08 dsnopek

@jpxaraujo:

Even with this, it still does not work for me. Maybe i'm missing something?

That error is usually caused by not having HOT_RELOAD_ENABLED defined, which I think is set via calling cmake with -DGODOT_ENABLE_HOT_RELOAD.

@dsnopek Thanks for the reply!

So, I added the changes in this commit, added "reloadable = true" to .gdextension and added the HOT_RELOAD_ENABLED

image

But still have the same problem ...

jpxaraujo avatar Aug 23 '24 22:08 jpxaraujo

Finally made it work. @jpxaraujo for hot reloading to work you also need to include HOT_RELOAD_ENABLED and -fno-gnu-unique flag when building your shared library. Adding this worked

set_property(TARGET ${LIBRARY_NAME} APPEND_STRING PROPERTY COMPILE_FLAGS "-D HOT_RELOAD_ENABLED -fno-gnu-unique")

Where ${LIBRARY_NAME} is name of target from add_library().

Drahiri avatar Aug 25 '24 14:08 Drahiri

@Drahiri well, I am bit confused I think. It was already working when running a scene. But I thought it would also update the scene in the editor. It would be a game changer if we could get an automatic update for scenes in the editor.

jpxaraujo avatar Aug 25 '24 14:08 jpxaraujo

It's doing exactly that. After I updated CMake to match this pull request and updated mine CMake with that line. After rebuilding shared library, editor automatically updated without that message asking if hot reloading is enabled. No need to reload whole project to see changes.

Drahiri avatar Aug 25 '24 14:08 Drahiri

@Drahiri I followed every step, It does not work for me, don't know why. I tried in two different systems, one with a 12800h and a 3050ti with fedora and another with 5800X3D and a 6950xt with gentoo ... It only updates if I run the scene, the editor does not change for me ...

jpxaraujo avatar Aug 25 '24 18:08 jpxaraujo

@jpxaraujo I've added repo with working example. Also sorry to all staff if it's turning into spam (I feel like a little).

Drahiri avatar Aug 26 '24 08:08 Drahiri

@jpxaraujo I've added repo with working example. Also sorry to all staff if it's turning into spam (I feel like a little).

Thank you for taking your time to create an example! Hopefully it can help other people. Will test it today or tomorrow. Regarding the spam, my bad, I'm sorry for that.

jpxaraujo avatar Aug 26 '24 09:08 jpxaraujo

Now using the compiler_is_gnu generator expression as suggested.

ytnuf avatar Aug 26 '24 19:08 ytnuf

Cherry-picked for 4.2 in PR https://github.com/godotengine/godot-cpp/pull/1631

dsnopek avatar Oct 28 '24 21:10 dsnopek

Cherry-picked for 4.3 in PR https://github.com/godotengine/godot-cpp/pull/1632

dsnopek avatar Oct 28 '24 21:10 dsnopek