godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.98k stars 21.16k forks source link

A propagate_notification call crashes the game #92757

Open BimDav opened 5 months ago

BimDav commented 5 months ago

Tested versions

4.2.2.stable

System information

MacOS Ventura 13.5.2 M2

Issue description

I have had several random crashes in my game, with this stack trace:

USER ERROR: Caller thread can't call this function in this node (/root). Use call_deferred() or call_thread_group() instead.
   at: propagate_notification (scene/main/node.cpp:2249)

================================================================
handle_crash: Program crashed with signal 11
Engine version: Godot Engine v4.2.2.stable.official (15073afe3856abd2aa1622492fe50026c7d63dc1)
Dumping the backtrace. Please include this when reporting the bug to the project developer.
[1] 1   libsystem_platform.dylib            0x000000018ea46a24 _sigtramp + 56
[2] 2   Network                             0x0000000194f9e254 nw_resolver_cancel + 704
[3] 3   Network                             0x00000001952af234 -[NWConcrete_nw_endpoint_resolver cancelWithHandler:forced:] + 228
[4] 4   Network                             0x00000001952ba474 nw_endpoint_handler_cancel + 1116
[5] 5   Network                             0x00000001957f5414 -[NWConcrete_nw_endpoint_flow cancelWithHandler:forced:] + 932
[6] 6   Network                             0x00000001952ba474 nw_endpoint_handler_cancel + 1116
[7] 7   Network                             0x00000001952109e4 __nw_connection_cancel_inner_block_invoke + 1248
[8] 8   Network                             0x0000000195210260 nw_connection_cancel_inner + 328
[9] 9   Network                             0x000000019520fe7c nw_connection_cancel + 116
[10] 10  CFNetwork                           0x00000001933bba5c CFURLDownloadCancel + 41484
[11] 11  CFNetwork                           0x00000001932b1418 CFHTTPMessageGetTypeID + 736
[12] 12  CFNetwork                           0x000000019333b9ec CFHTTPMessageCreateResponse + 1592
[13] 13  libdispatch.dylib                   0x000000018e866874 _dispatch_call_block_and_release + 32
[14] 14  libdispatch.dylib                   0x000000018e868400 _dispatch_client_callout + 20
[15] 15  libdispatch.dylib                   0x000000018e86fa88 _dispatch_lane_serial_drain + 668
[16] 16  libdispatch.dylib                   0x000000018e87062c _dispatch_lane_invoke + 436
[17] 17  libdispatch.dylib                   0x000000018e8718e8 _dispatch_workloop_invoke + 1764
[18] 18  libdispatch.dylib                   0x000000018e87b244 _dispatch_workloop_worker_thread + 648
[19] 19  libsystem_pthread.dylib             0x000000018ea14074 _pthread_wqthread + 288
[20] 20  libsystem_pthread.dylib             0x000000018ea12d94 start_wqthread + 8
-- END OF BACKTRACE --
================================================================

Edit: I should have precised that I don't have any call to propagate_notification in my code, not do I use threads. It is an engine call

Steps to reproduce

This is hard to reproduce, it seems possible to happen at any time.

Minimal reproduction project (MRP)

see above

AThousandShips commented 5 months ago

Since none of this is showing libraries for the engine itself it seems it might be external, some error in the OS or similar, not directly the engine

BimDav commented 5 months ago

Maybe, but the error begins with the error in propagate_notification. I also have edited the first post to precise that the propagate_notificationcall that seems to cause the crash is not called from my code.

AThousandShips commented 5 months ago

That's not necessarily relevant directly, as it's not part of the stack trace, what I mean is that it's not certain the crash is due to bad code in the editor, but something broken in the system libraries etc.

lmorao commented 5 months ago

I get these ones very often as well. I think it might be the same thing as this other issue https://github.com/godotengine/godot/issues/71010

Godot v4.2.1.stable - macOS 14.5.0 - Vulkan (Forward+) - integrated Apple M1 Pro - Apple M1 Pro (8 Threads)

USER ERROR: Caller thread can't call this function in this node (/root). Use call_deferred() or call_thread_group() instead.
   at: propagate_notification (scene/main/node.cpp:2236)

================================================================
handle_crash: Program crashed with signal 11
Engine version: Godot Engine v4.2.1.stable.official (b09f793f564a6c95dc76acc654b390e68441bd01)
Dumping the backtrace. Please include this when reporting the bug to the project developer.
[1] 1   libsystem_platform.dylib            0x000000019110b584 _sigtramp + 56
[2] 2   CoreFoundation                      0x0000000191174218 -[__NSDictionaryM setObject:forKey:] + 348
[3] 3   Metal                               0x000000019b566d58 -[MTLStructTypeInternal initWithMembers:count:] + 268
[4] deserializeStructArgument(id<MTLDeviceSPI>, AirReflection::NodeId const*, flatbuffers::Vector<AirReflection::NodeId const*::Offset<id<MTLDeviceSPI>::Node>> const*, ReflectionDeserializeContext&, bool*)
[5] deserializeStructArgument(id<MTLDeviceSPI>, AirReflection::NodeId const*, flatbuffers::Vector<AirReflection::NodeId const*::Offset<id<MTLDeviceSPI>::Node>> const*, ReflectionDeserializeContext&, bool*)
[6] deserializeArgument(id<MTLDeviceSPI>, AirReflection::NodeId const*, flatbuffers::Vector<AirReflection::NodeId const*::Offset<id<MTLDeviceSPI>::Node>> const*, ReflectionDeserializeContext&, MTLBindingInternal**)
[7] deserializeArguments(id<MTLDeviceSPI>, flatbuffers::Vector<AirReflection::NodeId const*> const*, flatbuffers<id<MTLDeviceSPI>::Offset<flatbuffers::Vector::Node>> const*, ReflectionDeserializeContext&, MTLBindingInternal**&, bool, unsigned int*)
[8] MTLVertexReflectionDeserializerAIR::deserialize(id<MTLDeviceSPI>, NSObject<OS_dispatch_data>*, NSObject<OS_dispatch_data>)
[9] MTLInputStageReflectionReader::deserialize(id<MTLDeviceSPI>, NSObject<OS_dispatch_data>*, NSObject<OS_dispatch_data>)
[10] 10  Metal                               0x000000019b52e4e4 -[MTLFunctionReflectionInternal initWithDevice:reflectionData:functionType:options:] + 252
[11] AGX::Program<AGX::G13::VertexProgramVariant, AGX::VertexProgramKey, AGX::G13::IndirectArgumentLayout, AGXG13XFamilyIndirectArgumentBufferLayout>::signalPending(unsigned long, NSObject<OS_dispatch_data>*, ReflectionKey const&, id<MTLDeviceSPI>, MTLFunctionType, MTLCompilerError)
[12] invocation function for block in AGX::UserCommonShaderFactory<AGX::G13::Encoders, AGX::G13::Classes, AGX::G13::ObjClasses>::createVertexProgramVariant(MTLRenderPipelineDescriptor*, AGXG13XFamilyDevice*, unsigned long, AGXG13XFamilyBinaryArchive*, NSArray*, AGX::G13::VertexProgram*, AGX::G13::FragmentProgramVariant*, NSObject<OS_dispatch_data>*, NSObject<OS_dispatch_data>*, bool, void (AGX::G13::VertexProgramVariant*, ReflectionKey, NSMutableDictionary*, MTLCompilerError, NSString*) block_pointer)
[13] invocation function for block in void AGX::Compiler::compileProgram<AGX::VertexProgramKey, AGCDeserializedReply>(AGX::VertexProgramKey const&, MTLCompileFunctionRequestData*, void (AGCDeserializedReply const&, NSObject<OS_dispatch_data>*, NSObject<OS_dispatch_data>*, NSObject<OS_dispatch_data>*, NSObject<OS_dispatch_data>*, NSObject<OS_dispatch_data>*, MTLCompilerError, NSString*, unsigned long long) block_pointer)
[14] 14  libdispatch.dylib                   0x0000000190f28750 _dispatch_call_block_and_release + 32
[15] 15  libdispatch.dylib                   0x0000000190f2a3e8 _dispatch_client_callout + 20
[16] 16  libdispatch.dylib                   0x0000000190f2d580 _dispatch_queue_override_invoke + 928
[17] 17  libdispatch.dylib                   0x0000000190f3bea8 _dispatch_root_queue_drain + 392
[18] 18  libdispatch.dylib                   0x0000000190f3c6b8 _dispatch_worker_thread2 + 156
[19] 19  libsystem_pthread.dylib             0x00000001910d6fd0 _pthread_wqthread + 228
[20] 20  libsystem_pthread.dylib             0x00000001910d5d28 start_wqthread + 8
-- END OF BACKTRACE --
================================================================
djrain commented 2 weeks ago

For me the following script reliably reproduces this on M1 Mac in Godot 4.3 (though the time before crash varies). Just copy paste this into any Node2D. Anyone can confirm?

extends Node2D

var a = A.new()

func _ready() -> void:
    a.start()

class Base extends RefCounted:
    var runner
    var name = ""
    signal finished

    func start():
        prints(self.name, "started")
        run()
        prints(self.name, "returned --")
        return

    func run():
        pass

    func done():
        prints(self.name, "DONE -------------")
        finished.emit()

class A extends Base:
    func _init():
        name = "A"

    func run():
        runner = B.new()
        runner.finished.connect(on_runner_done)
        runner.start()

    func on_runner_done():
        done()
        start()

class B extends Base:
    func _init():
        name = "B"

    func run():
        runner = C.new()
        runner.finished.connect(done)
        runner.start()

class C extends Base:
    func _init():
        name = "C"

    func run():
        await Engine.get_main_loop().create_timer(0.2).timeout
        done()
Alex2782 commented 2 weeks ago

Anyone can confirm?

I had to wait almost 2 minutes, maybe next week I'll find time to debug it on MacOS.

screenshot ![image](https://github.com/user-attachments/assets/c86c575c-fdd8-4092-bdcf-e70db1e7521a)