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

Unhandled user callback exception on dynamic library interaction #5152

Open
CrazyboyQCD opened this issue Sep 24, 2024 · 3 comments
Open

Unhandled user callback exception on dynamic library interaction #5152

CrazyboyQCD opened this issue Sep 24, 2024 · 3 comments
Labels
eframe Relates to epi and eframe native-windows Running on native Windows OS

Comments

@CrazyboyQCD
Copy link

CrazyboyQCD commented Sep 24, 2024

Describe the bug
When use dynamic library to render, clicking the exit button the application stop for seconds and exit with error.

To Reproduce
Steps to reproduce the behavior:
main.rs:

use eframe::egui::{self, Context};
use eframe::{App, Frame};
use libloading::{Library, Symbol};
use std::fs;

pub struct Program {
    libs: Vec<Library>,
}

impl Default for Program {
    fn default() -> Program {
        let plugins = fs::read_dir("libs/").expect("no plugins folder!");
        let mut libs = vec![];
        for plugin in plugins {
            unsafe {
                let path = plugin.unwrap().path();
                let lib = Library::new(path).expect("couldn't find dll");
                libs.push(lib);
            }
        }
        Self { libs }
    }
}

impl App for Program {
    fn update(&mut self, ctx: &Context, _frame: &mut Frame) {
        for lib in &self.libs {
            unsafe {
                let func: Symbol<unsafe extern "C" fn(&Context)> = lib.get(b"render").unwrap();
                func(ctx);
            }
        }
        egui::SidePanel::right("main").show(ctx, |ui| {
            ui.heading("My egui Application Main");
        });
    }
}

fn main() {
    let options = eframe::NativeOptions {
        viewport: egui::ViewportBuilder::default().with_inner_size([320.0, 240.0]),
        ..Default::default()
    };
    eframe::run_native(
        "My egui App",
        options,
        Box::new(|_cc| Ok(Box::<Program>::default())),
    )
    .unwrap();
}

lib.rs:

use eframe::egui;
use eframe::egui::Context;

#[no_mangle]
pub fn render(ctx: &Context) {
    egui::SidePanel::left("dll").show(ctx, |ui| {
        ui.heading("My egui Application dll");
    });
}

Expected behavior
Exit normally.

Screenshots
image

Desktop (please complete the following information):

  • OS: Windows11

Additional context
Error appears on both Glow and wgpu backend.
Both panic before dropping painter.
Eframe version: 0.28.1
Error 0xc000041d exists when exception isn't handled in windows' user callback.

@valadaptive
Copy link
Contributor

The render function in lib.rs is not defined as extern "C" but it is imported as one, which might result in the calling convention mismatching.

@CrazyboyQCD
Copy link
Author

CrazyboyQCD commented Oct 10, 2024

The render function in lib.rs is not defined as extern "C" but it is imported as one, which might result in the calling convention mismatching.

It made no difference in my test. And I have something more from debugger(sorry for the pic reading but I don't know how to dump it in vscode) :
image
image
image
And it seem like a deallocation problem here (in the first pic it started from egui::memory::Memory when dropped IdTypeMap), may be it is caused by using Arc in dll(wait for more test)?

@CrazyboyQCD
Copy link
Author

CrazyboyQCD commented Oct 15, 2024

In 0.29.1, after using mimalloc and applying -Zbuild-std=core,std, allocation issue is toward to LayoutJob's text's dropping, and it seems like a double-free problem?
image

image

@emilk emilk added native-windows Running on native Windows OS eframe Relates to epi and eframe and removed bug Something is broken labels Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
eframe Relates to epi and eframe native-windows Running on native Windows OS
Projects
None yet
Development

No branches or pull requests

3 participants