emilk/egui

Crash on wasm when using a color picker widget

Opened this issue · 0 comments

Describe the bug

When using a color picker, the program crashes with a memory access out of bounds error:

Full stack trace:

at runtime.wasm._$LT$egui..util..fixed_cache..FixedCache$LT$K$C$V$GT$$u20$as$u20$core..default..Default$GT$::default::h08e5bf05ab64fedc (runtime.wasm:0xb462ba)
    at runtime.wasm.core::ops::function::FnOnce::call_once::hd70bb3e0870fdf33 (runtime.wasm:0xda3649)
    at runtime.wasm.dynCall_vi (runtime.wasm:0x24f41c3)
    at wrapper (runtime.js:5270:20)
    at runtime.js:645:12
    at invoke_vi (runtime.js:13046:5)
    at imports.<computed> (runtime.js:5241:24)
    at runtime.wasm.egui::util::id_type_map::IdTypeMap::get_temp_mut_or_insert_with::he3265547730f1602 (runtime.wasm:0x7e893e)
    at runtime.wasm.egui::util::id_type_map::IdTypeMap::get_temp_mut_or_default::hbdb10fb0dbb4eaac (runtime.wasm:0x7e7adc)
    at runtime.wasm.dynCall_iij (runtime.wasm:0x24f6921)

To Reproduce

// setup egui using glow
// omitted
set_main_loop_wrapper(move || {
        // Get the egui context and begin drawing the frame
        let ctx = platform.context();
        // Draw an egui window
        egui::Window::new("Hello, world!").show(&ctx, |ui| {
            ui.label("Hello, world!");
            if ui.button("Greet").clicked() {
                println!("Hello, world!");
            }
            ui.horizontal(|ui| {
                ui.label("Color: ");
                ui.color_edit_button_rgb(&mut color); // if I comment this line, the crash disappears and everything works as expected
            });
            ui.code_editor(&mut text);
        });
        
        // More opengl code to render egui
});

Expected behavior

No crashes

Environment

  • OS: Windows 11
  • Browser: chrome
  • EGUI Version: 0.32.2
  • Target: wasm-unknown-emscripten

Additional context

I suspect the issue comes from the FIXED_CACHE_SIZE which fills up the stack on platforms like emscripten where stack space is limited.
Maybe having an option to change this cache size would help.

I don't know the full context and the purpose of this cache, but maybe it could be stored on the heap?

Note that if I compile the same program for desktop, no crashes occur