Skip to content

Macros "_THREAD_SAFE_XXX" in " include/godot_cpp/core/mutex_lock.hpp" are not work correctly in godot-cpp. #2020

Description

@Daylily-Zeleen

Godot version

4.7-stable

godot-cpp version

ba0edfe

System information

Windows 10, i7-8750h

Issue description

Macros "_THREAD_SAFE_XXX" in " include/godot_cpp/core/mutex_lock.hpp" use godot::Mutex without memnew() or Ref<T>, it will lead to the crash CRASH_NOW_MSG("BUG: Godot Object created without binding callbacks. Did you forget to use memnew()?");

It seems that "include/godot_cpp/core/mutex_lock.hpp" is simply migrated from godot source, we should do some change by using std::mutex or godot::Ref<godot::Mutex>, or consider the possibility of using some godot object without memnew().

Steps to reproduce

Just use _THREAD_SAFE_CLASS_ in any class and try to instantiate it.

// register_types.cpp
...
#include <godot_cpp/core/mutex_lock.hpp>

class MutexTest {
    _THREAD_SAFE_CLASS_

public: 
    void test() {
        ...
    }
};

...

void initialize_gdextension_types(ModuleInitializationLevel p_level)
{
	MutexTest  test; // Crash
	...
}

Minimal reproduction project

N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions