Skip to content

Fails during run when trying to add a Menu #40

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
golden-moss opened this issue Oct 16, 2018 · 4 comments · May be fixed by #96
Open

Fails during run when trying to add a Menu #40

golden-moss opened this issue Oct 16, 2018 · 4 comments · May be fixed by #96
Labels
c-bug Bug - some feature is not working as expected p-high High Priority
Milestone

Comments

@golden-moss
Copy link

Using the basic example as a baseline to make sure the error wasn't on my end, I tried to add a menu, changing the window type to HasMenubar and adding let menu = Menu::new(&ui, "Test Menu"); This complies without issues, but fails instantly at runtime. This happens whenever a new menu is defined.

   Compiling iui v0.3.0 (file:///X:/Documents/code_projects/libui-rs/iui)
warning: unused variable: `menu`
  --> examples\basic.rs:19:13
   |
19 |     let mut menu = Menu::new(&ui, "Test Menu");
   |             ^^^^ help: consider using `_menu` instead
   |
   = note: #[warn(unused_variables)] on by default

warning: variable does not need to be mutable
  --> examples\basic.rs:19:9
   |
19 |     let mut menu = Menu::new(&ui, "Test Menu");
   |         ----^^^^
   |         |
   |         help: remove this `mut`
   |
   = note: #[warn(unused_mut)] on by default

    Finished dev [unoptimized + debuginfo] target(s) in 0.59s
     Running `target\debug\examples\basic.exe`
error: process didn't exit successfully: `target\debug\examples\basic.exe` (exit code: 2147483651)
PS X:\Documents\code_projects\libui-rs\iui> cargo run --example basic
   Compiling iui v0.3.0 (file:///X:/Documents/code_projects/libui-rs/iui)
warning: unused variable: `menu`
  --> examples\basic.rs:19:9
   |
19 |     let menu = Menu::new(&ui, "Test Menu");
   |         ^^^^ help: consider using `_menu` instead
   |
   = note: #[warn(unused_variables)] on by default

    Finished dev [unoptimized + debuginfo] target(s) in 0.56s
     Running `target\debug\examples\basic.exe`
error: process didn't exit successfully: `target\debug\examples\basic.exe` (exit code: 2147483651)
PS X:\Documents\code_projects\libui-rs\iui> 
@NoraCodes NoraCodes added c-bug Bug - some feature is not working as expected p-high High Priority labels Oct 17, 2018
@mitchhentges
Copy link
Contributor

Workaround: Create the menu before the window:

let menu = Menu::new(&ui, "Test Menu");
let mut win = Window::new(&ui, "Test App", 200, 200, WindowType::HasMenubar);

This looks like the underlying issue is a Windows-specific problem. Linux also crashes the application, but it provides an error reason why:

** (iui-example:16391): CRITICAL **: 22:44:42.686: [libui] /...snip.../ui-sys-0.1.3/libui/unix/menu.c:233:uiNewMenu() You have a bug: You cannot create a new menu after menus have been finalized.

However, Windows doesn't share the helpful message:

error: process didn't exit successfully: target\debug\iui-example.exe (exit code: 2147483651)

@NoraCodes
Copy link
Collaborator

OK, we can solve this with a different API design; I'll have the UI handle recall whether or not menus have been initialized, and if they have, prevent you from changing menus.

Thanks for figuring this out.

@NoraCodes NoraCodes added this to the 0.4 Release milestone Feb 26, 2019
@aaneto
Copy link

aaneto commented Mar 3, 2019

Would it make sense for the WindowType enum to have NoMenubar and HasMenubar options with a menu inside?

@Inc0n
Copy link

Inc0n commented Mar 26, 2020

Could one possible fix is maybe change the fifth enum parameter of the control::window::new to a Option<Menu>, which could be None.

So, if we want no menu bar:

Window::new(&ui, "Test App", 200, 200, None);

And with menu bar:

Window::new(&ui, "Test App", 200, 200, Menu::new(&ui, "Test Menu"));

Having this style of api means:

  • (Assume that rust evaluate parameters first before calling) we can be sure of that the menu is created before the window.

  • Adding an intuitive way of adding menus to windows, avoiding the error probe usage of the library, i.e (calling menu after window):

let mut win = Window::new(&ui, "Test App", 200, 200, WindowType::HasMenubar);
Menu::new(&ui, "Test Menu");

@NoraCodes NoraCodes linked a pull request Aug 9, 2020 that will close this issue
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
c-bug Bug - some feature is not working as expected p-high High Priority
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants