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

WebGPU backend causes crash after window resize #7873

Closed
sava41 opened this issue Aug 9, 2024 · 2 comments
Closed

WebGPU backend causes crash after window resize #7873

sava41 opened this issue Aug 9, 2024 · 2 comments

Comments

@sava41
Copy link

sava41 commented Aug 9, 2024

Version/Branch of Dear ImGui:

Version 1.91.0, Branch: master

Back-ends:

imgui_impl_sdl3.cpp + imgui_impl_wgpu.cpp

Compiler, OS:

linux clang (emscripten)

Full config/build information:

NA

Details:

I believe this issue is partially related to #7765.

My application runs fine until I resize the window at which point I get a crash with the following error message:

Uncaught TypeError: Failed to execute 'createBindGroup' on 'GPUDevice': Failed to read the 'entries' property from 'GPUBindGroupDescriptor': Failed to read the 'resource' property from 'GPUBindGroupEntry': Required member is undefined.
    at _wgpuDeviceCreateBindGroup ()
    at canvas.wasm.ImGui_ImplWGPU_CreateImageBindGroup(WGPUBindGroupLayoutImpl*, WGPUTextureViewImpl*)
    at canvas.wasm.ImGui_ImplWGPU_RenderDrawData(ImDrawData*, WGPURenderPassEncoderImpl*)

This issue is caused by ImTextureID tex_id = pcmd->GetTexID(); in ImGui_ImplWGPU_RenderDrawData returning null after a window resize.

This issue only happens when I compile my application for the web. On desktop it works without issues.

I'm not using any textures with ImGUI aside from the font atlas so what texture is typically bound to each draw command? Is there a default 1x1 white texture somewhere?

Edit: Ok correct me if I'm wrong but it looks like the font atlas is bound to the texture bind group by default. The question now remains why pcmd->GetTexID(); returns the correct id before a window resize and null after a resize.

@sava41
Copy link
Author

sava41 commented Aug 9, 2024

Some more information about this bug. This issue started when I added SDL_WINDOW_HIGH_PIXEL_DENSITY to SDL_CreateWindow. After some more testing I found pcmd->GetTexID() only returns null when resizing on a display with fractional UI scaling (150%, 175%, etc). Still not sure about the root cause.

@sava41
Copy link
Author

sava41 commented Aug 21, 2024

I finally had the chance to look at this again and it was an issue on my end. I was rebuilding my fonts on SDL display scale change events like so in my sdl events handler function:

    case SDL_EVENT_DISPLAY_CONTENT_SCALE_CHANGED:
    case SDL_EVENT_WINDOW_DISPLAY_SCALE_CHANGED:
        app->dpiFactor = SDL_GetWindowDisplayScale( app->window );
        rebuildImGuiFonts();

For some reason on fractional dpi scaling, these events get triggered on a window resize (float precision error maybe?)

These events also would get trigged when the font atlas was locked by ImGui::NewFrame() so the atlas would not get rebuilt correctly causing io.Fonts->TexID to return null.

I have modified that code snipet to the following and now everything works:

    case SDL_EVENT_DISPLAY_CONTENT_SCALE_CHANGED:
    case SDL_EVENT_WINDOW_DISPLAY_SCALE_CHANGED:
        // do comparison with ints to eliminate precision error
        if( static_cast<int>( app->dpiFactor * 100 ) != static_cast<int>( SDL_GetWindowDisplayScale( app->window ) * 100 ) )
        {
            app->dpiFactor = SDL_GetWindowDisplayScale( app->window );

            //rebuild font next time the atlas is not locked
            app->rebuildFontAtlas = true;
        }

@sava41 sava41 closed this as completed Aug 21, 2024
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

2 participants