emilk / emilk/egui

Segfault when passing egui context to dynamic library and recreating a window with a same name

Open
#2,801 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Rust
Stars
30.6k
Forks
2.1k
Avg merge
1d 9h
Merged PRs (30d)
72

Description

**Describe the bug**
```rs
#[no_mangle]
pub extern fn execute(game: &Game, user: &User, ctx: &egui::Context) {
egui::Window::new("Window name").show(ctx, |ui| {
ui.label("Hello from Rust!");
});
}
```
This is the dynamic library code.
The dynamic library gets loaded whenever I make a change.
If I change the window name to anything else, nothing bad happens and the old window disappears and instead, the new window with the new name appears. However, if I change the content inside the label, the program crashes with "Segmentation fault (core dumped)".

**Expected behavior**
Change names of windows in the dynamic library without segfault.

**Screenshots**
This is where the segfault occurs.
![image](https://user-images.githubusercontent.com/103130191/224482442-51486fd0-2f35-431a-a7d3-666f2f5c5f99.png)

**Desktop:**
- OS: Linux Ubuntu

**Additional context:**
If I pass just egui::UI, and create the window outside of the dynamic library, it works just fine.

Contributor guide

Open the contributing guide

Research direction

Begin by reproducing the dynamic-library reload using the supplied execute entry point and the egui::Window::new call on Ubuntu. Compare the behavior when only the window name changes with changing the label content, and inspect the context passed across the library boundary. Done means repeated reloads no longer produce the reported segmentation fault.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
desktop
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.