godotengine / godot

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

Multi-threading related crash during play in Label::regenerate_word_cache #32470

Open WizzardMaker opened 5 years ago

WizzardMaker commented 5 years ago

Godot version: 3.1.1 Mono

OS/device including version: Windows 10 64bit

Issue description: I am using Mono in a project right now. It worked fine until lately. The player is now randomly crashing without any of my C# code running. The player just crashes after a few seconds - minutes. Its unpredictable when it happens and it gives no real error message, just the standard socket exception:

drivers/unix/net_socket_posix.cpp:190 - Socket error: 10054
** Debug Process Stopped **

The latest things I added to the project before it happened:

Things I changed on my system:

Verbose logging of the player is activated, but that does not indicate any error

mono logs often have a GC_MAJOR_CONCURRENT_START: (LOS overflow) (in domain Mono, info) at the end whenever a crash happend though

It seems to happen more often when you resize the window. It also seems like to happen more often when you change the size of GUI elements, like a box container or a label.

Steps to reproduce:

Minimal reproduction project:

Chaosus commented 5 years ago

Looks like a duplicate of #32203, but who know ¯_(ツ)_/¯

WizzardMaker commented 5 years ago

Kinda hard to tell, but in contrast to the other issue, my editor does not crash, only the player does.

WizzardMaker commented 5 years ago

I am currently too tired to manage any symbols but the game seems to crash at 0x00000000015F4522 according to a debugging session with Visual Studio attached to the games c++ side

Calinou commented 5 years ago

It seems to happen more often when you resize the window.

This was also reported on #24702 (but only on Windows).

WizzardMaker commented 5 years ago

Yeah, I've tested the resizing with other projects and even a blank one. They are also crashing

But I think I am observing two different crashes here. It seems like it's also crashing when trying to either set text in a label or when trying to resize a set of controls when changing text

I have a test project right now where its crashing occasionally, but not consistent.

  1. Open Test.tscn
  2. Start the scene
  3. Wait until: image appears.
  4. It should crash right before displaying the full text
  5. If its not crashing restart the scene (GOTO 2)

Again, no error message. Here is the project: Test.zip

qarmin commented 5 years ago

It happens very rarely to me(10% chance on Ubuntu 19.04 Mono 6.4) Something wrong happens in regenerate_word_cache() - log.txt


=================================================================
    Native stacktrace:
=================================================================
    0xc2b075 - ./Godot_v3.1.1-stable_mono_x11.64 : (null)
    0xc1ea09 - ./Godot_v3.1.1-stable_mono_x11.64 : (null)
    0xb9cf10 - ./Godot_v3.1.1-stable_mono_x11.64 : (null)
    0x1ed2cd2 - ./Godot_v3.1.1-stable_mono_x11.64 : _ZN5Label21regenerate_word_cacheEv
    0x1ed3635 - ./Godot_v3.1.1-stable_mono_x11.64 : _ZNK5Label14get_line_countEv
    0xe34dbd - ./Godot_v3.1.1-stable_mono_x11.64 : (null)
    0x10f495d - ./Godot_v3.1.1-stable_mono_x11.64 : _Z15godot_icall_0_1P10MethodBindP6Object
    0x40e3d4b4 - Unknown
WizzardMaker commented 5 years ago

Hmm, regenerate_word_cache gets called by get_line_count() which I am using. I am calling GetLineCount() every time I add text, to get the height of every dialogue option, to add a dynamic control "hit box"

I call GetLineCount() here twice (though that second call can be optimized, but shouldn't really matter) for every dialogue option in a dialogue node. This gets executed once a node reaches the option picking phase

foreach (DialogueOption option in dialogue.CurrentNode.options) {
    text += "* ";
    text += GetFullCleanTrText(option.textId, dialogue);
    text += '\n';
    textLabel.Text = text;

    AddLines(textLabel.GetLineCount() - lineCount, optionIndex);
    lineCount = textLabel.GetLineCount();

    optionIndex++;
}
Calinou commented 5 years ago

@WizzardMaker Does disabling font oversampling solve the issue? To do so, uncheck Rendering > Quality > Dynamic Fonts > Use Oversampling in the Project Settings.

WizzardMaker commented 5 years ago

No, it crashed again at the same point, after like 8 normal starts. I don't have a stack trace though

WizzardMaker commented 5 years ago

Ok, seems like it no longer is just a "once in a million" chance of happening. This is now crashing my game at nearly regular intervals. Every 3rd dialogue branch gets a crash. I hope I can help someone with fixing this bug

qarmin commented 5 years ago

I tried to reproduce this with GDScript, but without success on Godot 3.1 and master. Did you tried to use the latest Mono version of Godot?(https://downloads.tuxfamily.org/godotengine/3.2/alpha0-unofficial/mono/), I checked ~20 times and with it doesn't crash.

WizzardMaker commented 5 years ago

Just tried it. It still crashes without a stacktrace or error message

qarmin commented 5 years ago

Another backtrace:

        0xc2b075 - /home/rafal/DOSPRAWDZENIA/Godot_v3.1.1-stable_mono_x11_64/Godot_v3.1.1-stable_mono_x11.64 : (null)
        0xc1ea09 - /home/rafal/DOSPRAWDZENIA/Godot_v3.1.1-stable_mono_x11_64/Godot_v3.1.1-stable_mono_x11.64 : (null)
        0xb9cf10 - /home/rafal/DOSPRAWDZENIA/Godot_v3.1.1-stable_mono_x11_64/Godot_v3.1.1-stable_mono_x11.64 : (null)
        0x1ed2cd2 - /home/rafal/DOSPRAWDZENIA/Godot_v3.1.1-stable_mono_x11_64/Godot_v3.1.1-stable_mono_x11.64 : _ZN5Label21regenerate_word_cacheEv
        0x1ed4361 - /home/rafal/DOSPRAWDZENIA/Godot_v3.1.1-stable_mono_x11_64/Godot_v3.1.1-stable_mono_x11.64 : _ZN5Label13_notificationEi
        0x2d4c854 - /home/rafal/DOSPRAWDZENIA/Godot_v3.1.1-stable_mono_x11_64/Godot_v3.1.1-stable_mono_x11.64 : _ZN6Object12notificationEib
        0x2106076 - /home/rafal/DOSPRAWDZENIA/Godot_v3.1.1-stable_mono_x11_64/Godot_v3.1.1-stable_mono_x11.64 : _ZN10CanvasItem16_update_callbackEv
        0x1978c99 - /home/rafal/DOSPRAWDZENIA/Godot_v3.1.1-stable_mono_x11_64/Godot_v3.1.1-stable_mono_x11.64 : (null)
        0x2dab0d3 - /home/rafal/DOSPRAWDZENIA/Godot_v3.1.1-stable_mono_x11_64/Godot_v3.1.1-stable_mono_x11.64 : _ZN6Object4callERK10StringNamePPK7VariantiRNS3_9CallErrorE
        0x29f9e2d - /home/rafal/DOSPRAWDZENIA/Godot_v3.1.1-stable_mono_x11_64/Godot_v3.1.1-stable_mono_x11.64 : _ZN12MessageQueue14_call_functionEP6ObjectRK10StringNamePK7Variantib
        0x29fa0e3 - /home/rafal/DOSPRAWDZENIA/Godot_v3.1.1-stable_mono_x11_64/Godot_v3.1.1-stable_mono_x11.64 : _ZN12MessageQueue5flushEv
        0x1dbdbd9 - /home/rafal/DOSPRAWDZENIA/Godot_v3.1.1-stable_mono_x11_64/Godot_v3.1.1-stable_mono_x11.64 : _ZN9SceneTree9iterationEf
        0x1a1ae94 - /home/rafal/DOSPRAWDZENIA/Godot_v3.1.1-stable_mono_x11_64/Godot_v3.1.1-stable_mono_x11.64 : _ZN4Main9iterationEv
        0x1a59c39 - /home/rafal/DOSPRAWDZENIA/Godot_v3.1.1-stable_mono_x11_64/Godot_v3.1.1-stable_mono_x11.64 : _ZN6OS_X113runEv
        0xb5a5ec - /home/rafal/DOSPRAWDZENIA/Godot_v3.1.1-stable_mono_x11_64/Godot_v3.1.1-stable_mono_x11.64 : main
        0x7fa8fefa9b6b - /lib/x86_64-linux-gnu/libc.so.6 : __libc_start_main
        0xb5bd9e - /home/rafal/DOSPRAWDZENIA/Godot_v3.1.1-stable_mono_x11_64/Godot_v3.1.1-stable_mono_x11.64 : (null)

Can you strip reproducible project to ~20 - 30 lines?

I found that crash happens almost always, when code in Office.cs is added to loop

for(int i = 0; i < 100; i++){
    start.AddOption(new DialogueOption(101, noNewLoan));
    start.AddOption(new DialogueOption(102, noReturningOfLoan));
    start.AddOption(new DialogueOptionReturning(103));
}
qarmin commented 5 years ago

Smaller project: Test.zip

Seems that you have problem with threading which changing same data

Thread 1 (Thread 0x7f7460b15500 (LWP 1225)):
#0  0x00007f7462c4491a in __waitpid (pid=pid@entry=1249, stat_loc=stat_loc@entry=0x7ffc459dc690, options=options@entry=0) at ../sysdeps/unix/sysv/linux/waitpid.c:30
#1  0x0000000000cf044a in dump_native_stacktrace (ctx=ctx@entry=0x7ffc459dd240, signal=0x32cf642 "SIGABRT") at mini-posix.c:1112
#2  0x0000000000cf05fa in mono_dump_native_crash_info (signal=signal@entry=0x32cf642 "SIGABRT", ctx=ctx@entry=0x7ffc459dd240, info=info@entry=0x7ffc459dd370) at mini-posix.c:1149
#3  0x0000000000ce3c79 in mono_handle_native_crash (signal=0x32cf642 "SIGABRT", ctx=0x7ffc459dd240, info=0x7ffc459dd370) at mini-exceptions.c:3290
#4  <signal handler called>
#5  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#6  0x00007f746290c535 in __GI_abort () at abort.c:79
#7  0x00007f7462973726 in __libc_message (action=action@entry=do_abort, fmt=fmt@entry=0x7f7462a99952 "%s\n") at ../sysdeps/posix/libc_fatal.c:181
#8  0x00007f746297a59a in malloc_printerr (str=str@entry=0x7f7462a9b638 "double free or corruption (fasttop)") at malloc.c:5352
#9  0x00007f746297c534 in _int_free (av=0x7f7414000020, p=0x7f7414049400, have_lock=<optimized out>) at malloc.c:4274
#10 0x0000000001dbb040 in Label::regenerate_word_cache() ()
#11 0x0000000001dbbb78 in Label::get_minimum_size() const ()
#12 0x00007ffc00000000 in ?? ()
#13 0x00000000108fd2f0 in ?? ()
#14 0x0000000000000000 in ?? ()

and other thread

Thread 9 (Thread 0x7f9b6e9fe700 (LWP 1512)):
#0  0x00000000019babbe in DynamicFontAtSize::get_char_size(wchar_t, wchar_t, Vector<Ref<DynamicFontAtSize> > const&) const ()
#1  0x0000000000000020 in ?? ()
#2  0x00000000019bb24b in DynamicFont::get_char_size(wchar_t, wchar_t) const ()
#3  0x00007f9b6e9fd1f0 in ?? ()
#4  0x424a1af241a4fbe0 in ?? ()
#5  0x0000000000000336 in ?? ()
#6  0x00007f9b6e9fd1f0 in ?? ()
#7  0x000000000fd15a80 in ?? ()
#8  0x0000000001dbae18 in Label::get_longest_line_width() const ()
#9  0x0000000001ed9c68 in Control::get_stylebox(StringName const&, StringName const&) const ()
#10 0x0000000041a4fbe0 in ?? ()
#11 0x0000000000000335 in ?? ()
#12 0x0000000000000000 in ?? ()
akien-mga commented 4 years ago

Backtrace of the project in https://github.com/godotengine/godot/issues/32470#issuecomment-538900526:

0x00007f5fffe4cf1a in waitpid () from /lib64/libpthread.so.0
  Id   Target Id                                           Frame 
* 1    Thread 0x7f5fff302fc0 (LWP 28019) "godot.x11.tools" 0x00007f5fffe4cf1a in waitpid () from /lib64/libpthread.so.0
  2    Thread 0x7f5ff395d700 (LWP 28020) "godot.x11.tools" 0x00007f5fffe4b686 in do_futex_wait.constprop () from /lib64/libpthread.so.0
  3    Thread 0x7f5ff2049700 (LWP 28022) "godot.x:disk$0"  0x00007f5fffe48af5 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
  4    Thread 0x7f5ff1848700 (LWP 28023) "godot.x:disk$1"  0x00007f5fffe48af5 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
  5    Thread 0x7f5ff1047700 (LWP 28024) "godot.x:disk$2"  0x00007f5fffe48af5 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
  6    Thread 0x7f5ff0846700 (LWP 28025) "godot.x:disk$3"  0x00007f5fffe48af5 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
  7    Thread 0x7f5ff0045700 (LWP 28026) "godot.x11.tools" 0x00007f5fffe4b686 in do_futex_wait.constprop () from /lib64/libpthread.so.0
  8    Thread 0x7f5fdbc65700 (LWP 28027) "godot.x11.tools" 0x00007f5fffe4ca00 in nanosleep () from /lib64/libpthread.so.0
  9    Thread 0x7f5fdbc24700 (LWP 28028) "godot.x11.tools" 0x00007f5fffa59600 in nanosleep () from /lib64/libc.so.6
  10   Thread 0x7f5fdb3ff700 (LWP 28031) "SGen worker"     0x00007f5fffe48af5 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
  11   Thread 0x7f5fdbac7700 (LWP 28032) "Finalizer"       0x00007f5fffe4b686 in do_futex_wait.constprop () from /lib64/libpthread.so.0
  12   Thread 0x7f5fd95ff700 (LWP 28035) "godot.x11.tools" 0x00007f5fffe4902e in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
  13   Thread 0x7f5fd8fa0700 (LWP 28036) "Thread Pool Wor" 0x00000000014a14ac in CharProxy<wchar_t>::CharProxy (this=0x7f5fd8f9f110, p_index=@0x7f5fd8f9f104: 2292, cowdata=...) at ./core/ustring.h:50
  14   Thread 0x7f5fd8d9f700 (LWP 28037) "Thread Pool Wor" 0x00007f5fffe4b862 in do_futex_wait () from /lib64/libpthread.so.0

Thread 14 (Thread 0x7f5fd8d9f700 (LWP 28037)):
#0  0x00007f5fffe4b862 in do_futex_wait () from /lib64/libpthread.so.0
#1  0x00007f5fffe4b953 in __new_sem_wait_slow () from /lib64/libpthread.so.0
#2  0x00007f60000250d7 in mono_os_sem_timedwait (flags=MONO_SEM_FLAGS_ALERTABLE, timeout_ms=51314, sem=0x7f600051c888 <worker+72>) at ../../mono/utils/mono-os-semaphore.h:252
#3  mono_coop_sem_timedwait (sem=0x7f600051c888 <worker+72>, flags=MONO_SEM_FLAGS_ALERTABLE, timeout_ms=<optimized out>) at ../../mono/utils/mono-coop-semaphore.h:55
#4  worker_park () at threadpool-worker-default.c:391
#5  worker_thread (unused=unused@entry=0x0) at threadpool-worker-default.c:490
#6  0x00007f60000f898c in start_wrapper_internal (stack_ptr=0x7f5fd8da0000, start_info=0x0) at threads.c:1178
#7  start_wrapper (data=0x7f5fb000af50) at threads.c:1238
#8  0x00007f5fffe4304c in start_thread () from /lib64/libpthread.so.0
#9  0x00007f5fffa9258f in clone () from /lib64/libc.so.6

Thread 13 (Thread 0x7f5fd8fa0700 (LWP 28036)):
#0  0x00000000014a14ac in CharProxy<wchar_t>::CharProxy (this=0x7f5fd8f9f110, p_index=@0x7f5fd8f9f104: 2292, cowdata=...) at ./core/ustring.h:50
#1  0x00000000014a0ba9 in String::operator[] (this=0x8864678, p_index=2292) at ./core/ustring.h:162
#2  0x0000000002d06c52 in Label::regenerate_word_cache (this=0x8864220) at scene/gui/label.cpp:412
#3  0x0000000002d06637 in Label::get_line_count (this=0x8864220) at scene/gui/label.cpp:360
#4  0x00000000016c35dc in MethodBind0RC<int>::ptrcall (this=0x6d1d4b0, p_object=0x8864220, p_args=0x0, r_ret=0x7f5fd8f9f2e8) at ./core/method_bind.gen.inc:600
#5  0x0000000001a438ad in godot_icall_0_1 (method=0x6d1d4b0, ptr=0x8864220) at modules/mono/glue/mono_glue.gen.cpp:15
#6  0x00000000420b299e in ?? ()
#7  0x00007f5fdbad6330 in ?? ()
#8  0x00007f5fd8f9f490 in ?? ()
#9  0x00007f5fdb5397f0 in ?? ()
#10 0x00000000000002f2 in ?? ()
#11 0x0000000000000000 in ?? ()

Thread 12 (Thread 0x7f5fd95ff700 (LWP 28035)):
#0  0x00007f5fffe4902e in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
#1  0x00007f60001ac62f in mono_os_cond_timedwait (cond=cond@entry=0x7f60005302e0 <sleep_cond>, mutex=mutex@entry=0x7f6000530320 <sleep_mutex>, timeout_ms=timeout_ms@entry=500) at mono-os-mutex.c:75
#2  0x00007f60001b7e19 in mono_coop_cond_timedwait (cond=0x7f60005302e0 <sleep_cond>, mutex=0x7f6000530320 <sleep_mutex>, timeout_ms=500) at ../../mono/utils/mono-coop-mutex.h:100
#3  sleep_interruptable (alerted=0x7f5fd95fecf4, ms=500) at mono-threads.c:1612
#4  mono_thread_info_sleep (ms=ms@entry=500, alerted=alerted@entry=0x7f5fd95fecf4) at mono-threads.c:1644
#5  0x00007f6000025e0b in monitor_thread (unused=unused@entry=0x0) at threadpool-worker-default.c:708
#6  0x00007f60000f898c in start_wrapper_internal (stack_ptr=0x7f5fd9600000, start_info=0x0) at threads.c:1178
#7  start_wrapper (data=0x88507c0) at threads.c:1238
#8  0x00007f5fffe4304c in start_thread () from /lib64/libpthread.so.0
#9  0x00007f5fffa9258f in clone () from /lib64/libc.so.6

Thread 11 (Thread 0x7f5fdbac7700 (LWP 28032)):
#0  0x00007f5fffe4b686 in do_futex_wait.constprop () from /lib64/libpthread.so.0
#1  0x00007f5fffe4b758 in __new_sem_wait_slow.constprop.0 () from /lib64/libpthread.so.0
#2  0x00007f600014b138 in mono_os_sem_wait (flags=MONO_SEM_FLAGS_ALERTABLE, sem=0x7f6000520f80 <finalizer_sem>) at ../../mono/utils/mono-os-semaphore.h:203
#3  mono_coop_sem_wait (flags=MONO_SEM_FLAGS_ALERTABLE, sem=0x7f6000520f80 <finalizer_sem>) at ../../mono/utils/mono-coop-semaphore.h:41
#4  finalizer_thread (unused=unused@entry=0x0) at gc.c:920
#5  0x00007f60000f898c in start_wrapper_internal (stack_ptr=0x7f5fdbac8000, start_info=0x0) at threads.c:1178
#6  start_wrapper (data=0x75589d0) at threads.c:1238
#7  0x00007f5fffe4304c in start_thread () from /lib64/libpthread.so.0
#8  0x00007f5fffa9258f in clone () from /lib64/libc.so.6

Thread 10 (Thread 0x7f5fdb3ff700 (LWP 28031)):
#0  0x00007f5fffe48af5 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
#1  0x00007f600019bfc3 in mono_os_cond_wait (mutex=0x7f600052f860 <lock>, cond=0x7f600052f820 <work_cond>) at ../../mono/utils/mono-os-mutex.h:168
#2  get_work (job=<synthetic pointer>, do_idle=<synthetic pointer>, work_context=<synthetic pointer>, worker_index=0) at sgen-thread-pool.c:165
#3  thread_func (data=<optimized out>) at sgen-thread-pool.c:196
#4  0x00007f5fffe4304c in start_thread () from /lib64/libpthread.so.0
#5  0x00007f5fffa9258f in clone () from /lib64/libc.so.6

Thread 9 (Thread 0x7f5fdbc24700 (LWP 28028)):
#0  0x00007f5fffa59600 in nanosleep () from /lib64/libc.so.6
#1  0x00007f5fffa89624 in usleep () from /lib64/libc.so.6
#2  0x00000000014a930e in JoypadLinux::monitor_joypads (this=0x66dc570) at platform/x11/joypad_linux.cpp:216
#3  0x00000000014a921e in JoypadLinux::run_joypad_thread (this=0x66dc570) at platform/x11/joypad_linux.cpp:114
#4  0x00000000014a9203 in JoypadLinux::joy_thread_func (p_user=0x66dc570) at platform/x11/joypad_linux.cpp:102
#5  0x00000000020722e9 in ThreadPosix::thread_callback (userdata=0x66d65a0) at drivers/unix/thread_posix.cpp:74
#6  0x00007f5fffe4304c in start_thread () from /lib64/libpthread.so.0
#7  0x00007f5fffa9258f in clone () from /lib64/libc.so.6

Thread 8 (Thread 0x7f5fdbc65700 (LWP 28027)):
#0  0x00007f5fffe4ca00 in nanosleep () from /lib64/libpthread.so.0
#1  0x000000000206e141 in OS_Unix::delay_usec (this=0x7ffd7b849220, p_usec=1000) at drivers/unix/os_unix.cpp:261
#2  0x0000000002077019 in AudioDriverPulseAudio::thread_func (p_udata=0x7ffd7b8496b0) at drivers/pulseaudio/audio_driver_pulseaudio.cpp:520
#3  0x00000000020722e9 in ThreadPosix::thread_callback (userdata=0x64e7800) at drivers/unix/thread_posix.cpp:74
#4  0x00007f5fffe4304c in start_thread () from /lib64/libpthread.so.0
#5  0x00007f5fffa9258f in clone () from /lib64/libc.so.6

Thread 7 (Thread 0x7f5ff0045700 (LWP 28026)):
#0  0x00007f5fffe4b686 in do_futex_wait.constprop () from /lib64/libpthread.so.0
#1  0x00007f5fffe4b758 in __new_sem_wait_slow.constprop.0 () from /lib64/libpthread.so.0
#2  0x0000000002071ff2 in SemaphorePosix::wait (this=0x63e66c0) at drivers/unix/semaphore_posix.cpp:41
#3  0x000000000373c239 in VisualServerScene::_gi_probe_bake_thread (this=0x7f5fdbee7020) at servers/visual/visual_server_scene.cpp:2547
#4  0x000000000373b1a4 in VisualServerScene::_gi_probe_bake_threads (self=0x7f5fdbee7020) at servers/visual/visual_server_scene.cpp:2333
#5  0x00000000020722e9 in ThreadPosix::thread_callback (userdata=0x63ea460) at drivers/unix/thread_posix.cpp:74
#6  0x00007f5fffe4304c in start_thread () from /lib64/libpthread.so.0
#7  0x00007f5fffa9258f in clone () from /lib64/libc.so.6

Thread 6 (Thread 0x7f5ff0846700 (LWP 28025)):
#0  0x00007f5fffe48af5 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
#1  0x00007f5ff266979b in util_queue_thread_func () from /usr/lib64/dri/i965_dri.so
#2  0x00007f5ff2669407 in impl_thrd_routine () from /usr/lib64/dri/i965_dri.so
#3  0x00007f5fffe4304c in start_thread () from /lib64/libpthread.so.0
#4  0x00007f5fffa9258f in clone () from /lib64/libc.so.6

Thread 5 (Thread 0x7f5ff1047700 (LWP 28024)):
#0  0x00007f5fffe48af5 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
#1  0x00007f5ff266979b in util_queue_thread_func () from /usr/lib64/dri/i965_dri.so
#2  0x00007f5ff2669407 in impl_thrd_routine () from /usr/lib64/dri/i965_dri.so
#3  0x00007f5fffe4304c in start_thread () from /lib64/libpthread.so.0
#4  0x00007f5fffa9258f in clone () from /lib64/libc.so.6

Thread 4 (Thread 0x7f5ff1848700 (LWP 28023)):
#0  0x00007f5fffe48af5 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
#1  0x00007f5ff266979b in util_queue_thread_func () from /usr/lib64/dri/i965_dri.so
#2  0x00007f5ff2669407 in impl_thrd_routine () from /usr/lib64/dri/i965_dri.so
#3  0x00007f5fffe4304c in start_thread () from /lib64/libpthread.so.0
#4  0x00007f5fffa9258f in clone () from /lib64/libc.so.6

Thread 3 (Thread 0x7f5ff2049700 (LWP 28022)):
#0  0x00007f5fffe48af5 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
#1  0x00007f5ff266979b in util_queue_thread_func () from /usr/lib64/dri/i965_dri.so
#2  0x00007f5ff2669407 in impl_thrd_routine () from /usr/lib64/dri/i965_dri.so
#3  0x00007f5fffe4304c in start_thread () from /lib64/libpthread.so.0
#4  0x00007f5fffa9258f in clone () from /lib64/libc.so.6

Thread 2 (Thread 0x7f5ff395d700 (LWP 28020)):
#0  0x00007f5fffe4b686 in do_futex_wait.constprop () from /lib64/libpthread.so.0
#1  0x00007f5fffe4b758 in __new_sem_wait_slow.constprop.0 () from /lib64/libpthread.so.0
#2  0x0000000002071ff2 in SemaphorePosix::wait (this=0x6195620) at drivers/unix/semaphore_posix.cpp:41
#3  0x0000000003b3db01 in _IP_ResolverPrivate::_thread_function (self=0x6195080) at core/io/ip.cpp:101
#4  0x00000000020722e9 in ThreadPosix::thread_callback (userdata=0x6195660) at drivers/unix/thread_posix.cpp:74
#5  0x00007f5fffe4304c in start_thread () from /lib64/libpthread.so.0
#6  0x00007f5fffa9258f in clone () from /lib64/libc.so.6

Thread 1 (Thread 0x7f5fff302fc0 (LWP 28019)):
#0  0x00007f5fffe4cf1a in waitpid () from /lib64/libpthread.so.0
#1  0x00007f5ffffbf417 in dump_native_stacktrace (ctx=ctx@entry=0x0, signal=0x7f60001ed389 "SIGSEGV") at mini-posix.c:1115
#2  0x00007f5ffffbf51e in mono_dump_native_crash_info (signal=signal@entry=0x7f60001ed389 "SIGSEGV", ctx=ctx@entry=0x0, info=info@entry=0x0) at mini-posix.c:1159
#3  0x00007f5ffff4af7c in mono_handle_native_crash (signal=signal@entry=0x7f60001ed389 "SIGSEGV", ctx=ctx@entry=0x0, info=info@entry=0x0) at mini-exceptions.c:3340
#4  0x00007f5ffffb8a78 in altstack_handle_and_restore (ctx=0x7ffd7b848150, obj=0x0, stack_ovf=0) at exceptions-amd64.c:870
#5  0x0000000002d06d43 in Label::regenerate_word_cache (this=0x8864220) at scene/gui/label.cpp:430
#6  0x0000000002d06319 in Label::get_minimum_size (this=0x8864220) at scene/gui/label.cpp:308
#7  0x0000000002c6a2b9 in Control::_update_minimum_size_cache (this=0x8864220) at scene/gui/control.cpp:179
#8  0x0000000002c6a39e in Control::get_combined_minimum_size (this=0x8864220) at scene/gui/control.cpp:197
#9  0x0000000002c47c61 in BoxContainer::get_minimum_size (this=0x8851550) at scene/gui/box_container.cpp:224
#10 0x0000000002c6a2b9 in Control::_update_minimum_size_cache (this=0x8851550) at scene/gui/control.cpp:179
#11 0x0000000002c6a39e in Control::get_combined_minimum_size (this=0x8851550) at scene/gui/control.cpp:197
#12 0x0000000002c72843 in Control::_size_changed (this=0x8851550) at scene/gui/control.cpp:1371
#13 0x0000000002c6e298 in Control::_notification (this=0x8851550, p_notification=31) at scene/gui/control.cpp:671
#14 0x000000000151f7f0 in Control::_notificationv (this=0x8851550, p_notification=31, p_reversed=false) at ./scene/gui/control.h:48
#15 0x0000000001537961 in Container::_notificationv (this=0x8851550, p_notification=31, p_reversed=false) at ./scene/gui/container.h:38
#16 0x0000000001537fcd in BoxContainer::_notificationv (this=0x8851550, p_notification=31, p_reversed=false) at ./scene/gui/box_container.h:38
#17 0x00000000015387f3 in VBoxContainer::_notificationv (this=0x8851550, p_notification=31, p_reversed=false) at ./scene/gui/box_container.h:81
#18 0x0000000003983906 in Object::notification (this=0x8851550, p_notification=31, p_reversed=false) at core/object.cpp:931
#19 0x0000000003045efa in CanvasItem::_update_callback (this=0x8851550) at scene/2d/canvas_item.cpp:454
#20 0x0000000001537248 in MethodBind0::call (this=0x6cea340, p_object=0x8851550, p_args=0x0, p_arg_count=0, r_error=...) at ./core/method_bind.gen.inc:59
#21 0x00000000039837e9 in Object::call (this=0x8851550, p_method=..., p_args=0x0, p_argcount=0, r_error=...) at core/object.cpp:921
#22 0x000000000397a465 in MessageQueue::_call_function (this=0x61ecba0, p_target=0x8851550, p_func=..., p_args=0x7f5ff2f19080, p_argcount=0, p_show_error=false) at core/message_queue.cpp:250
#23 0x000000000397a721 in MessageQueue::flush (this=0x61ecba0) at core/message_queue.cpp:297
#24 0x0000000002be7a69 in SceneTree::iteration (this=0x7c885d0, p_time=0.0166666675) at scene/main/scene_tree.cpp:485
#25 0x00000000014cf094 in Main::iteration () at main/main.cpp:2005
#26 0x000000000149f3ed in OS_X11::run (this=0x7ffd7b849220) at platform/x11/os_x11.cpp:3262
#27 0x000000000148f8ac in main (argc=9, argv=0x7ffd7b8499e8) at platform/x11/godot_x11.cpp:56
neikeq commented 4 years ago

Not a language specific issue. Here's the same example project uploaded by @qarmin but in GDScript:

Test32470.zip

ericrybick commented 4 years ago

Making Label::_notification() & Label::regenerate_word_cache() thread safe methods would solve this issue, but I doubt that would be a good solution.

WizzardMaker commented 4 years ago

It would at least suffice if we would clearly state, that working with Labels isn't thread safe.

starryalley commented 4 years ago

I had a similar crash that happened when I try to load a texture on an Image in a thread function. The scene tree does contain some labels. The crash looks like this:

ERROR: ImageLoader::load_image: Error opening file: res://assets/some_image.jpg
   At: core\io\image_loader.cpp:56
ERROR: RasterizerStorageGLES3::texture_set_data: Condition ' !texture->active ' is true.
   At: drivers\gles3\rasterizer_storage_gles3.cpp:741
CrashHandlerException: Program crashed
Dumping the backtrace. Please include this when reporting the bug on https://github.com/godotengine/godot/issues
[0] Label::regenerate_word_cache (C:\Users\mark\project\godot\scene\gui\label.cpp:416)
[1] Label::regenerate_word_cache (C:\Users\mark\project\godot\scene\gui\label.cpp:416)
[2] Label::get_minimum_size (C:\Users\mark\project\godot\scene\gui\label.cpp:302)
[3] Control::get_combined_minimum_size (C:\Users\mark\project\godot\scene\gui\control.cpp:178)
[4] MarginContainer::get_minimum_size (C:\Users\mark\project\godot\scene\gui\margin_container.cpp:53)
[5] Control::get_combined_minimum_size (C:\Users\mark\project\godot\scene\gui\control.cpp:178)
[6] Control::_update_minimum_size (C:\Users\mark\project\godot\scene\gui\control.cpp:277)
[7] MethodBind0<Control>::call (C:\Users\mark\project\godot\core\method_bind.gen.inc:140)
[8] Object::call (C:\Users\mark\project\godot\core\object.cpp:940)
[9] MessageQueue::_call_function (C:\Users\mark\project\godot\core\message_queue.cpp:256)
[10] MessageQueue::flush (C:\Users\mark\project\godot\core\message_queue.cpp:322)
[11] SceneTree::iteration (C:\Users\mark\project\godot\scene\main\scene_tree.cpp:476)
[12] Main::iteration (C:\Users\mark\project\godot\main\main.cpp:1860)
[13] OS_Windows::run (C:\Users\mark\project\godot\platform\windows\os_windows.cpp:2821)
[14] widechar_main (C:\Users\mark\project\godot\platform\windows\godot_windows.cpp:151)
[15] _main (C:\Users\mark\project\godot\platform\windows\godot_windows.cpp:175)
[16] main (C:\Users\mark\project\godot\platform\windows\godot_windows.cpp:185)
[17] __scrt_common_main_seh (d:\agent\_work\2\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288)
[18] BaseThreadInitThunk
-- END OF BACKTRACE --
ERROR: ImageLoader::load_image: Error opening file: res://assets/some_image.jpg
   At: core\io\image_loader.cpp:56
ERROR: NetSocketPosix::_get_socket_error: Socket error: 10054
   At: drivers\unix\net_socket_posix.cpp:190

I'll probably change my code so that modifying UI in a thread won't happen.

KoBeWi commented 3 years ago

Still valid in 3.2.4 beta4 The project won't run on master due to syntax errors.

qarmin commented 3 years ago

Still happens with 3.4.beta.custom_build. 7c1ee0488 Tested project - Tester.zip

scene/gui/label.cpp:418:17: runtime error: member access within null pointer of type 'struct WordCache'
handle_crash: Program crashed with signal 11
Dumping the backtrace. Please include this when reporting the bug on https://github.com/godotengine/godot/issues
ERROR: Condition "!id_map.has(p_rid.get_data())" is true. Returned: nullptr
   at: get (./core/rid.h:140)
ERROR: Condition "!texture" is true.
   at: texture_set_data (drivers/gles3/rasterizer_storage_gles3.cpp:705)
[1] /usr/bin/godots() [0x17b5100] (/mnt/Miecz/godot3.2/platform/x11/crash_handler_x11.cpp:54)
[2] /lib/x86_64-linux-gnu/libc.so.6(+0x41040) [0x7f25e10a1040] (??:0)
[3] Label::regenerate_word_cache() (/mnt/Miecz/godot3.2/scene/gui/label.cpp:418)
[4] Label::get_line_count() const (/mnt/Miecz/godot3.2/scene/gui/label.cpp:346)
[5] MethodBind0RC<int>::call(Object*, Variant const**, int, Variant::CallError&) (/mnt/Miecz/godot3.2/./core/method_bind.gen.inc:593 (discriminator 4))
[6] Object::call(StringName const&, Variant const**, int, Variant::CallError&) (/mnt/Miecz/godot3.2/core/object.cpp:918 (discriminator 1))
[7] Variant::call_ptr(StringName const&, Variant const**, int, Variant*, Variant::CallError&) (/mnt/Miecz/godot3.2/core/variant_call.cpp:1173 (discriminator 1))
[8] GDScriptFunction::call(GDScriptInstance*, Variant const**, int, Variant::CallError&, GDScriptFunction::CallState*) (/mnt/Miecz/godot3.2/modules/gdscript/gdscript_function.cpp:1032)
[9] GDScriptInstance::call(StringName const&, Variant const**, int, Variant::CallError&) (/mnt/Miecz/godot3.2/modules/gdscript/gdscript.cpp:1151)
[10] Object::call(StringName const&, Variant const**, int, Variant::CallError&) (/mnt/Miecz/godot3.2/core/object.cpp:899 (discriminator 1))
[11] Variant::call_ptr(StringName const&, Variant const**, int, Variant*, Variant::CallError&) (/mnt/Miecz/godot3.2/core/variant_call.cpp:1173 (discriminator 1))
[12] GDScriptFunction::call(GDScriptInstance*, Variant const**, int, Variant::CallError&, GDScriptFunction::CallState*) (/mnt/Miecz/godot3.2/modules/gdscript/gdscript_function.cpp:1037)
[13] GDScriptInstance::call(StringName const&, Variant const**, int, Variant::CallError&) (/mnt/Miecz/godot3.2/modules/gdscript/gdscript.cpp:1151)
[14] Object::call(StringName const&, Variant const**, int, Variant::CallError&) (/mnt/Miecz/godot3.2/core/object.cpp:899 (discriminator 1))
[15] _Thread::_start_func(void*) (/mnt/Miecz/godot3.2/core/bind/core_bind.cpp:2596 (discriminator 1))
[16] Thread::callback(Thread*, Thread::Settings const&, void (*)(void*), void*) (/mnt/Miecz/godot3.2/core/os/thread.cpp:76)
[17] 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++/10/bits/invoke.h:60)
[18] 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++/10/bits/invoke.h:96)
[19] void 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++/10/thread:264)
[20] std::thread::_Invoker<std::tuple<void (*)(Thread*, Thread::Settings const&, void (*)(void*), void*), Thread*, Thread::Settings, void (*)(void*), void*> >::operator()() (/usr/include/c++/10/thread:271)
[21] 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++/10/thread:215)
[22] /usr/bin/godots() [0x131d2824] (thread.o:?)
[23] /lib/x86_64-linux-gnu/libpthread.so.0(+0x9450) [0x7f25e1d1e450] (??:0)
[24] /lib/x86_64-linux-gnu/libc.so.6(clone+0x43) [0x7f25e1177d53] (??:0)
-- END OF BACKTRACE --