Fix crash when game name cannot be parsed (#216)

This commit is contained in:
Logan McNaughton 2025-02-04 13:01:33 +01:00 committed by GitHub
parent 166b7daa9d
commit ad4eddb408
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 8 deletions

View File

@ -395,10 +395,12 @@ fn parse_rom_file(file: std::path::PathBuf, tx: std::sync::mpsc::Sender<GameInfo
let rom_contents = device::get_rom_contents(file.as_path());
if !rom_contents.is_empty() {
let hash = device::cart::rom::calculate_hash(&rom_contents);
let game_name = std::str::from_utf8(&rom_contents[0x20..0x20 + 0x14])
.unwrap()
.trim()
.replace('\0', "");
let mut game_name = "Unknown".to_owned();
let header_value = std::str::from_utf8(&rom_contents[0x20..0x34]);
if header_value.is_ok() {
game_name = header_value.unwrap().trim().replace('\0', "");
}
tx.send((
hash,
game_name,

View File

@ -109,10 +109,11 @@ pub fn init(ui: &mut ui::Ui, rom: &[u8]) {
let base_path = ui.dirs.data_dir.join("saves");
let game_name = std::str::from_utf8(&rom[0x20..0x20 + 0x14])
.unwrap()
.trim()
.replace('\0', "");
let mut game_name = "".to_owned();
let header_value = std::str::from_utf8(&rom[0x20..0x34]);
if header_value.is_ok() {
game_name = header_value.unwrap().trim().replace('\0', "");
}
let prefix = if game_name.is_empty() {
&ui.game_id