britzl / extension-imgui

Dear ImGUI extension for Defold
MIT License
58 stars 19 forks source link

HTML5 error when adding font #29

Open SalavatR opened 1 year ago

SalavatR commented 1 year ago

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@anonymous>:1:12355","___assert_fail@<anonymous:1:19145"

britzl commented 1 year ago

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?

SalavatR commented 1 year ago

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

SalavatR commented 7 months ago

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

britzl commented 7 months ago

our QA sometimes cought it only in iframe on platforms

Interesting. How are you loading the font?

SalavatR commented 7 months ago
    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
britzl commented 6 months ago

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 commented 5 months ago

@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.

SalavatR commented 3 months ago

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

britzl commented 3 months ago

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

SalavatR commented 3 months ago
image

still same error

britzl commented 3 months ago

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 commented 3 months ago

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