godotengine / godot

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

Godot freezes due to print statements in thread within an EditorPlugin #43705

Open winston-yallow opened 3 years ago

winston-yallow commented 3 years ago

Godot version: v3.2.3.stable.official

OS/device including version: OS: Solus x86_64 (Kernel 5.6.19-159.current) CPU: Intel i5-7400

Issue description: Printing repeatedly in a thread (started within the editor) will freeze godot. The following error is printed in an endless scroll to the terminal if godot was started from the command line:

ERROR: _process_line: Index line = 0 is out of bounds (l.offset_caches.size() = 0).
   At: scene/gui/rich_text_label.cpp:170.

Steps to reproduce: Start a thread repeatedly that prints to the output. The output tab must be open for godot to freeze after enough lines were printed. It never happens on the first run of the thread, but at one of the following runs.

Minimal reproduction project: The project contains a small plugin that can freeze the engine. Steps to use this project:

  1. Open the output tab
  2. Press the "CRASH" button at the top right corner of the editor
  3. Wait till you can press it again, then go back to step 2

Project zip: bug.zip Bug file: ./addons/freezer/CrashButton.gd (thread method in line 40)

winston-yallow commented 3 years ago

Could anyone help me and point me to a starting point where this might be related to in the source code? I would like to try and investigate but are a bit lost for a starting point.

Edit: Removed first sentence and changed some words as it sounded a bit too demanding

akien-mga commented 3 years ago

The problem is that RichTextLabel (which is used by the Output panel) is not thread safe. You'd have to see if you can make RichTextLabel thread safe, or make the Output panel's code that handles receiving and printing messages thread safe.

akien-mga commented 3 years ago

Related (or duplicate, but that one is not about thread use) to #38058.