mark function that can be used unsafely unsafe

This commit is contained in:
Corwin 2023-04-03 01:54:40 +01:00
parent f86bf9c07a
commit 82b68fc335
No known key found for this signature in database

View file

@ -155,7 +155,9 @@ impl OAMManager<'_> {
}
}
fn do_work_with_sprite_loader<C, T>(&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<C, T>(&self, c: C) -> T
where
C: Fn(&mut StaticSpriteLoader) -> T,
{
@ -184,8 +186,11 @@ impl OAMManager<'_> {
// finished OAM interactions
self.object_store.remove_all_in_removal_list();
// safety: not reentrant
unsafe {
self.do_work_with_sprite_loader(StaticSpriteLoader::garbage_collect);
}
}
pub fn add_object(&self, sprite: SpriteVram) -> Object<'_> {
self.object_store
@ -193,8 +198,11 @@ impl OAMManager<'_> {
}
pub fn get_vram_sprite(&self, sprite: &'static Sprite) -> SpriteVram {
// 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<'_> {
self.add_object(self.get_vram_sprite(sprite))