extension-imgui icon indicating copy to clipboard operation
extension-imgui copied to clipboard

HTML5 error when adding font

Open SalavatR opened this issue 2 years ago • 12 comments

hi! after release on html5 platform, we got errors, can't reproduce local

"RuntimeError: abort(Assertion failed: font_cfg->FontData != 0L && font_cfg->FontDataSize > 0, at: upload/imgui/src/imgui/imgui_draw.cpp,1899,AddFont). Build with -s ASSERTIONS=1 for more info.","abort@:1:12355","___assert_fail@:1:19145"

SalavatR avatar Aug 16 '23 06:08 SalavatR

It looks like it is font related. Are you using a custom font and imgui.font_add_ttf_data()? If so, is the font available and loaded correctly?

britzl avatar Aug 16 '23 06:08 britzl

yes, it works like a charm on all available devices and browsers, but i got this error in sentry

SalavatR avatar Aug 22 '23 07:08 SalavatR

this error never happens if we run directly html page our QA sometimes cought it only in iframe on platforms

SalavatR avatar Apr 11 '24 12:04 SalavatR

our QA sometimes cought it only in iframe on platforms

Interesting. How are you loading the font?

britzl avatar Apr 11 '24 13:04 britzl

	imgui.set_ini_filename()
	imgui.set_ini_filename("devtool.ini")
	-- dv.set_style()

	imgui.set_style_color(imgui.ImGuiCol_MenuBarBg, 1.0, 0.01, 0.02, 0.01)
	local w, h = window.get_size()

	local global_font_scale = 2.2
	local scale_all_sizes = 2.5
	if w > h then
		global_font_scale = global_font_scale * w / display_height
	else
		global_font_scale = global_font_scale * h / display_height
	end
	imgui.scale_all_sizes(scale_all_sizes)

	local regular_data, error = sys.load_resource("/assets/imgui_res/space_mono_regular.ttf")
	if sysutil.is_android() then
		imgui.set_global_font_scale(global_font_scale)
	elseif regular_data then
		imgui.font_add_ttf_data(regular_data, #regular_data, 12.0 * global_font_scale, 12.0 * global_font_scale)
	end

SalavatR avatar Apr 11 '24 14:04 SalavatR

imgui/src/imgui/imgui_draw.cpp,1899,AddFont

I should probably update to the latest version of DearImGUI. The version used in this extension is two years old. It might help.

One thing which you could do is to add some printf()'s in imgui_draw.cpp:1899 to check what exactly it is asserting on.

britzl avatar Apr 12 '24 10:04 britzl

@SalavatR would you mind trying with the latest version? It was updated to ImGui 1.89.9. And if it doesn't work then please provide a sample project that I can try.

britzl avatar Jun 02 '24 06:06 britzl

Hello! i found repro case on mac os

https://yandex.ru/games/app/183506

https://vk.com/app7952341

https://ok.ru/game/mergehotel

if i open many tabs very fast i got error: image

But i got it only in iframes, can't get when open direct links from cnd https://cdn.mergeitgame.com/html5/yg/index.html https://cdn.mergeitgame.com/html5/vk/index.html https://cdn.mergeitgame.com/html5/ok/index.html

SalavatR avatar Jul 22 '24 03:07 SalavatR

if i open many tabs very fast i got error:

I can also reproduce this. I looked more closely at the code when the font is loaded from memory and there is a memory allocation that might fail. I've now added a check for this and a dmLogWarning(). Perhaps you could try the new version and see if the failed allocation was the reason?

https://github.com/britzl/extension-imgui/releases/tag/2.3.1

britzl avatar Jul 22 '24 06:07 britzl

image still same error

SalavatR avatar Jul 22 '24 13:07 SalavatR

That is not exactly the same error though. Initially it was IM_ASSERT(font_cfg->FontData != NULL && font_cfg->FontDataSize > 0); but now it is IM_ASSERT(font_cfg->SizePixels > 0.0f);

britzl avatar Jul 22 '24 20:07 britzl

What is the size you are passing to imgui.font_add_ttf_data() ?

britzl avatar Jul 22 '24 20:07 britzl