Skip to content

Commit d3560f3

Browse files
committed
Fix resource manager not popping debug group on error
1 parent 6f1882d commit d3560f3

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

toybox-gfx/src/resource_manager.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ impl ResourceManager {
198198
pub fn process_requests(&mut self, core: &mut core::Core, vfs: &vfs::Vfs) -> anyhow::Result<()> {
199199
core.push_debug_group("Process Resource Requests");
200200

201+
let _debug_group_guard = common::defer(|| core.pop_debug_group());
202+
201203
self.load_shader_requests.process_requests(&mut self.shaders, |def| {
202204
let label = def.path.display().to_string();
203205

@@ -225,10 +227,6 @@ impl ResourceManager {
225227
Ok(ImageResource::from_create_request(core, def))
226228
})?;
227229

228-
// TODO(pat.m): this will never be reached if the above fails, but if the above fails
229-
// the whole engine is probably coming down anyway
230-
core.pop_debug_group();
231-
232230
Ok(())
233231
}
234232
}

toybox-gfx/src/resource_manager/image.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl super::Resource for ImageResource {
6161
}
6262

6363
impl ImageResource {
64-
pub fn from_vfs(core: &mut Core, vfs: &vfs::Vfs, virtual_path: &Path, label: String) -> anyhow::Result<ImageResource> {
64+
pub fn from_vfs(core: &Core, vfs: &vfs::Vfs, virtual_path: &Path, label: String) -> anyhow::Result<ImageResource> {
6565
// TODO(pat.m): use a BufReader instead so that image can read only what it needs
6666
let data = vfs.load_resource_data(virtual_path)?;
6767

@@ -84,7 +84,7 @@ impl ImageResource {
8484
})
8585
}
8686

87-
pub fn array_from_vfs(core: &mut Core, vfs: &vfs::Vfs, virtual_paths: &[PathBuf], label: String) -> anyhow::Result<ImageResource> {
87+
pub fn array_from_vfs(core: &Core, vfs: &vfs::Vfs, virtual_paths: &[PathBuf], label: String) -> anyhow::Result<ImageResource> {
8888
if virtual_paths.is_empty() {
8989
anyhow::bail!("Trying to create empty image array")
9090
}
@@ -128,7 +128,7 @@ impl ImageResource {
128128
})
129129
}
130130

131-
pub fn from_create_request(core: &mut Core, req: &CreateImageRequest) -> ImageResource {
131+
pub fn from_create_request(core: &Core, req: &CreateImageRequest) -> ImageResource {
132132
let mut image_info = req.image_info.clone();
133133

134134
match req.resize_policy {
@@ -162,7 +162,7 @@ impl ImageResource {
162162
}
163163
}
164164

165-
pub(crate) fn on_resize(&mut self, core: &mut Core) {
165+
pub(crate) fn on_resize(&mut self, core: &Core) {
166166
let size_2d = match self.resize_policy {
167167
ImageResizePolicy::Fixed => return,
168168
ImageResizePolicy::MatchBackbuffer => core.backbuffer_size(),

toybox-gfx/src/resource_manager/shader.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl super::Resource for ShaderResource {
3636
}
3737

3838
impl ShaderResource {
39-
pub fn from_source(core: &mut core::Core, shader_type: ShaderType, data: &str, label: &str) -> anyhow::Result<ShaderResource> {
39+
pub fn from_source(core: &core::Core, shader_type: ShaderType, data: &str, label: &str) -> anyhow::Result<ShaderResource> {
4040
// TODO(pat.m): ugh
4141
let uses_user_clipping = data.contains("gl_ClipDistance");
4242

@@ -76,7 +76,7 @@ impl ShaderResource {
7676
})
7777
}
7878

79-
pub fn from_vfs(core: &mut core::Core, vfs: &vfs::Vfs, shader_type: ShaderType, virtual_path: &Path, label: &str) -> anyhow::Result<ShaderResource> {
79+
pub fn from_vfs(core: &core::Core, vfs: &vfs::Vfs, shader_type: ShaderType, virtual_path: &Path, label: &str) -> anyhow::Result<ShaderResource> {
8080
let data = vfs.load_resource_data(virtual_path)?;
8181
let data = String::from_utf8(data)?;
8282

@@ -86,7 +86,7 @@ impl ShaderResource {
8686

8787

8888
// TODO(pat.m): Could this be in core?
89-
fn reflect_workgroup_size(core: &mut core::Core, shader_name: ShaderName) -> Option<Vec3i> {
89+
fn reflect_workgroup_size(core: &core::Core, shader_name: ShaderName) -> Option<Vec3i> {
9090
if shader_name.shader_type != ShaderType::Compute {
9191
return None
9292
}

0 commit comments

Comments
 (0)