From 82b68fc335ccb72efa9aa1855e7536304359c957 Mon Sep 17 00:00:00 2001 From: Corwin Date: Mon, 3 Apr 2023 01:54:40 +0100 Subject: [PATCH] mark function that can be used unsafely unsafe --- agb/src/display/object/managed.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/agb/src/display/object/managed.rs b/agb/src/display/object/managed.rs index bdc62002..dd9e3d04 100644 --- a/agb/src/display/object/managed.rs +++ b/agb/src/display/object/managed.rs @@ -155,7 +155,9 @@ impl OAMManager<'_> { } } - fn do_work_with_sprite_loader(&self, c: C) -> T + /// SAFETY: + /// Do not reenter or recurse or otherwise use sprite loader cell during this. + unsafe fn do_work_with_sprite_loader(&self, c: C) -> T where C: Fn(&mut StaticSpriteLoader) -> T, { @@ -184,7 +186,10 @@ impl OAMManager<'_> { // finished OAM interactions self.object_store.remove_all_in_removal_list(); - self.do_work_with_sprite_loader(StaticSpriteLoader::garbage_collect); + // safety: not reentrant + unsafe { + self.do_work_with_sprite_loader(StaticSpriteLoader::garbage_collect); + } } pub fn add_object(&self, sprite: SpriteVram) -> Object<'_> { @@ -193,7 +198,10 @@ impl OAMManager<'_> { } pub fn get_vram_sprite(&self, sprite: &'static Sprite) -> SpriteVram { - self.do_work_with_sprite_loader(|sprite_loader| sprite_loader.get_vram_sprite(sprite)) + // safety: not reentrant + unsafe { + self.do_work_with_sprite_loader(|sprite_loader| sprite_loader.get_vram_sprite(sprite)) + } } pub fn add_object_static_sprite(&self, sprite: &'static Sprite) -> Object<'_> {