Skip to content

Deleting objects created by GDExtension randomly cause crash. #629

Closed

Description

@bruvzg

godot-cpp: 5826fd52592c5ed9051c7ef5dbfbd9295fb23607
godot: godotengine/godot#52192

Deleting objects created by GDExtension randomly cause crash (seems to never happen when running under LLDB, probably there's uninitialized variable somewhere). When it is running properly, Object destructor is called and no leaks is detected.

The object is created and to the singleton in the driver_initializer callback:

void register_types() {
	ClassDB::register_class<TextServerTest>();

	TextServerManager *ts_man = TextServerManager::get_singleton();
	if (ts_man) {
		Ref<TextServerTest> ts;
		ts.instantiate();
		ts_man->add_interface(ts);
	}
}

GDNativeBool GDN_EXPORT ts_test_init(const GDNativeInterface *p_interface, const GDNativeExtensionClassLibraryPtr p_library, GDNativeInitialization *r_initialization) {
	GDExtensionBinding::InitObject init_obj(p_interface, p_library, r_initialization);

	init_obj.register_driver_initializer(register_types);

	return init_obj.init();
}

And deleted from Main::cleanup on singleton deletion:

TextServerManager::~TextServerManager() {
	if (primary_interface.is_valid()) {
		primary_interface.unref();
	}
	while (interfaces.size() > 0) {
		interfaces.remove(0);
	}
	singleton = nullptr;
}

Crash log:

Exception Type:        EXC_BAD_ACCESS (SIGABRT)
Exception Codes:       KERN_INVALID_ADDRESS at 0x0000000100000008
Exception Note:        EXC_CORPSE_NOTIFY

VM Regions Near 0x100000008:
--> 
    __TEXT                      102af8000-109ec4000    [115.8M] r-x/r-x SM=COW  /Users/*/*.arm64

Application Specific Information:
abort() called

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libsystem_kernel.dylib        	0x000000018044ce68 __pthread_kill + 8
1   libsystem_pthread.dylib       	0x000000018047f43c pthread_kill + 292
2   libsystem_c.dylib             	0x00000001803c7454 abort + 124
3   godot.osx.tools.arm64         	0x0000000102e8d1a0 handle_crash(int) + 2152 (crash_handler_osx.mm:163)
4   libsystem_platform.dylib      	0x00000001804cac44 _sigtramp + 56
5   godot.osx.tools.arm64         	0x00000001074e9d0c RefCounted::unreference() + 264 (ref_counted.cpp:85)
6   godot.osx.tools.arm64         	0x0000000102edb8a4 Ref<TextServer>::unref() + 44 (ref_counted.h:220)
7   godot.osx.tools.arm64         	0x0000000102edb864 Ref<TextServer>::~Ref() + 28 (ref_counted.h:233)
8   godot.osx.tools.arm64         	0x0000000102ec69cc Ref<TextServer>::~Ref() + 28 (ref_counted.h:232)
9   godot.osx.tools.arm64         	0x0000000106855b14 CowData<Ref<TextServer> >::_unref(void*) + 156 (cowdata.h:218)
10  godot.osx.tools.arm64         	0x00000001068556c4 CowData<Ref<TextServer> >::resize(int) + 148 (cowdata.h:276)
11  godot.osx.tools.arm64         	0x0000000106856128 CowData<Ref<TextServer> >::remove(int) + 300 (cowdata.h:178)
12  godot.osx.tools.arm64         	0x000000010683e4f8 Vector<Ref<TextServer> >::remove(int) + 36 (vector.h:70)
13  godot.osx.tools.arm64         	0x000000010683e770 TextServerManager::~TextServerManager() + 192 (text_server.cpp:148)
14  godot.osx.tools.arm64         	0x000000010683e82c TextServerManager::~TextServerManager() + 28 (text_server.cpp:143)
15  godot.osx.tools.arm64         	0x0000000102ec6b60 void memdelete<TextServerManager>(TextServerManager*) + 48 (memory.h:109)
16  godot.osx.tools.arm64         	0x0000000102ed9b00 Main::cleanup(bool) + 648 (main.cpp:2757)
17  godot.osx.tools.arm64         	0x0000000102ebe994 main + 844 (godot_main_osx.mm:81)
18  libdyld.dylib                 	0x000000018049d430 start + 4

Activity

  1. added
    bug
    topic:gdextension
    on Sep 28, 2021
  2. added this to the 4.0 milestone on Sep 28, 2021
  3. bruvzg commented on Feb 21, 2022

    @bruvzg
    MemberAuthor

    Not sure when it was fixed, but it's no longer reproducible.

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

    bugtopic:gdextension

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions