1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-30 21:30:03 -04:00

Support returning errors when creating the app (#4565)

The closure passed to `eframe::run_native` now returns a `Result`,
allowing you to return an error during app creation, which will be
returned to the caller of `run_native`.

This means you need to wrap your `Box::new(MyApp::new(…))` in an
`Ok(…)`.

* Closes https://github.com/emilk/egui/issues/4474
This commit is contained in:
Emil Ernerfeldt
2024-05-28 21:59:19 +02:00
committed by GitHub
parent 54429e0549
commit 942fe4ab31
28 changed files with 44 additions and 36 deletions

View File

@@ -30,7 +30,7 @@ impl Drop for AppRunner {
impl AppRunner {
/// # Errors
/// Failure to initialize WebGL renderer.
/// Failure to initialize WebGL renderer, or failure to create app.
pub async fn new(
canvas_id: &str,
web_options: crate::WebOptions,
@@ -71,7 +71,7 @@ impl AppRunner {
let theme = system_theme.unwrap_or(web_options.default_theme);
egui_ctx.set_visuals(theme.egui_visuals());
let app = app_creator(&epi::CreationContext {
let cc = epi::CreationContext {
egui_ctx: egui_ctx.clone(),
integration_info: info.clone(),
storage: Some(&storage),
@@ -86,7 +86,8 @@ impl AppRunner {
wgpu_render_state: painter.render_state(),
#[cfg(all(feature = "wgpu", feature = "glow"))]
wgpu_render_state: None,
});
};
let app = app_creator(&cc).map_err(|err| err.to_string())?;
let frame = epi::Frame {
info,

View File

@@ -54,7 +54,7 @@ impl WebRunner {
/// Create the application, install callbacks, and start running the app.
///
/// # Errors
/// Failing to initialize graphics.
/// Failing to initialize graphics, or failure to create app.
pub async fn start(
&self,
canvas_id: &str,