diff --git a/agb/src/display/tiled/vram_manager.rs b/agb/src/display/tiled/vram_manager.rs index e2818088..5b5f798d 100644 --- a/agb/src/display/tiled/vram_manager.rs +++ b/agb/src/display/tiled/vram_manager.rs @@ -116,6 +116,10 @@ impl TileReferenceCount { self.reference_count = 0; self.tile_in_tile_set = None; } + + fn current_count(&self) -> u16 { + self.reference_count + } } #[non_exhaustive] @@ -279,6 +283,9 @@ impl VRamManager { pub(crate) fn gc(&mut self) { for tile_index in self.indices_to_gc.drain(..) { let index = tile_index.index() as usize; + if self.reference_counts[index].current_count() > 0 { + continue; // it has since been added back + } let tile_reference = Self::reference_from_index(tile_index); unsafe { diff --git a/examples/the-hat-chooses-the-wizard/src/main.rs b/examples/the-hat-chooses-the-wizard/src/main.rs index 1a3a0edc..de8f3ea9 100644 --- a/examples/the-hat-chooses-the-wizard/src/main.rs +++ b/examples/the-hat-chooses-the-wizard/src/main.rs @@ -273,8 +273,8 @@ impl<'a, 'b> Map<'a, 'b> { self.background.set_pos(vram, self.position.floor()); self.foreground.set_pos(vram, self.position.floor()); - self.background.commit(); - self.foreground.commit(); + self.background.commit(vram); + self.foreground.commit(vram); } pub fn init_background(&mut self, vram: &mut VRamManager) -> PartialUpdateStatus { @@ -793,7 +793,7 @@ fn main(mut agb: agb::Gba) -> ! { } } - world_display.commit(); + world_display.commit(&mut vram); world_display.show(); splash_screen::show_splash_screen( @@ -835,7 +835,7 @@ fn main(mut agb: agb::Gba) -> ! { &mut vram, ); - world_display.commit(); + world_display.commit(&mut vram); world_display.show(); music_box.before_frame(&mut mixer); diff --git a/examples/the-hat-chooses-the-wizard/src/splash_screen.rs b/examples/the-hat-chooses-the-wizard/src/splash_screen.rs index b39e39f9..64243b9b 100644 --- a/examples/the-hat-chooses-the-wizard/src/splash_screen.rs +++ b/examples/the-hat-chooses-the-wizard/src/splash_screen.rs @@ -76,7 +76,7 @@ pub fn show_splash_screen( } } - map.commit(); + map.commit(vram); vram.set_background_palettes(palette); map.show(); diff --git a/examples/the-purple-night/src/main.rs b/examples/the-purple-night/src/main.rs index ea822c4d..930f7cd9 100644 --- a/examples/the-purple-night/src/main.rs +++ b/examples/the-purple-night/src/main.rs @@ -85,9 +85,9 @@ impl<'a> Level<'a> { foreground.init(vram, start_pos, &mut between_updates); clouds.init(vram, start_pos / 4, &mut between_updates); - backdrop.commit(); - foreground.commit(); - clouds.commit(); + backdrop.commit(vram); + foreground.commit(vram); + clouds.commit(vram); backdrop.show(); foreground.show(); @@ -2081,9 +2081,9 @@ impl<'a> Game<'a> { .commit_with_fudge(this_frame_offset, (0, 0).into()); } - self.level.background.commit(); - self.level.foreground.commit(); - self.level.clouds.commit(); + self.level.background.commit(vram); + self.level.foreground.commit(vram); + self.level.clouds.commit(vram); for i in remove { self.particles.remove(i);