Skip to content

Godot 4.4 beta 4 hot-reloading not working. #1712

Open

Description

@chriztheanvill

Godot version

Godot 4.4 beta 4

godot-cpp version

master

System information

Fedora Kinoite 41

Issue description

After compiling any part of the code, every public code to show in Godot gui, disappear.

In Cmake I tried this:

set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -fno-omit-frame-pointer -O0 -DHOT_RELOAD_ENABLED -DDEBUG_ENABLED -DDEBUG_METHODS_ENABLED")

tried this:

set(GODOT_ENABLE_HOT_RELOAD ON CACHE INTERNAL "Enable hot reloading support")
set(GODOT_CPP_SYSTEM_HEADERS ON CACHE INTERNAL "Generate system headers")
#set(GODOT_CPP_WARNING_AS_ERROR OFF CACHE INTERNAL "Treat warnings as errors")
set(GENERATE_TEMPLATE_GET_NODE ON CACHE INTERNAL "Get template node")
set(FLOAT_PRECISION "${PRECISION}" CACHE INTERNAL "Library precision")
set(GODOT_CUSTOM_API_FILE "${EXTENSION_FILE}" CACHE INTERNAL "Extension api file")

and this.

reloadable = true

I tried this with 4.3 and 4.4 beta 1,2,3 and 4

Steps to reproduce

Launch Godot, edit some part of the code, compile and disappears every public code and not showing in godot GUI.

Before:

Image

After:

Image

Minimal reproduction project

Could happen with a new project.

Activity

  1. added this to the 4.x milestone on Feb 20, 2025
  2. added
    bug
    on Feb 20, 2025
  3. dsnopek commented on Feb 20, 2025

    @dsnopek
    Collaborator

    Thanks for the report!

    However, I'm not sure how much headway we'll be able to make without an MRP. I've relatively recently tested hot reload with Godot 4.3 and it was working, although, that was with scons. Based on your description it sounds like you're doing what you need to do for hot reload with cmake, but something must not be right if it works for me, but not for you.

    Could you share which version of godot-cpp you're using?

    We did at one point have an issue with the cmake configuration missing something needed for hot reload, but that should be fixed now.

  4. chriztheanvill commented on Feb 20, 2025

    @chriztheanvill
    Author

    I am using the master branch, I downloaded yesterday to test the godot beta 4.4.

    Could you share your compile flags ?

  5. ghuser404 commented on Feb 20, 2025

    @ghuser404

    The correct variable is GODOT_USE_HOT_RELOAD, not GODOT_ENABLE_HOT_RELOAD.

  6. chriztheanvill commented on Feb 20, 2025

    @chriztheanvill
    Author

    GODOT_USE_HOT_RELOAD

    Mmm same result, not working. Also noticed that.

    Before Compile:

    Image

    • Then, edit any part of my code, no matter if is "Collectable".
    • In Clion press the button to compile, but before finish, switch to godot, the changes not showing.

    Image

    • If I switch back to CLion, then back to godot, the info disappears.

    Image

  7. chriztheanvill commented on Feb 20, 2025

    @chriztheanvill
    Author

    Image

    Image

  8. ghuser404 commented on Feb 20, 2025

    @ghuser404

    If this still doesn't work, you will have to upload an example project for anyone to be able to help you with this issue.

  9. ghuser404 commented on Feb 20, 2025

    @ghuser404

    In Clion press the button to compile, but before finish, switch to godot, the changes not showing.

    Godot editor reloads GDExtension only on focus, i.e. if you open the editor before the compilation finishes, and compilation finishes when you're in the editor, you will not see the changes. You have to re-focus the editor. I opened an issue for that a while ago godotengine/godot-proposals#11684

  10. ghuser404 commented on Feb 20, 2025

    @ghuser404

    If I switch back to CLion, then back to godot, the info disappears.

    This means your hot reload is working. I'm not very sure what your issue is right now.

  11. chriztheanvill commented on Feb 20, 2025

    @chriztheanvill
    Author

    If I switch back to CLion, then back to godot, the info disappears.

    This means your hot reload is working. I'm not very sure what your issue is right now.

    For example, at start I set the Lv of the collectable:

    // header
    private:
    int m_lv { };
    
    public:
    auto GetLv( ) const -> int;
    auto SetLv(int val) -> void;
    
    // Source
    ClassDB::bind_method(D_METHOD("GetLv"), &Collectable::GetLv);
    ClassDB::bind_method(D_METHOD("SetLv", "val"), &Collectable::SetLv);
    ClassDB::add_property("Collectable", PropertyInfo(Variant::INT, "lv"), "SetLv", "GetLv");

    Compile and shows the info in godot, perfect.

    Then I want to work with this class, Adding methods, working with the process method, or just add other attribute,

    // header
    private:
    int m_lv { };
    bool m_isActive {}; // <--- Just an example
    

    Or If I edit any part of the project, for example, the player.cpp file. The Lv info that showed in Godot, disappear.

    Edit: The cmake file, is a mess, because I am trying many things.

    CMakeLists.txt
    conanfile.txt

  12. ghuser404 commented on Feb 20, 2025

    @ghuser404

    Upload all project sources, not just those 2 files. Create a small example project, if you don't want to share your sources.

  13. ghuser404 commented on Feb 20, 2025

    @ghuser404

    The problem is that your node becomes just Area2D instead of your class. I can't tell you the reason for that without seeing sources.

  14. chriztheanvill commented on Feb 20, 2025

    @chriztheanvill
    Author

    The problem is that your node becomes just Area2D instead of your class. I can't tell you the reason for that without seeing sources.

    I am making a new project.

    The problem is that your node becomes just Area2D instead of your class.

    I don't get it.

    class Collectable : public Area2D, public IObject {
    	GDCLASS(Collectable, Area2D)
    
  15. 12 remaining items

  16. chriztheanvill commented on Feb 21, 2025

    @chriztheanvill
    Author

    Yeah, I'm not sure about the GDREGISTER_RUNTIME_CLASS vs GDREGISTER_CLASS situation. Maybe you should open a separate issue for that. But I'm glad you got it working in the end.

    Almost, because I closed godot, and open again and if I try to modify something, removes everything, like this:

    Image

    I have to delete the .godot folder to again.

  17. ghuser404 commented on Feb 21, 2025

    @ghuser404

    Why don't you just use GDREGISTER_RUNTIME_CLASS if it works for you?

  18. ghuser404 commented on Feb 21, 2025

    @ghuser404

    The reason I think why it's failing is because GDREGISTER_CLASS runs your nodes in the editor, and when you rebuild the project, it destroys those objects and calls their destructors, which is where it probably crashes. I saw you had some code for connecting the signal in the constructor (which I think you should be using _ready for), but I don't think you were disconnecting the signal, which would be the reason for the crash.

  19. chriztheanvill commented on Feb 22, 2025

    @chriztheanvill
    Author

    Mmm... After playing with a new empty project with CMake. This was not the issue:

    GDREGISTER_RUNTIME_CLASS(Collectable); // This works with Hot-Reloading
      // GDREGISTER_CLASS(Collectable);              // This disables hot-reloading.

    Working with this new project, adding one by one my original code, godot stop working with hot-reloading when I start working with SQLiteCpp.

  20. dsnopek commented on Feb 24, 2025

    @dsnopek
    Collaborator

    @chriztheanvill: Thanks for sharing your project!

    Working with this new project, adding one by one my original code, godot stop working with hot-reloading when I start working with SQLiteCpp.

    So, you're saying that without SQLiteCpp, reloading works fine, but as soon as you add SQLiteCpp, then reloading doesn't work?

    It could be that there is something in SQLiteCpp that makes the unloading of your extensions not succeed, which would cause the subsequent reloading to fail.

    This is something we've encountered a couple times, for example: on MacOS, using any thread_local variable will prevent unloading from succeeding. Or, if using GCC, building without -fno-gnu-unique will break unloading.

    Are you using GCC? I don't know how Conan builds end up coming together, but is it possible the SQLiteCpp files are built without -fno-gnu-unique? Or, cmake configuration should be adding that, but I don't know if it'll make it into the SQLiteCpp build.

  21. chriztheanvill commented on Feb 24, 2025

    @chriztheanvill
    Author

    @chriztheanvill: Thanks for sharing your project!

    Working with this new project, adding one by one my original code, godot stop working with hot-reloading when I start working with SQLiteCpp.

    So, you're saying that without SQLiteCpp, reloading works fine, but as soon as you add SQLiteCpp, then reloading doesn't work?

    It could be that there is something in SQLiteCpp that makes the unloading of your extensions not succeed, which would cause the subsequent reloading to fail.

    This is something we've encountered a couple times, for example: on MacOS, using any thread_local variable will prevent unloading from succeeding. Or, if using GCC, building without -fno-gnu-unique will break unloading.

    Are you using GCC? I don't know how Conan builds end up coming together, but is it possible the SQLiteCpp files are built without -fno-gnu-unique? Or, cmake configuration should be adding that, but I don't know if it'll make it into the SQLiteCpp build.

    Hi.

    I am still playing with Godot + CMake with Conan, and yes, looks like Godot do not like SqliteCpp.

    void SInventory::_enter_tree( ) {
      UtilityFunctions::print("SInventory::_enter_tree( )");
      SQLite::Database db("data.db", SQLite::OPEN_READWRITE | SQLite::OPEN_CREATE);
    
      std::string qGetStoreItems { "SELECT * FROM StoreItems" };
    
      SQLite::Statement qItemsStore(db, qGetStoreItems);
    
      while (qItemsStore.executeStep( )) {
        int storeItemsID = qItemsStore.getColumn(0).getInt( );
        int storeItemsType = qItemsStore.getColumn(1).getInt( );
    
        SQLite::Statement qlistItems(
          db,
          "SELECT * FROM ListItems "
          "WHERE id = ?"
          "AND type = ?"
        );
        qlistItems.bind(1, storeItemsID);
        qlistItems.bind(2, storeItemsType);
        qlistItems.executeStep( );
    
        std::string name = qlistItems.getColumn(1).getString( );
    
        DataItem* item = memnew(DataItem);
        item->set_name(name.c_str( ));
    
        m_inventory.push_back(item); // m_inventory is an Array from godot::cpp
      }
    }

    About -fno-gnu-unique in my previous cmake config, yes, if I did not use it, the hot-reloading not works. But in this really really small cmake config, even without enabling -fno-gnu-unique or GODOT_USE_HOT_RELOAD the hot-reloading works ( Yes, I enabled -fno-gnu-unique and GODOT_USE_HOT_RELOAD in this cmake).

    The funny thing is:

    • Close godot.
    • Erase the .godot of the project.
    • Compile the project with the SqliteCpp code.
    • Open godot and everything works excellent. IF I close godot and open again, the hot-reloading stop working, I need to erase again the .godot folder to hot-reloading work.
  22. chriztheanvill commented on Feb 26, 2025

    @chriztheanvill
    Author

    Still happen with rc 2 and using the master of godot-cpp.

  23. ghuser404 commented on Feb 27, 2025

    @ghuser404

    Possibly your sql code throws an exception in destructor? Try removing the sql code, just linking with it, and see if you get the same issue.

  24. chriztheanvill commented on Feb 28, 2025

    @chriztheanvill
    Author

    Possibly your sql code throws an exception in destructor? Try removing the sql code, just linking with it, and see if you get the same issue.

    Ahh... I tried as you said and works. So, I start to using Sqlite3 instead of SQliteCpp, but same issue. If I do not use sqlite everything works excellent, but if I try Sqlite3 or SQliteCpp:

    • Close godot.
    • Erase the .godot of the project.
    • Compile the project with the SqliteCpp or Sqlite3 code.
    • Open godot and everything works excellent. IF I close godot and open again, the hot-reloading stop working, I need to erase again the .godot folder to hot-reloading work.

    This is my Sqlite3 code:

    sqlite3_stmt* stmt = NULL;
    
      //  // ===============================
      sqlite3* db;
      if (sqlite3_open("data.db", &db) != SQLITE_OK) {
    	UtilityFunctions::print("SInventory::SInventory =============== cant connect to sqlite");
    	return;
      }
    
      std::string qGetStoreItems { "SELECT * FROM StoreItems" };
    
      int result = sqlite3_prepare_v2(db, qGetStoreItems.c_str( ), -1, &stmt, NULL);
    
      if (result != SQLITE_OK) {
    	UtilityFunctions::print("SInventory::SInventory Sqlite result Error !!!", sqlite3_errmsg(db));
    	return;
      }
      while ((result = sqlite3_step(stmt)) == SQLITE_ROW) {
    	// Solo muestra el nombre de las columnas
    	// UtilityFunctions::print("id: ", sqlite3_column_name(stmt, 0));
    	// UtilityFunctions::print("--: ", sqlite3_column_name(stmt, 1));
    
    	// Valores
    	// std::cout << "\nid: " << sqlite3_column_text(stmt, 0);
    	UtilityFunctions::print(
    	  "id: ",
    	  sqlite3_column_int(stmt, 0),
    	  " - ",
    	  reinterpret_cast<const char*>(sqlite3_column_text(stmt, 1))
    	  // std::string(reinterpret_cast<const char*>(sqlite3_column_text(stmt, 0))).c_str( )
    	);
    	// UtilityFunctions::print("--: ", sqlite3_column_text(stmt, 1));
      }
    
      sqlite3_finalize(stmt);
    
      sqlite3_close(db);

    I tried to set in the Constructor, _ready, _enter_tree.

  25. chriztheanvill commented on Feb 28, 2025

    @chriztheanvill
    Author

    Just tried again with rc3 and download the godot-cpp master again and not working.

  26. chriztheanvill commented on Mar 3, 2025

    @chriztheanvill
    Author

    And I tried with 4.4 with godot-cpp in 4.4 branch. Still the issues.

  27. chriztheanvill commented on Mar 3, 2025

    @chriztheanvill
    Author

    And just tried instead of Conan, Vcpkg and same result.

  28. chriztheanvill commented on Mar 3, 2025

    @chriztheanvill
    Author

    The funny thing: In C++, if I erase the .godot folder, just the first time that I open godot, let me to use hot-reloading, if I close it, and open again, hot-reloading not work.

    In C# adding:

    dotnet add package Newtonsoft.Json
    dotnet add package Microsoft.Data.Sqlite

    Works excellent.

  29. chriztheanvill commented on Mar 18, 2025

    @chriztheanvill
    Author

    The issues still in 4.4.rc1

  30. chriztheanvill commented on Oct 12, 2025

    @chriztheanvill
    Author

    The issues still in 4.5-stable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugneeds testing

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions