Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugs when setting BitmapFont in Project Settings #52262

Closed
dalexeev opened this issue Aug 30, 2021 · 9 comments
Closed

Bugs when setting BitmapFont in Project Settings #52262

dalexeev opened this issue Aug 30, 2021 · 9 comments

Comments

@dalexeev
Copy link
Member

dalexeev commented Aug 30, 2021

Godot version

3.3.3, 3.4 beta 4, 4.0-dev

System information

Kubuntu 21.04

Issue description

Setting BitmapFont as a custom font in Project Settings (gui/theme/custom_font) brings up strange bugs that are slightly different in different projects and different versions of Godot. That said, it used to work correctly before (in 3.2), and even in these versions the font worked without any errors until I re-generated it.

I don't know if this bug is OS dependent. The only assumption is that this bug occurs due to the wrong order of code execution (race condition?). In this case, in the future, both resources (both the texture and the font) are loaded correctly, you can see this in the editor and in the running project.

I managed to catch crashes in both versions when starting the editor. If you delete the .import folder, then in 3.4 beta 4 the editor will start normally, but the font will not work globally (only locally), and the same 7 errors will be displayed when the project starts.

Real project, Godot 3.3.3
handle_crash: Program crashed with signal 11
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(+0x41040) [0x7f4b32397040] (??:0)
-- END OF BACKTRACE --
Real project, Godot 3.4 beta 4

MRP, Godot 3.3.3
handle_crash: Program crashed with signal 8
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(+0x41040) [0x7fad7f99d040] (??:0)
[2] /home/danil/.local/bin/godot_3.3.3() [0x1ae5df8] (??:0)
[3] /home/danil/.local/bin/godot_3.3.3() [0x1b2d1a5] (??:0)
[4] /home/danil/.local/bin/godot_3.3.3() [0x1ae1c52] (??:0)
[5] /home/danil/.local/bin/godot_3.3.3() [0x1ae1d4c] (??:0)
[6] /home/danil/.local/bin/godot_3.3.3() [0x1af0597] (??:0)
[7] /home/danil/.local/bin/godot_3.3.3() [0x1af1d16] (??:0)
[8] /home/danil/.local/bin/godot_3.3.3() [0x1afbd3e] (??:0)
[9] /home/danil/.local/bin/godot_3.3.3() [0x1afbebf] (??:0)
[10] /home/danil/.local/bin/godot_3.3.3() [0x2077cdb] (??:0)
[11] /home/danil/.local/bin/godot_3.3.3() [0x9db592] (??:0)
[12] /home/danil/.local/bin/godot_3.3.3() [0x20e27fe] (??:0)
[13] /home/danil/.local/bin/godot_3.3.3() [0x20e3079] (??:0)
[14] /home/danil/.local/bin/godot_3.3.3() [0x264dbc0] (??:0)
[15] /home/danil/.local/bin/godot_3.3.3() [0x25673bf] (??:0)
[16] /home/danil/.local/bin/godot_3.3.3() [0x2f02065] (??:?)
[17] /home/danil/.local/bin/godot_3.3.3() [0xe50446] (??:0)
[18] /home/danil/.local/bin/godot_3.3.3() [0xe55c16] (??:0)
[19] /home/danil/.local/bin/godot_3.3.3() [0xe56adc] (??:0)
[20] /home/danil/.local/bin/godot_3.3.3() [0x25f1536] (??:0)
[21] /home/danil/.local/bin/godot_3.3.3() [0xe142e4] (??:0)
[22] /home/danil/.local/bin/godot_3.3.3() [0x1cda1ae] (??:0)
[23] /home/danil/.local/bin/godot_3.3.3() [0x1ceb9ef] (??:0)
[24] /home/danil/.local/bin/godot_3.3.3() [0x3119a3d] (??:?)
[25] /home/danil/.local/bin/godot_3.3.3() [0x990dcd] (??:0)
[26] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xd5) [0x7fad7f984565] (??:0)
[27] /home/danil/.local/bin/godot_3.3.3() [0x99f5ae] (??:0)
-- END OF BACKTRACE --
MRP, Godot 3.4 beta 4
handle_crash: Program crashed with signal 8
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(+0x41040) [0x7fce0b21e040] (??:0)
[2] /home/danil/Рабочий стол/Godot_v3.4-beta4_x11.64() [0x1ec9e58] (??:0)
[3] /home/danil/Рабочий стол/Godot_v3.4-beta4_x11.64() [0x1ecf32d] (??:0)
[4] /home/danil/Рабочий стол/Godot_v3.4-beta4_x11.64() [0x1ecf682] (??:0)
[5] /home/danil/Рабочий стол/Godot_v3.4-beta4_x11.64() [0x1ecf77c] (??:0)
[6] /home/danil/Рабочий стол/Godot_v3.4-beta4_x11.64() [0x1ed5ee7] (??:0)
[7] /home/danil/Рабочий стол/Godot_v3.4-beta4_x11.64() [0x1ed6475] (??:0)
[8] /home/danil/Рабочий стол/Godot_v3.4-beta4_x11.64() [0x1eef22e] (??:0)
[9] /home/danil/Рабочий стол/Godot_v3.4-beta4_x11.64() [0x1eeffff] (??:0)
[10] /home/danil/Рабочий стол/Godot_v3.4-beta4_x11.64() [0x19557d2] (??:0)
[11] /home/danil/Рабочий стол/Godot_v3.4-beta4_x11.64() [0x2e616ea] (??:0)
[12] /home/danil/Рабочий стол/Godot_v3.4-beta4_x11.64() [0x195ccf4] (??:0)
[13] /home/danil/Рабочий стол/Godot_v3.4-beta4_x11.64() [0x195d579] (??:0)
[14] /home/danil/Рабочий стол/Godot_v3.4-beta4_x11.64() [0x1480fc1] (??:0)
[15] /home/danil/Рабочий стол/Godot_v3.4-beta4_x11.64() [0xb44895] (??:0)
[16] /home/danil/Рабочий стол/Godot_v3.4-beta4_x11.64() [0x2b333c9] (??:0)
[17] /home/danil/Рабочий стол/Godot_v3.4-beta4_x11.64() [0x2b337bd] (??:0)
[18] /home/danil/Рабочий стол/Godot_v3.4-beta4_x11.64() [0x2b3449c] (??:0)
[19] /home/danil/Рабочий стол/Godot_v3.4-beta4_x11.64() [0x1427e16] (??:0)
[20] /home/danil/Рабочий стол/Godot_v3.4-beta4_x11.64() [0x1d73b66] (??:0)
[21] /home/danil/Рабочий стол/Godot_v3.4-beta4_x11.64() [0x1d7cfed] (??:0)
[22] /home/danil/Рабочий стол/Godot_v3.4-beta4_x11.64() [0x9ce017] (??:0)
[23] /home/danil/Рабочий стол/Godot_v3.4-beta4_x11.64() [0x93dd75] (??:0)
[24] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xd5) [0x7fce0b205565] (??:0)
[25] /home/danil/Рабочий стол/Godot_v3.4-beta4_x11.64() [0x9516ee] (??:0)
-- END OF BACKTRACE --

Steps to reproduce

See MRP.

Minimal reproduction project

tmp35.zip

@akien-mga
Copy link
Member

Here's a stacktrace from trying to open the script editor after having deleted the .import folder:

ERROR: Condition "img.is_null() || img->empty()" is true. Returned: ERR_FILE_CORRUPT
   at: _load_data (scene/resources/texture.cpp:566)
ERROR: Failed loading resource: res://.import/font.png-b6bb944f072a9edca7c6221ef7aeb6c9.stex. Make sure resources have been imported by opening the project in the editor at least once.
   at: _load (core/io/resource_loader.cpp:270)
ERROR: Failed loading resource: res://font.png. Make sure resources have been imported by opening the project in the editor at least once.
   at: _load (core/io/resource_loader.cpp:270)
ERROR: Can't load dependency: res://font.png.
   at: poll (core/io/resource_format_binary.cpp:611)
ERROR: Failed to load resource 'res://font.font'.
   at: load (core/io/resource_loader.cpp:206)
ERROR: Failed loading resource: res://font.font. Make sure resources have been imported by opening the project in the editor at least once.
   at: _load (core/io/resource_loader.cpp:270)
ERROR: Error loading custom font 'res://font.font'
   at: register_scene_types (scene/register_scene_types.cpp:778)

================================================================
handle_crash: Program crashed with signal 8
Engine version: Godot Engine v3.4.beta.custom_build (25bd0c3f72fd39daafb17e34764b08a715db763e)
Dumping the backtrace. Please include this when reporting the bug on https://github.com/godotengine/godot/issues
[1] /lib64/libc.so.6(+0x3ac90) [0x7f351ad37c90] (??:0)
[2] TextEdit::Text::get_char_width(wchar_t, wchar_t, int) const (/home/akien/Projects/godot/godot-3.x/scene/gui/text_edit.cpp:316)
[3] TextEdit::Text::_update_line_cache(int) const (/home/akien/Projects/godot/godot-3.x/scene/gui/text_edit.cpp:135 (discriminator 3))
[4] TextEdit::Text::get_line_width(int) const (/home/akien/Projects/godot/godot-3.x/scene/gui/text_edit.cpp:236)
[5] TextEdit::Text::get_max_width(bool) const (/home/akien/Projects/godot/godot-3.x/scene/gui/text_edit.cpp:280)
[6] TextEdit::_update_scrollbars() (/home/akien/Projects/godot/godot-3.x/scene/gui/text_edit.cpp:346)
[7] TextEdit::_insert_text_at_cursor(String const&) (/home/akien/Projects/godot/godot-3.x/scene/gui/text_edit.cpp:4285)
[8] TextEdit::set_text(String) (/home/akien/Projects/godot/godot-3.x/scene/gui/text_edit.cpp:4967 (discriminator 35))
[9] ScriptTextEditor::set_edited_resource(Ref<Resource> const&) (/home/akien/Projects/godot/godot-3.x/editor/plugins/script_text_editor.cpp:148 (discriminator 2))
[10] ScriptEditor::edit(Ref<Resource> const&, int, int, bool) (/home/akien/Projects/godot/godot-3.x/editor/plugins/script_editor_plugin.cpp:2097)
[11] ScriptEditor::edit(Ref<Resource> const&, bool) (/home/akien/Projects/godot/godot-3.x/editor/plugins/script_editor_plugin.h:426)
[12] ScriptEditorPlugin::edit(Object*) (/home/akien/Projects/godot/godot-3.x/editor/plugins/script_editor_plugin.cpp:3456 (discriminator 3))
[13] EditorNode::_edit_current() (/home/akien/Projects/godot/godot-3.x/editor/editor_node.cpp:2118)
[14] EditorNode::push_item(Object*, String const&, bool) (/home/akien/Projects/godot/godot-3.x/editor/editor_node.cpp:1928)
[15] InspectorDock::_resource_selected(Ref<Resource> const&, String const&) const (/home/akien/Projects/godot/godot-3.x/editor/inspector_dock.cpp:296)
[16] InspectorDock::edit_resource(Ref<Resource> const&) (/home/akien/Projects/godot/godot-3.x/editor/inspector_dock.cpp:392 (discriminator 2))
[17] EditorNode::load_resource(String const&, bool) (/home/akien/Projects/godot/godot-3.x/editor/editor_node.cpp:992)
[18] FileSystemDock::_select_file(String const&, bool) (/home/akien/Projects/godot/godot-3.x/editor/filesystem_dock.cpp:947)
[19] FileSystemDock::_tree_activate_file() (/home/akien/Projects/godot/godot-3.x/editor/filesystem_dock.cpp:961 (discriminator 12))
[20] MethodBind0::call(Object*, Variant const**, int, Variant::CallError&) (/home/akien/Projects/godot/godot-3.x/./core/method_bind.gen.inc:61 (discriminator 4))
[21] Object::call(StringName const&, Variant const**, int, Variant::CallError&) (/home/akien/Projects/godot/godot-3.x/core/object.cpp:918 (discriminator 1))
[22] Object::emit_signal(StringName const&, Variant const**, int) (/home/akien/Projects/godot/godot-3.x/core/object.cpp:1226 (discriminator 1))
[23] Object::emit_signal(StringName const&, Variant const&, Variant const&, Variant const&, Variant const&, Variant const&) (/home/akien/Projects/godot/godot-3.x/core/object.cpp:1282)
[24] Tree::_gui_input(Ref<InputEvent>) (/home/akien/Projects/godot/godot-3.x/scene/gui/tree.cpp:2623 (discriminator 2))
[25] MethodBind1<Ref<InputEvent> >::call(Object*, Variant const**, int, Variant::CallError&) (/home/akien/Projects/godot/godot-3.x/./core/method_bind.gen.inc:775 (discriminator 12))
[26] Object::call_multilevel(StringName const&, Variant const**, int) (/home/akien/Projects/godot/godot-3.x/core/object.cpp:766 (discriminator 1))
[27] Object::call_multilevel(StringName const&, Variant const&, Variant const&, Variant const&, Variant const&, Variant const&) (/home/akien/Projects/godot/godot-3.x/core/object.cpp:864)
[28] Viewport::_gui_call_input(Control*, Ref<InputEvent> const&) (/home/akien/Projects/godot/godot-3.x/scene/main/viewport.cpp:1632 (discriminator 2))
[29] Viewport::_gui_input_event(Ref<InputEvent>) (/home/akien/Projects/godot/godot-3.x/scene/main/viewport.cpp:1951 (discriminator 3))
[30] Viewport::input(Ref<InputEvent> const&) (/home/akien/Projects/godot/godot-3.x/scene/main/viewport.cpp:2783 (discriminator 2))
[31] Viewport::_vp_input(Ref<InputEvent> const&) (/home/akien/Projects/godot/godot-3.x/scene/main/viewport.cpp:1402)
[32] MethodBind1<Ref<InputEvent> const&>::call(Object*, Variant const**, int, Variant::CallError&) (/home/akien/Projects/godot/godot-3.x/./core/method_bind.gen.inc:775 (discriminator 12))
[33] Object::call(StringName const&, Variant const**, int, Variant::CallError&) (/home/akien/Projects/godot/godot-3.x/core/object.cpp:918 (discriminator 1))
[34] Object::call(StringName const&, Variant const&, Variant const&, Variant const&, Variant const&, Variant const&) (/home/akien/Projects/godot/godot-3.x/core/object.cpp:848)
[35] SceneTree::call_group_flags(unsigned int, StringName const&, StringName const&, Variant const&, Variant const&, Variant const&, Variant const&, Variant const&) (/home/akien/Projects/godot/godot-3.x/scene/main/scene_tree.cpp:272)
[36] SceneTree::input_event(Ref<InputEvent> const&) (/home/akien/Projects/godot/godot-3.x/scene/main/scene_tree.cpp:431 (discriminator 6))
[37] InputDefault::_parse_input_event_impl(Ref<InputEvent> const&, bool) (/home/akien/Projects/godot/godot-3.x/main/input_default.cpp:494)
[38] InputDefault::flush_buffered_events() (/home/akien/Projects/godot/godot-3.x/main/input_default.cpp:714)
[39] OS_X11::process_xevents() (/home/akien/Projects/godot/godot-3.x/platform/x11/os_x11.cpp:2908)
[40] OS_X11::run() (/home/akien/Projects/godot/godot-3.x/platform/x11/os_x11.cpp:3638)
[41] godot-3.x(main+0x109) [0x178881f] (/home/akien/Projects/godot/godot-3.x/platform/x11/godot_x11.cpp:57)
[42] /lib64/libc.so.6(__libc_start_main+0xcd) [0x7f351ad247dd] (??:0)
[43] godot-3.x(_start+0x2a) [0x178866a] (??:?)
-- END OF BACKTRACE --
================================================================

@akien-mga akien-mga modified the milestones: 3.4, 3.5 Nov 8, 2021
@dalexeev
Copy link
Member Author

4.0-dev also has this problem. If you specify a font in the Project Settings or set it in the default theme, the project will load endlessly, without errors in the console. It looks like there is indeed some kind of error in the project load order related to images.

@dalexeev
Copy link
Member Author

I researched this problem in 4.0, MRP was hard for me.

For some reason, custom_font conflicts with some GDScript files. Initially I thought that the problem only occurs when loading the project in the editor. But I managed to isolate the problem and get stuck in an already loaded project. The fact that the project hangs when loading is a consequence of the fact that there is GDScript in autoload. I discovered this when I tried to reproduce the custom_font issue in an empty project (without autoloads).

Steps to reproduce:

  1. Load MRP - custom_font_and_gdscript_conflict.zip.
  2. Try to open correct.gd.
  3. Try to open error.gd (editor freezes, v4.0.dev.custom_build [340883636]).
    error.gd differs from correct.gd only by the presence of an empty _ready function.

Note that this only applies to 4.0, I haven't tested it in 3.x and I'm guessing something else (but possibly similar) is causing the problem.

@YuriSizov
Copy link
Contributor

Isn't this a duplicate of #55008 which is fixed in 3.4.1 by #55484 and in master by #55483?

@bruvzg
Copy link
Member

bruvzg commented Dec 29, 2021

Note that this only applies to 4.0, I haven't tested it in 3.x and I'm guessing something else (but possibly similar) is causing the problem.

Seems like it caused by tab size being zero (which is caused by zero space size), and it's stuck here trying to align the line to the tab offset:

while (tab_off <= off) {
tab_off += p_tab_stops[tab_index];
tab_index++;
if (tab_index >= p_tab_stops.size()) {
tab_index = 0;
}
}
.

@YuriSizov
Copy link
Contributor

YuriSizov commented Dec 29, 2021

Should probably open a new issue for that then. 🙃 Doesn't seem to be related to the OP.

@bruvzg
Copy link
Member

bruvzg commented Dec 29, 2021

Click to expand
diff --git a/modules/text_server_adv/text_server_adv.cpp b/modules/text_server_adv/text_server_adv.cpp
index 5eb55f4584..aeb04f50c1 100644
--- a/modules/text_server_adv/text_server_adv.cpp
+++ b/modules/text_server_adv/text_server_adv.cpp
@@ -3681,6 +3681,12 @@ float TextServerAdvanced::shaped_text_tab_align(RID p_shaped, const PackedFloat3
 		const_cast<TextServerAdvanced *>(this)->shaped_text_update_breaks(p_shaped);
 	}
 
+	for (int i = 0; i < p_tab_stops.size(); i++) {
+		if (p_tab_stops[i] <= 0) {
+			return 0.f;
+		}
+	}
+
 	int tab_index = 0;
 	float off = 0.f;
 
diff --git a/modules/text_server_fb/text_server_fb.cpp b/modules/text_server_fb/text_server_fb.cpp
index 09adeacfe0..77f26958bb 100644
--- a/modules/text_server_fb/text_server_fb.cpp
+++ b/modules/text_server_fb/text_server_fb.cpp
@@ -2665,6 +2665,12 @@ float TextServerFallback::shaped_text_tab_align(RID p_shaped, const PackedFloat3
 		const_cast<TextServerFallback *>(this)->shaped_text_update_breaks(p_shaped);
 	}
 
+	for (int i = 0; i < p_tab_stops.size(); i++) {
+		if (p_tab_stops[i] <= 0) {
+			return 0.f;
+		}
+	}
+
 	int tab_index = 0;
 	float off = 0.f;
 

A quick fix for a tab issue. But I'm not sure why it's trying to set TextEdit font to the random one when you are opening arbitrary script, there's something else wrong as well.

@dalexeev
Copy link
Member Author

Yes, I tested, the problem is really in the tabs.

(Tabs! I was your faithful follower, and you betrayed me! I am switching to spaces. 🤣)

@dalexeev
Copy link
Member Author

dalexeev commented Dec 29, 2021

Since the problem has been fixed in all branches, I close this issue.

@bruvzg The tabs issue needs to be fixed separately. Should I open a new issue for this?

EDIT: Although curious why the custom_font setting affects the tabs.

@Calinou Calinou removed this from the 3.5 milestone Dec 29, 2021
@Calinou Calinou removed the confirmed label Dec 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants