don't crash on missing resource base path
This commit is contained in:
parent
5ed9a42f8e
commit
f384959fc6
2 changed files with 30 additions and 11 deletions
|
@ -404,7 +404,10 @@ impl Button {
|
|||
.clone()
|
||||
.map(|icon| {
|
||||
Image::from_file(AssetPath::from((
|
||||
gui_handler.resource_base_path().full_path(),
|
||||
gui_handler
|
||||
.resource_base_path()
|
||||
.ok_or(anyhow!("resource base path not set!"))?
|
||||
.full_path(),
|
||||
icon,
|
||||
)))?
|
||||
.attach_sampler(Sampler::nearest_sampler().build(gui_handler.device())?)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::prelude::*;
|
||||
use anyhow::Result;
|
||||
use anyhow::{Result, anyhow};
|
||||
use assetpath::AssetPath;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use utilities::{impl_reprc, prelude::*};
|
||||
|
@ -189,7 +189,7 @@ pub struct GuiHandler {
|
|||
width: AtomicU32,
|
||||
height: AtomicU32,
|
||||
|
||||
resource_base_path: AssetPath,
|
||||
resource_base_path: Option<AssetPath>,
|
||||
|
||||
top_ui: RwLock<Option<Arc<dyn TopGui>>>,
|
||||
tooltip_ui: RwLock<Option<Arc<dyn TopGui>>>,
|
||||
|
@ -330,9 +330,7 @@ impl GuiHandler {
|
|||
hover_sound
|
||||
}),
|
||||
|
||||
resource_base_path: gui_handler_create_info
|
||||
.resource_directory
|
||||
.expect("missing resource directory"),
|
||||
resource_base_path: gui_handler_create_info.resource_directory,
|
||||
|
||||
top_ui: RwLock::new(None),
|
||||
tooltip_ui: RwLock::new(None),
|
||||
|
@ -437,7 +435,13 @@ impl GuiHandler {
|
|||
Some(image) => Ok(image),
|
||||
None => {
|
||||
if !path.has_prefix() {
|
||||
path.set_prefix(&self.resource_base_path().full_path());
|
||||
path.set_prefix(
|
||||
&self
|
||||
.resource_base_path
|
||||
.as_ref()
|
||||
.ok_or(anyhow!("resource base path not set!"))?
|
||||
.full_path(),
|
||||
);
|
||||
}
|
||||
|
||||
let image = Image::from_file(path)?
|
||||
|
@ -452,7 +456,13 @@ impl GuiHandler {
|
|||
},
|
||||
None => {
|
||||
if !path.has_prefix() {
|
||||
path.set_prefix(&self.resource_base_path().full_path());
|
||||
path.set_prefix(
|
||||
&self
|
||||
.resource_base_path
|
||||
.as_ref()
|
||||
.ok_or(anyhow!("resource base path not set!"))?
|
||||
.full_path(),
|
||||
);
|
||||
}
|
||||
|
||||
let image = Image::from_file(path.clone())?
|
||||
|
@ -499,7 +509,13 @@ impl GuiHandler {
|
|||
|
||||
pub(crate) fn displayable_image_from_path(&self, mut path: AssetPath) -> Result<Arc<Image>> {
|
||||
if !path.has_prefix() {
|
||||
path.set_prefix(&self.resource_base_path.full_path());
|
||||
path.set_prefix(
|
||||
&self
|
||||
.resource_base_path
|
||||
.as_ref()
|
||||
.ok_or(anyhow!("resource base path not set!"))?
|
||||
.full_path(),
|
||||
);
|
||||
}
|
||||
|
||||
if self.internal_textures.read().unwrap().contains_key(&path) {
|
||||
|
@ -571,8 +587,8 @@ impl GuiHandler {
|
|||
*self.ortho.read().unwrap()
|
||||
}
|
||||
|
||||
pub(crate) fn resource_base_path(&self) -> &AssetPath {
|
||||
&self.resource_base_path
|
||||
pub(crate) fn resource_base_path(&self) -> Option<&AssetPath> {
|
||||
self.resource_base_path.as_ref()
|
||||
}
|
||||
|
||||
#[cfg(feature = "audio")]
|
||||
|
|
Loading…
Reference in a new issue