migueldeicaza / SwiftGodot

New Godot bindings for Swift
https://migueldeicaza.github.io/SwiftGodotDocs/tutorials/swiftgodot-tutorials/
MIT License
1.19k stars 77 forks source link

Crash when one Godot subclass creates another via an ivar #616

Closed cbackas42 closed 4 days ago

cbackas42 commented 4 days ago

Describe the bug If I have two classes that both subclass a Godot type (Node3D in this case), and one of them contains an instance of the other via an ivar, then the Swift runtime crashes/exits with ABORT.

For questions, please use the Discussions page.

To Reproduce Create a hierarchy like so:

@Godot class A :Node3D { var b: B = B() }

@Godot class B: Node3D { }

Then load the project in the Editor.

Expected behavior I expected the classes to be loaded without incident.

Desktop (please complete the following information):

Additional context Here is the crash report I got. This happened 100% of the time until I changed my ivar into an optional. In the report below, "Class A" was named "HeadAnimator" and "Class B" was named "HeadComponent"

Process: Godot [34432] Path: /Users/USER/*/Godot Debug.app/Contents/MacOS/Godot Identifier: org.godotengine.godot Version: 4.3 (4.3) Code Type: ARM-64 (Native) Parent Process: launchd [1] User ID: 501

Date/Time: 2024-11-24 01:00:38.0477 -0800 OS Version: macOS 15.1.1 (24B91) Report Version: 12 Anonymous UUID: A2C3C2B3-8DF9-93E2-D938-402A0BDFFF79

Time Awake Since Boot: 330000 seconds

System Integrity Protection: enabled

Crashed Thread: 0 Dispatch queue: com.apple.main-thread

Exception Type: EXC_BREAKPOINT (SIGABRT) Exception Codes: 0x0000000000000001, 0x000000019c41ab4c

Termination Reason: Namespace SIGNAL, Code 6 Abort trap: 6 Terminating Process: Godot [34432]

Application Specific Information: abort() called

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread 0 libsystem_kernel.dylib 0x18b74e600 pthread_kill + 8 1 libsystem_pthread.dylib 0x18b786f70 pthread_kill + 288 2 libsystem_c.dylib 0x18b693908 abort + 128 3 Godot 0x1007d2f14 0x10000c000 + 8154900 4 libsystem_platform.dylib 0x18b7bc184 _sigtramp + 56 5 libswiftCore.dylib 0x19c41ab4c assertionFailure(:_:file:line:flags:) + 592 6 libSanctuaryDriver.dylib 0x1147b3838 closure #1 in variable initialization expression of static HeadComponent._initializeClass + 276 (@swiftmacro15SanctuaryDriver13HeadComponent5GodotfMm.swift:8) 7 libSanctuaryDriver.dylib 0x1147b371c one-time initialization function for _initializeClass + 12 (@swiftmacro15SanctuaryDriver13HeadComponent5GodotfMm.swift:6) 8 libdispatch.dylib 0x18b5d4658 _dispatch_client_callout + 20 9 libdispatch.dylib 0x18b5d5ea0 _dispatch_once_callout + 32 10 libSanctuaryDriver.dylib 0x1147b370c HeadComponent._initializeClass.unsafeMutableAddressor + 76 (@swiftmacro15SanctuaryDriver13HeadComponent5GodotfMm.swift:6) 11 libSanctuaryDriver.dylib 0x1147b36b4 static HeadComponent.classInitializer.getter + 32 (@swiftmacro15SanctuaryDriver13HeadComponent5GodotfMm.swift:3) 12 libSwiftGodot.dylib 0x11daa949c Wrapped.init() + 672 (Wrapped.swift:260) 13 libSwiftGodot.dylib 0x11c8682cc Object.init() + 32 14 libSwiftGodot.dylib 0x11c7ba414 Node.init() + 32 15 libSwiftGodot.dylib 0x11c7f7e3c Node3D.init() + 32 16 libSanctuaryDriver.dylib 0x1147b50b0 HeadComponent.init() + 1068 (HeadComponent.swift:92) 17 libSanctuaryDriver.dylib 0x1147b4c78 HeadComponent.__allocating_init() + 44 18 libSanctuaryDriver.dylib 0x1147a96c8 HeadAnimator.init() + 2128 (HeadAnimator.swift:88) 19 libSanctuaryDriver.dylib 0x1147a8e6c HeadAnimator.allocatinginit() + 44 20 libSwiftGodot.dylib 0x11daaad20 createFunc(:) + 264 (Wrapped.swift:478) 21 libSwiftGodot.dylib 0x11daaac10 @objc createFunc(_:) + 12 22 Godot 0x104134318 ClassDB::class_get_default_property_value(StringName const&, StringName const&, bool) + 1340 23 Godot 0x1017326c0 0x10000c000 + 24274624 24 Godot 0x10172b668 DocTools::generate(BitField) + 3336 25 Godot 0x1017fdc64 EditorHelp::_gen_extensions_docs() + 28 26 Godot 0x10413ea8c CallQueue::_call_function(Callable const&, Variant const, int, bool) + 296 27 Godot 0x10413ed48 CallQueue::flush() + 352 28 Godot 0x10238b460 SceneTree::physics_process(double) + 244 29 Godot 0x100833c4c Main::iteration() + 596 30 Godot 0x1007ce0bc OS_MacOS::run() + 168 31 Godot 0x1007fa124 main + 392 32 dyld 0x18b404274 start + 2840

Thread 1: 0 libsystem_pthread.dylib 0x18b7820e8 start_wqthread + 0

Thread 2: 0 libsystem_pthread.dylib 0x18b7820e8 start_wqthread + 0

Thread 3: 0 libsystem_pthread.dylib 0x18b7820e8 start_wqthread + 0

Thread 4: 0 libsystem_kernel.dylib 0x18b7495cc psynch_cvwait + 8 1 libsystem_pthread.dylib 0x18b787894 _pthread_cond_wait + 1204 2 libc++.1.dylib 0x18b6bd578 std::__1::condition_variable::wait(std::1::unique_lock&) + 28 3 Godot 0x103d65e54 _IP_ResolverPrivate::_thread_function(void) + 152 4 Godot 0x103c5a46c Thread::callback(unsigned long long, Thread::Settings const&, void ()(void), void) + 120 5 Godot 0x103c5a7d4 0x10000c000 + 63236052 6 libsystem_pthread.dylib 0x18b7872e4 _pthread_start + 136 7 libsystem_pthread.dylib 0x18b7820fc thread_start + 8

Thread 5: 0 libsystem_kernel.dylib 0x18b7495cc psynch_cvwait + 8 1 libsystem_pthread.dylib 0x18b787894 _pthread_cond_wait + 1204 2 libc++.1.dylib 0x18b6bd578 std::__1::condition_variable::wait(std::1::unique_lock&) + 28 3 Godot 0x10418fb68 WorkerThreadPool::_thread_function(void) + 272 4 Godot 0x103c5a46c Thread::callback(unsigned long long, Thread::Settings const&, void ()(void), void) + 120 5 Godot 0x103c5a7d4 0x10000c000 + 63236052 6 libsystem_pthread.dylib 0x18b7872e4 _pthread_start + 136 7 libsystem_pthread.dylib 0x18b7820fc thread_start + 8

Thread 6: 0 libsystem_kernel.dylib 0x18b7495cc psynch_cvwait + 8 1 libsystem_pthread.dylib 0x18b787894 _pthread_cond_wait + 1204 2 libc++.1.dylib 0x18b6bd578 std::__1::condition_variable::wait(std::1::unique_lock&) + 28 3 Godot 0x10418fb68 WorkerThreadPool::_thread_function(void) + 272 4 Godot 0x103c5a46c Thread::callback(unsigned long long, Thread::Settings const&, void ()(void), void) + 120 5 Godot 0x103c5a7d4 0x10000c000 + 63236052 6 libsystem_pthread.dylib 0x18b7872e4 _pthread_start + 136 7 libsystem_pthread.dylib 0x18b7820fc thread_start + 8

Thread 7: 0 libsystem_kernel.dylib 0x18b7495cc psynch_cvwait + 8 1 libsystem_pthread.dylib 0x18b787894 _pthread_cond_wait + 1204 2 libc++.1.dylib 0x18b6bd578 std::__1::condition_variable::wait(std::1::unique_lock&) + 28 3 Godot 0x10418fb68 WorkerThreadPool::_thread_function(void) + 272 4 Godot 0x103c5a46c Thread::callback(unsigned long long, Thread::Settings const&, void ()(void), void) + 120 5 Godot 0x103c5a7d4 0x10000c000 + 63236052 6 libsystem_pthread.dylib 0x18b7872e4 _pthread_start + 136 7 libsystem_pthread.dylib 0x18b7820fc thread_start + 8

Thread 8: 0 libsystem_kernel.dylib 0x18b7495cc psynch_cvwait + 8 1 libsystem_pthread.dylib 0x18b787894 _pthread_cond_wait + 1204 2 libc++.1.dylib 0x18b6bd578 std::__1::condition_variable::wait(std::1::unique_lock&) + 28 3 Godot 0x10418fb68 WorkerThreadPool::_thread_function(void) + 272 4 Godot 0x103c5a46c Thread::callback(unsigned long long, Thread::Settings const&, void ()(void), void) + 120 5 Godot 0x103c5a7d4 0x10000c000 + 63236052 6 libsystem_pthread.dylib 0x18b7872e4 _pthread_start + 136 7 libsystem_pthread.dylib 0x18b7820fc thread_start + 8

Thread 9: 0 libsystem_kernel.dylib 0x18b7495cc psynch_cvwait + 8 1 libsystem_pthread.dylib 0x18b787894 _pthread_cond_wait + 1204 2 libc++.1.dylib 0x18b6bd578 std::__1::condition_variable::wait(std::1::unique_lock&) + 28 3 Godot 0x10418fb68 WorkerThreadPool::_thread_function(void) + 272 4 Godot 0x103c5a46c Thread::callback(unsigned long long, Thread::Settings const&, void ()(void), void) + 120 5 Godot 0x103c5a7d4 0x10000c000 + 63236052 6 libsystem_pthread.dylib 0x18b7872e4 _pthread_start + 136 7 libsystem_pthread.dylib 0x18b7820fc thread_start + 8

Thread 10: 0 libsystem_kernel.dylib 0x18b7495cc psynch_cvwait + 8 1 libsystem_pthread.dylib 0x18b787894 _pthread_cond_wait + 1204 2 libc++.1.dylib 0x18b6bd578 std::__1::condition_variable::wait(std::1::unique_lock&) + 28 3 Godot 0x10418fb68 WorkerThreadPool::_thread_function(void) + 272 4 Godot 0x103c5a46c Thread::callback(unsigned long long, Thread::Settings const&, void ()(void), void) + 120 5 Godot 0x103c5a7d4 0x10000c000 + 63236052 6 libsystem_pthread.dylib 0x18b7872e4 _pthread_start + 136 7 libsystem_pthread.dylib 0x18b7820fc thread_start + 8

Thread 11: 0 libsystem_kernel.dylib 0x18b7495cc psynch_cvwait + 8 1 libsystem_pthread.dylib 0x18b787894 _pthread_cond_wait + 1204 2 libc++.1.dylib 0x18b6bd578 std::__1::condition_variable::wait(std::1::unique_lock&) + 28 3 Godot 0x10418fb68 WorkerThreadPool::_thread_function(void) + 272 4 Godot 0x103c5a46c Thread::callback(unsigned long long, Thread::Settings const&, void ()(void), void) + 120 5 Godot 0x103c5a7d4 0x10000c000 + 63236052 6 libsystem_pthread.dylib 0x18b7872e4 _pthread_start + 136 7 libsystem_pthread.dylib 0x18b7820fc thread_start + 8

Thread 12: 0 libsystem_kernel.dylib 0x18b7495cc psynch_cvwait + 8 1 libsystem_pthread.dylib 0x18b787894 _pthread_cond_wait + 1204 2 libc++.1.dylib 0x18b6bd578 std::__1::condition_variable::wait(std::1::unique_lock&) + 28 3 Godot 0x10418fb68 WorkerThreadPool::_thread_function(void) + 272 4 Godot 0x103c5a46c Thread::callback(unsigned long long, Thread::Settings const&, void ()(void), void) + 120 5 Godot 0x103c5a7d4 0x10000c000 + 63236052 6 libsystem_pthread.dylib 0x18b7872e4 _pthread_start + 136 7 libsystem_pthread.dylib 0x18b7820fc thread_start + 8

Thread 13: 0 libsystem_kernel.dylib 0x18b7495cc psynch_cvwait + 8 1 libsystem_pthread.dylib 0x18b787894 _pthread_cond_wait + 1204 2 libc++.1.dylib 0x18b6bd578 std::__1::condition_variable::wait(std::1::unique_lock&) + 28 3 Godot 0x10418fb68 WorkerThreadPool::_thread_function(void) + 272 4 Godot 0x103c5a46c Thread::callback(unsigned long long, Thread::Settings const&, void ()(void), void) + 120 5 Godot 0x103c5a7d4 0x10000c000 + 63236052 6 libsystem_pthread.dylib 0x18b7872e4 _pthread_start + 136 7 libsystem_pthread.dylib 0x18b7820fc thread_start + 8

Thread 14: 0 libsystem_kernel.dylib 0x18b7495cc psynch_cvwait + 8 1 libsystem_pthread.dylib 0x18b787894 _pthread_cond_wait + 1204 2 libc++.1.dylib 0x18b6bd578 std::__1::condition_variable::wait(std::1::unique_lock&) + 28 3 Godot 0x10418fb68 WorkerThreadPool::_thread_function(void) + 272 4 Godot 0x103c5a46c Thread::callback(unsigned long long, Thread::Settings const&, void ()(void), void) + 120 5 Godot 0x103c5a7d4 0x10000c000 + 63236052 6 libsystem_pthread.dylib 0x18b7872e4 _pthread_start + 136 7 libsystem_pthread.dylib 0x18b7820fc thread_start + 8

Thread 15:: com.apple.NSEventThread 0 libsystem_kernel.dylib 0x18b745e34 mach_msg2_trap + 8 1 libsystem_kernel.dylib 0x18b7585d0 mach_msg2_internal + 80 2 libsystem_kernel.dylib 0x18b74e9d8 mach_msg_overwrite + 480 3 libsystem_kernel.dylib 0x18b74617c mach_msg + 24 4 CoreFoundation 0x18b86dedc CFRunLoopServiceMachPort + 160 5 CoreFoundation 0x18b86c73c CFRunLoopRun + 1212 6 CoreFoundation 0x18b86bbc4 CFRunLoopRunSpecific + 588 7 AppKit 0x18f4bcb8c _NSEventThread + 148 8 libsystem_pthread.dylib 0x18b7872e4 _pthread_start + 136 9 libsystem_pthread.dylib 0x18b7820fc thread_start + 8

Thread 16:: caulk.messenger.shared:17 0 libsystem_kernel.dylib 0x18b745db0 semaphore_wait_trap + 8 1 caulk 0x1967b30e0 caulk::semaphore::timed_wait(double) + 220 2 caulk 0x1967b2f8c caulk::concurrent::details::worker_thread::run() + 36 3 caulk 0x1967b2c60 void caulk::thread_proxy<std::__1::tuple<caulk::thread::attributes, void (caulk::concurrent::details::worker_thread::)(), std::__1::tuple<caulk::concurrent::details::worker_thread>>>(void) + 96 4 libsystem_pthread.dylib 0x18b7872e4 _pthread_start + 136 5 libsystem_pthread.dylib 0x18b7820fc thread_start + 8

Thread 17:: caulk.messenger.shared:high 0 libsystem_kernel.dylib 0x18b745db0 semaphore_wait_trap + 8 1 caulk 0x1967b30e0 caulk::semaphore::timed_wait(double) + 220 2 caulk 0x1967b2f8c caulk::concurrent::details::worker_thread::run() + 36 3 caulk 0x1967b2c60 void caulk::thread_proxy<std::__1::tuple<caulk::thread::attributes, void (caulk::concurrent::details::worker_thread::)(), std::__1::tuple<caulk::concurrent::details::worker_thread>>>(void) + 96 4 libsystem_pthread.dylib 0x18b7872e4 _pthread_start + 136 5 libsystem_pthread.dylib 0x18b7820fc thread_start + 8

Thread 18:: caulk::deferred_logger 0 libsystem_kernel.dylib 0x18b745db0 semaphore_wait_trap + 8 1 caulk 0x1967b30e0 caulk::semaphore::timed_wait(double) + 220 2 caulk 0x1967b2f8c caulk::concurrent::details::worker_thread::run() + 36 3 caulk 0x1967b2c60 void caulk::thread_proxy<std::__1::tuple<caulk::thread::attributes, void (caulk::concurrent::details::worker_thread::)(), std::__1::tuple<caulk::concurrent::details::worker_thread>>>(void) + 96 4 libsystem_pthread.dylib 0x18b7872e4 _pthread_start + 136 5 libsystem_pthread.dylib 0x18b7820fc thread_start + 8

Thread 19:: com.apple.audio.IOThread.client 0 libsystem_kernel.dylib 0x18b745dbc semaphore_wait_signal_trap + 8 1 caulk 0x1967cf5c4 caulk::mach::semaphore::wait_signal_or_error(caulk::mach::semaphore&) + 36 2 CoreAudio 0x18e294998 HALC_ProxyIOContext::IOWorkLoop() + 4892 3 CoreAudio 0x18e292f00 invocation function for block in HALC_ProxyIOContext::HALC_ProxyIOContext(unsigned int, unsigned int) + 176 4 CoreAudio 0x18e43f108 HALC_IOThread::Entry(void*) + 88 5 libsystem_pthread.dylib 0x18b7872e4 _pthread_start + 136 6 libsystem_pthread.dylib 0x18b7820fc thread_start + 8

Thread 20: 0 libsystem_kernel.dylib 0x18b7495cc psynch_cvwait + 8 1 libsystem_pthread.dylib 0x18b787894 _pthread_cond_wait + 1204 2 libc++.1.dylib 0x18b6bd578 std::__1::condition_variable::wait(std::1::unique_lock&) + 28 3 Godot 0x101194b1c 0x10000c000 + 18385692 4 Godot 0x1011949c8 0x10000c000 + 18385352 5 libsystem_pthread.dylib 0x18b7872e4 _pthread_start + 136 6 libsystem_pthread.dylib 0x18b7820fc thread_start + 8

Thread 21: 0 libsystem_kernel.dylib 0x18b7493c8 __semwait_signal + 8 1 libsystem_c.dylib 0x18b628714 nanosleep + 220 2 Godot 0x10143cf40 OS_Unix::delay_usec(unsigned int) const + 64 3 Godot 0x1015923b4 EditorExportPlatformAndroid::_check_for_changes_poll_thread(void) + 7496 4 Godot 0x103c5a46c Thread::callback(unsigned long long, Thread::Settings const&, void ()(void), void) + 120 5 Godot 0x103c5a7d4 0x10000c000 + 63236052 6 libsystem_pthread.dylib 0x18b7872e4 _pthread_start + 136 7 libsystem_pthread.dylib 0x18b7820fc thread_start + 8

Thread 22: 0 libsystem_kernel.dylib 0x18b7493c8 __semwait_signal + 8 1 libsystem_c.dylib 0x18b628714 nanosleep + 220 2 Godot 0x10143cf40 OS_Unix::delay_usec(unsigned int) const + 64 3 Godot 0x1015ec3bc EditorExportPlatformIOS::_check_for_changes_poll_thread(void) + 10000 4 Godot 0x103c5a46c Thread::callback(unsigned long long, Thread::Settings const&, void ()(void), void) + 120 5 Godot 0x103c5a7d4 0x10000c000 + 63236052 6 libsystem_pthread.dylib 0x18b7872e4 _pthread_start + 136 7 libsystem_pthread.dylib 0x18b7820fc thread_start + 8

Thread 23: 0 libsystem_kernel.dylib 0x18b7495cc psynch_cvwait + 8 1 libsystem_pthread.dylib 0x18b787894 _pthread_cond_wait + 1204 2 libc++.1.dylib 0x18b6bd578 std::__1::condition_variable::wait(std::1::unique_lock&) + 28 3 Godot 0x1021f41e8 TilesEditorUtils::_thread() + 276 4 Godot 0x103c5a46c Thread::callback(unsigned long long, Thread::Settings const&, void ()(void), void*) + 120 5 Godot 0x103c5a7d4 0x10000c000 + 63236052 6 libsystem_pthread.dylib 0x18b7872e4 _pthread_start + 136 7 libsystem_pthread.dylib 0x18b7820fc thread_start + 8

Thread 0 crashed with ARM Thread State (64-bit): x0: 0x0000000000000000 x1: 0x0000000000000000 x2: 0x0000000000000000 x3: 0x0000000000000000 x4: 0x0000000000000001 x5: 0x00000000b100084d x6: 0x00006000039a9300 x7: 0x0000000000000000 x8: 0x39c2e41a2137166f x9: 0x39c2e41bd1beae2f x10: 0x0000000000000002 x11: 0x0000010000000000 x12: 0x00000000fffffffd x13: 0x0000000000000000 x14: 0x0000000000000000 x15: 0x0000000000000000 x16: 0x0000000000000148 x17: 0x00000001f8af9850 x18: 0x0000000000000000 x19: 0x0000000000000006 x20: 0x0000000000000103 x21: 0x00000001f089b920 x22: 0x000000000000001e x23: 0x0000000105e32b39 x24: 0x0000000105e32b59 x25: 0x0000000105e32b4e x26: 0x000000014e87e180 x27: 0x000000016fdf08a8 x28: 0x0000000000000000 fp: 0x000000016fdeffe0 lr: 0x000000018b786f70 sp: 0x000000016fdeffc0 pc: 0x000000018b74e600 cpsr: 0x40001000 far: 0x0000000000000000 esr: 0x56000080 Address size fault

cbackas42 commented 4 days ago

Actually, I think I was wrong about the cause of this; I believe that the real cause is that the EntryPointGeneratorPlugin is not detecting/exporting my HeadComponent on one of my machines, and therefore it's not in Godot's ClassDB when it's supposed to be created. I was fooling myself because changing to an Optional seemed to fix the issue, and also because it was working fine on one computer and not another.