Fixed panic on PreviewPanel::drop.

This commit is contained in:
Filipe Rodrigues 2021-05-31 01:52:28 +01:00
parent a3aa4bc1fc
commit dbbb888f7f
2 changed files with 20 additions and 0 deletions

View File

@ -88,6 +88,7 @@ impl epi::App for FileEditor {
egui::menu::menu(ui, "File", |ui| {
// On open, ask the user and open the file
if ui.button("Open").clicked() {
// Ask the user for the file
let cur_dir_path = std::env::current_dir().expect("Unable to get current directory path");
*file_path = FileDialog::new()
.set_location(&cur_dir_path)
@ -174,6 +175,12 @@ impl epi::App for FileEditor {
}
fn on_exit(&mut self) {
// Forget all images we have
// TODO: Somehow get a frame here to drop them?
if let Some(preview_panel) = &mut self.preview_panel {
preview_panel.forget_textures();
}
// Flush the file if we have it
if let Some(loaded_game) = &mut self.loaded_game {
match loaded_game.game_file_mut().cdrom().flush() {

View File

@ -105,6 +105,19 @@ impl PreviewPanel {
}
}
/// Forgets all textures in this panel without freeing them
pub fn forget_textures(&mut self) {
match self {
PreviewPanel::Tim { pallettes, .. } => {
pallettes.drain(..);
},
PreviewPanel::Tis { images } => {
images.drain(..);
},
_ => (),
}
}
/// Displays this panel
pub fn display(&self, ctx: &egui::CtxRef) {
egui::CentralPanel::default().show(ctx, |ui| match self {