Abdera7mane/discord-rpc-gdscript

Crash after a varying amount of time

Festerdam opened this issue · 4 comments

Problem previously raised here: 3ddelano/godot-editor-discord-presence#9
Godot seems to crash after some amount of time, using the godot-editor-discord-presence plugin that uses this project with the following output:

OpenGL ES 3.0 Renderer: Mesa Intel(R) HD Graphics 5500 (BDW GT2)
OpenGL ES Batching: ON
	OPTIONS
	max_join_item_commands 16
	colored_vertex_format_threshold 0.25
	batch_buffer_size 16384
	light_scissor_area_threshold 1
	item_reordering_lookahead 4
	light_max_join_items 32
	single_rect_fallback False
	debug_flash False
	diagnose_frame False
PulseAudio: context other
PulseAudio: context other
PulseAudio: context other
PulseAudio: context ready
PulseAudio: Detecting channels for device: alsa_output.pci-0000_00_1b.0.analog-stereo
PulseAudio: detected 2 output channels
PulseAudio: audio buffer frames: 512 calculated output latency: 11ms
JoypadLinux: udev enabled and loaded successfully.
 
Loading resource: res://locale/en_US.po
Loading resource: res://locale/pt_PT.po
Loading resource: res://locale/de_DE.po
CORE API HASH: 4983981888327659428
EDITOR API HASH: 17985513469441247513
Construct gdnative interface

Destruct gdnative interface

Class 'BulletPhysicsDirectBodyState' is not exposed, skipping.
Class 'BulletPhysicsDirectSpaceState' is not exposed, skipping.
Class 'BulletPhysicsServer' is not exposed, skipping.
Class 'GDScriptNativeClass' is not exposed, skipping.
Class 'IP_Unix' is not exposed, skipping.
Class 'InputDefault' is not exposed, skipping.
Class 'Physics2DDirectBodyStateSW' is not exposed, skipping.
Class 'Physics2DDirectSpaceStateSW' is not exposed, skipping.
Class 'Physics2DServerSW' is not exposed, skipping.
Class 'ResourceImporterMP3' is not exposed, skipping.
Class 'ResourceImporterOGGVorbis' is not exposed, skipping.
Loading resource: /home/monix/.config/godot/editor_settings-3.tres
EditorSettings: Load OK!
Loading resource: res://src/common/Globals.gd
Loading resource: res://src/common/WorldRWS.gd
Loading resource: res://addons/godot-sqlite/bin/gdsqlite.gdns
Loading resource: res://addons/godot-sqlite/bin/gdsqlite.gdnlib
Loading resource: res://src/common/Network.gd
Loading resource: res://src/common/Events.gd
Loading resource: res://src/common/ClientSettings.gd
Loading resource: res://addons/dialogue_manager/dialogue_manager.gd
Loading resource: res://addons/dialogue_manager/dialogue_resource.gd
Loading resource: res://addons/dialogue_manager/dialogue_line.gd
Loading resource: res://addons/dialogue_manager/constants.gd
Loading resource: res://addons/dialogue_manager/dialogue_response.gd
Loading resource: res://addons/dialogue_manager/components/settings.gd
Loading resource: res://addons/dialogue_manager/components/parser.gd
Loading resource: res://addons/dialogue_manager/example_balloon/example_balloon.gd
Loading resource: res://addons/dialogue_manager/example_balloon/menu_item.tscn
Loading resource: res://addons/dialogue_manager/example_balloon/Open_Sans/OpenSans-Regular.ttf
Loading resource: res://addons/dialogue_manager/example_balloon/menu_item.gd
Loading resource: res://addons/dialogue_manager/example_balloon/example_balloon.tscn
Loading resource: res://addons/dialogue_manager/example_balloon/menu.tscn
Loading resource: res://addons/dialogue_manager/example_balloon/menu.gd
Loading resource: res://addons/dialogue_manager/example_balloon/pointer.svg
Loading resource: res://addons/dialogue_manager/example_balloon/Open_Sans/OpenSans-Bold.ttf
Loading resource: res://addons/dialogue_manager/example_balloon/Open_Sans/OpenSans-Italic.ttf
Loading resource: res://addons/dialogue_manager/dialogue_label.tscn
Loading resource: res://addons/dialogue_manager/dialogue_label.gd
Loading resource: res://addons/dialogue_manager/example_balloon/background.svg
Loading resource: res://src/common/Story.gd
Loaded builtin certs
EditorSettings: Save OK!
Loading resource: res://addons/dialogue_manager/plugin.gd
Loading resource: res://addons/dialogue_manager/editor_export_plugin.gd
Loading resource: res://addons/dialogue_manager/views/main_view.tscn
Loading resource: res://addons/dialogue_manager/components/code_editor.tscn
Loading resource: res://addons/dialogue_manager/components/code_editor.gd
Loading resource: res://addons/dialogue_manager/views/choose_title_dialog.gd
Loading resource: res://addons/dialogue_manager/components/title_list.gd
Loading resource: res://addons/dialogue_manager/views/main_view.gd
Loading resource: res://addons/dialogue_manager/components/title_list.tscn
Loading resource: res://addons/dialogue_manager/views/settings_dialog.tscn
Loading resource: res://addons/dialogue_manager/views/settings_dialog.gd
Loading resource: res://addons/dialogue_manager/components/update_checker.tscn
Loading resource: res://addons/dialogue_manager/components/update_checker.gd
Loading resource: res://addons/dialogue_manager/components/search.tscn
Loading resource: res://addons/dialogue_manager/components/search.gd
Loading resource: res://addons/dialogue_manager/views/new_dialogue_dialog.tscn
Loading resource: res://addons/dialogue_manager/views/choose_title_dialog.tscn
Loading resource: res://addons/dialogue_manager/components/error_list.tscn
Loading resource: res://addons/dialogue_manager/components/error_list.gd
Loading resource: res://addons/dialogue_manager/components/error_button.tscn
Loading resource: res://addons/dialogue_manager/components/error_button_style.tres
Loading resource: res://addons/dialogue_manager/views/open_dialogue_dialog.tscn
Loading resource: res://addons/dialogue_manager/views/invalid_dialogue_dialog.tscn
Loading resource: res://addons/dialogue_manager/views/save_translations_dialog.tscn
Loading resource: res://addons/dialogue_manager/assets/icons/icon_dark_1.svg
Loading resource: res://addons/godot_editor_discord_presence/plugin.gd
Loading resource: res://addons/godot_editor_discord_presence/Discord RPC/DiscordRPC.gd
Loading resource: res://addons/godot_editor_discord_presence/Discord RPC/ipc/module/IPCModule.gd
Loading resource: res://addons/godot_editor_discord_presence/Discord RPC/ipc/IPC.gd
Loading resource: res://addons/godot_editor_discord_presence/Discord RPC/ipc/pipe/IPCPipe.gd
Loading resource: res://addons/godot_editor_discord_presence/Discord RPC/ipc/IPCPayload.gd
Loading resource: res://addons/godot_editor_discord_presence/Discord RPC/util/UUID.gd
Loading resource: res://addons/godot_editor_discord_presence/Discord RPC/DiscordRPCEnum.gd
Loading resource: res://addons/godot_editor_discord_presence/Discord RPC/ipc/pipe/WindowsPipe.gd
Loading resource: res://addons/godot_editor_discord_presence/Discord RPC/ipc/pipe/UnixPipe.gd
Loading resource: res://addons/godot_editor_discord_presence/godot-unix-socket/unix-socket.gdns
Loading resource: res://addons/godot_editor_discord_presence/godot-unix-socket/native_script.gd
Loading resource: res://addons/godot_editor_discord_presence/godot-unix-socket/unix-socket.gdnlib
Loading resource: res://addons/godot_editor_discord_presence/Discord RPC/ipc/module/rich presence/RichPresenceModule.gd
Loading resource: res://addons/godot_editor_discord_presence/Discord RPC/ipc/module/rich presence/RichPresence.gd
Loading resource: res://addons/godot_editor_discord_presence/Discord RPC/ipc/module/rich presence/RichPresenceButton.gd
Loading resource: res://addons/godot_editor_discord_presence/Discord RPC/ipc/module/rich presence/UpdateRichPresencePayload.gd
Loading resource: res://addons/godot_editor_discord_presence/Discord RPC/util/IPCUtil.gd
Loading resource: res://addons/godot_editor_discord_presence/Discord RPC/util/URLUtil.gd
Loading resource: res://src/server/Chat.gd
Loading resource: res://src/client/menu/Chat.gd
Loading resource: res://src/client/VisibleCanvasLayer.gd
Loading resource: res://src/client/menu/ChatPreview.gd
Loading resource: res://src/client/menu/ConnectMenu.gd
Loading resource: res://src/Entry.gd
Loading resource: res://src/client/menu/GameHUD.gd
Loading resource: res://src/client/Main.gd
Loading resource: res://src/client/maps/test-tilemap.tscn
Loading resource: res://icon.png
Loading resource: res://src/client/Player.tscn
Loading resource: res://src/common/TileColissionShape.tres
Loading resource: res://src/client/Player.gd
Loading resource: res://src/common/Player.gd
Loading resource: res://src/server/Main.gd
Loading resource: res://src/server/maps/test-tilemap.tscn
Loading resource: res://src/server/placeholder.jpg
Loading resource: res://src/server/Player.tscn
Loading resource: res://src/server/Player.gd
Loading resource: res://src/Entry.tscn

================================================================
handle_crash: Program crashed with signal 11
Engine version: Godot Engine v3.4.4.stable.official (419e713a29f20bd3351a54d1e6c4c5af7ef4b253)
Dumping the backtrace. Please include this when reporting the bug on https://github.com/godotengine/godot/issues
[1] /lib/x86_64-linux-gnu/libc.so.6(+0x38920) [0x7f68f8a41920] (??:0)
[2] /home/monix/Software/godot() [0x2b8dc21] (??:0)
[3] /home/monix/Software/godot() [0x2b92b36] (??:0)
[4] /home/monix/Software/godot() [0xdea1ee] (??:0)
[5] /home/monix/Software/godot() [0x2b77b5e] (??:0)
[6] /home/monix/Software/godot() [0x2c01745] (??:0)
[7] /home/monix/Software/godot() [0xaab8c4] (??:0)
[8] /home/monix/Software/godot() [0xa3aa60] (??:0)
[9] /home/monix/Software/godot() [0x2b77b5e] (??:0)
[10] /home/monix/Software/godot() [0x2c01745] (??:0)
[11] /home/monix/Software/godot() [0xaab8c4] (??:0)
[12] /home/monix/Software/godot() [0xa3aa60] (??:0)
[13] /home/monix/Software/godot() [0x2b77b5e] (??:0)
[14] /home/monix/Software/godot() [0x2c01745] (??:0)
[15] /home/monix/Software/godot() [0xaab8c4] (??:0)
[16] /home/monix/Software/godot() [0xa3ab20] (??:0)
[17] /home/monix/Software/godot() [0x1d6d53f] (??:0)
[18] /home/monix/Software/godot() [0x1d8c846] (??:0)
[19] /home/monix/Software/godot() [0x1db11ad] (??:0)
[20] /home/monix/Software/godot() [0x9d8c27] (??:0)
[21] /home/monix/Software/godot() [0x9471ad] (??:0)
[22] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xcd) [0x7f68f8a2c7fd] (??:0)
[23] /home/monix/Software/godot() [0x95ae1e] (??:0)
-- END OF BACKTRACE --
================================================================
OS: Debian testing
Godot Version: 3.4.4

Discord is open during the crash.

Unfortunately the output doesn't indicate the actual cause of the crash but I'm guessing it's either because of the way I'm handling the connection on Unix based OS, or an an issue from Godot UnixSocket (no need to forward the issue there)

I will try to debug this

I was able to replicate the issue using the editor presence plugin, the fastest way to crash the engine is by quickly switching the editor workspace then try to edit a resource file.

Using a debug build of Godot I got two different kinds of backtrace logs:

First

handle_crash: Program crashed with signal 11
Engine version: Godot Engine v3.4.4.stable.custom_build (419e713a29f20bd3351a54d1e6c4c5af7ef4b253)
Dumping the backtrace. Please include this when reporting the bug on https://github.com/godotengine/godot/issues
[1] /lib/x86_64-linux-gnu/libc.so.6(+0x46210) [0x7ffff787b210] (??:0)
[2] StringName::unref() (/usr/include/c++/7/bits/atomic_base.h:524 (discriminator 1))
[3] StringName::operator=(StringName const&) (/opt/godot/core/string_name.cpp:143)
[4] NativeScriptInstance::call(StringName const&, Variant const**, int, Variant::CallError&) (/opt/godot/modules/gdnative/nativescript/nativescript.cpp:738 (discriminator 3))
[5] Object::call(StringName const&, Variant const**, int, Variant::CallError&) (/opt/godot/core/object.cpp:899 (discriminator 1))
[6] Variant::call_ptr(StringName const&, Variant const**, int, Variant*, Variant::CallError&) (/opt/godot/core/variant_call.cpp:1176 (discriminator 1))
[7] GDScriptFunction::call(GDScriptInstance*, Variant const**, int, Variant::CallError&, GDScriptFunction::CallState*) (/opt/godot/modules/gdscript/gdscript_function.cpp:1048)
[8] GDScriptInstance::call(StringName const&, Variant const**, int, Variant::CallError&) (/opt/godot/modules/gdscript/gdscript.cpp:1176)
[9] Object::call(StringName const&, Variant const**, int, Variant::CallError&) (/opt/godot/core/object.cpp:899 (discriminator 1))
[10] Variant::call_ptr(StringName const&, Variant const**, int, Variant*, Variant::CallError&) (/opt/godot/core/variant_call.cpp:1176 (discriminator 1))
[11] GDScriptFunction::call(GDScriptInstance*, Variant const**, int, Variant::CallError&, GDScriptFunction::CallState*) (/opt/godot/modules/gdscript/gdscript_function.cpp:1048)
[12] GDScriptInstance::call(StringName const&, Variant const**, int, Variant::CallError&) (/opt/godot/modules/gdscript/gdscript.cpp:1176)
[13] Object::call(StringName const&, Variant const**, int, Variant::CallError&) (/opt/godot/core/object.cpp:899 (discriminator 1))
[14] _Thread::_start_func(void*) (/opt/godot/core/bind/core_bind.cpp:2664 (discriminator 1))
[15] Thread::callback(Thread*, Thread::Settings const&, void (*)(void*), void*) (/opt/godot/core/os/thread.cpp:79)
[16] void std::__invoke_impl<void, void (*)(Thread*, Thread::Settings const&, void (*)(void*), void*), Thread*, Thread::Settings, void (*)(void*), void*>(std::__invoke_other, void (*&&)(Thread*, Thread::Settings const&, void (*)(void*), void*), Thread*&&, Thread::Settings&&, void (*&&)(void*), void*&&) (/usr/include/c++/7/bits/invoke.h:60)
[17] std::__invoke_result<void (*)(Thread*, Thread::Settings const&, void (*)(void*), void*), Thread*, Thread::Settings, void (*)(void*), void*>::type std::__invoke<void (*)(Thread*, Thread::Settings const&, void (*)(void*), void*), Thread*, Thread::Settings, void (*)(void*), void*>(void (*&&)(Thread*, Thread::Settings const&, void (*)(void*), void*), Thread*&&, Thread::Settings&&, void (*&&)(void*), void*&&) (/usr/include/c++/7/bits/invoke.h:95)
[18] decltype (__invoke((_S_declval<0ul>)(), (_S_declval<1ul>)(), (_S_declval<2ul>)(), (_S_declval<3ul>)(), (_S_declval<4ul>)())) std::thread::_Invoker<std::tuple<void (*)(Thread*, Thread::Settings const&, void (*)(void*), void*), Thread*, Thread::Settings, void (*)(void*), void*> >::_M_invoke<0ul, 1ul, 2ul, 3ul, 4ul>(std::_Index_tuple<0ul, 1ul, 2ul, 3ul, 4ul>) (/usr/include/c++/7/thread:234)
[19] std::thread::_Invoker<std::tuple<void (*)(Thread*, Thread::Settings const&, void (*)(void*), void*), Thread*, Thread::Settings, void (*)(void*), void*> >::operator()() (/usr/include/c++/7/thread:243)
[20] std::thread::_State_impl<std::thread::_Invoker<std::tuple<void (*)(Thread*, Thread::Settings const&, void (*)(void*), void*), Thread*, Thread::Settings, void (*)(void*), void*> > >::_M_run() (/usr/include/c++/7/thread:186)
[21] /home/mint/Desktop/godot.x11.tools.64() [0x4b1091f] (thread.o:?)
[22] /lib/x86_64-linux-gnu/libpthread.so.0(+0x9609) [0x7ffff7b85609] (??:0)
[23] /lib/x86_64-linux-gnu/libc.so.6(clone+0x43) [0x7ffff7957293] (??:0)
-- END OF BACKTRACE --

Second

handle_crash: Program crashed with signal 11
Engine version: Godot Engine v3.4.4.stable.custom_build (419e713a29f20bd3351a54d1e6c4c5af7ef4b253)
Dumping the backtrace. Please include this when reporting the bug on https://github.com/godotengine/godot/issues
[1] /lib/x86_64-linux-gnu/libc.so.6(+0x46210) [0x7ffff787b210] (??:0)
[2] StringName::unref() (/usr/include/c++/7/bits/atomic_base.h:524 (discriminator 1))
[3] StringName::operator=(StringName const&) (/opt/godot/core/string_name.cpp:143)
[4] NativeScriptInstance::call(StringName const&, Variant const**, int, Variant::CallError&) (/opt/godot/modules/gdnative/nativescript/nativescript.cpp:731)
[5] Object::call(StringName const&, Variant const**, int, Variant::CallError&) (/opt/godot/core/object.cpp:899 (discriminator 1))
[6] Variant::call_ptr(StringName const&, Variant const**, int, Variant*, Variant::CallError&) (/opt/godot/core/variant_call.cpp:1176 (discriminator 1))
[7] GDScriptFunction::call(GDScriptInstance*, Variant const**, int, Variant::CallError&, GDScriptFunction::CallState*) (/opt/godot/modules/gdscript/gdscript_function.cpp:1048)
[8] GDScriptInstance::call(StringName const&, Variant const**, int, Variant::CallError&) (/opt/godot/modules/gdscript/gdscript.cpp:1176)
[9] Object::call(StringName const&, Variant const**, int, Variant::CallError&) (/opt/godot/core/object.cpp:899 (discriminator 1))
[10] Variant::call_ptr(StringName const&, Variant const**, int, Variant*, Variant::CallError&) (/opt/godot/core/variant_call.cpp:1176 (discriminator 1))
[11] GDScriptFunction::call(GDScriptInstance*, Variant const**, int, Variant::CallError&, GDScriptFunction::CallState*) (/opt/godot/modules/gdscript/gdscript_function.cpp:1048)
[12] GDScriptInstance::call(StringName const&, Variant const**, int, Variant::CallError&) (/opt/godot/modules/gdscript/gdscript.cpp:1176)
[13] Object::call(StringName const&, Variant const**, int, Variant::CallError&) (/opt/godot/core/object.cpp:899 (discriminator 1))
[14] Variant::call_ptr(StringName const&, Variant const**, int, Variant*, Variant::CallError&) (/opt/godot/core/variant_call.cpp:1176 (discriminator 1))
[15] GDScriptFunction::call(GDScriptInstance*, Variant const**, int, Variant::CallError&, GDScriptFunction::CallState*) (/opt/godot/modules/gdscript/gdscript_function.cpp:1048)
[16] GDScriptInstance::call_multilevel(StringName const&, Variant const**, int) (/opt/godot/modules/gdscript/gdscript.cpp:1191)
[17] Node::_notification(int) (/opt/godot/scene/main/node.cpp:54)
[18] Node::_notificationv(int, bool) (/opt/godot/./scene/main/node.h:45 (discriminator 14))
[19] Object::notification(int, bool) (/opt/godot/core/object.cpp:929)
[20] SceneTree::_notify_group_pause(StringName const&, int) (/opt/godot/scene/main/scene_tree.cpp:990)
[21] SceneTree::idle(float) (/opt/godot/scene/main/scene_tree.cpp:536 (discriminator 3))
[22] Main::iteration() (/opt/godot/main/main.cpp:2201)
[23] OS_X11::run() (/opt/godot/platform/x11/os_x11.cpp:3643)
[24] /home/mint/Desktop/godot.x11.tools.64(main+0x121) [0x178c6f8] (/opt/godot/platform/x11/godot_x11.cpp:57)
[25] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf3) [0x7ffff785c0b3] (??:0)
[26] /home/mint/Desktop/godot.x11.tools.64(_start+0x2a) [0x178c51a] (??:?)
-- END OF BACKTRACE --

DiscordRPC uses threads internally and I think this causes issues with using NativeScripts inside a thread and Godot crashes when it reloads the NativeScript resource maybe. I still need to investigate more into this.

I stumbled upon some engine issues that could be related:

I think it is pretty safe to assume that my previous theory was correct, I will be working on a version of this addon that doesn't use threads and see if it fixes the issue

@Festerdam I got it working, the editor didn't crash on my side, I pushed the changes to no-threads branch could you replace res://addons/godot_editor_discord_presence/Discord RPC/ with the update and see if it solves the issue ? 🤔