more crash protection (#831)
This commit is contained in:
parent
01863a70a8
commit
3d6ca17a9a
@ -113,8 +113,10 @@ pub fn load_savestate(device: &mut device::Device) {
|
||||
let save_bytes = ui::storage::decompress_file(savestate, "saves");
|
||||
let rdp_state = ui::storage::decompress_file(savestate, "rdp_state");
|
||||
let ra_state = ui::storage::decompress_file(savestate, "ra_state");
|
||||
if let Ok(state) = postcard::from_bytes::<device::Device>(&device_bytes) {
|
||||
device.ui.storage.saves = postcard::from_bytes(&save_bytes).unwrap();
|
||||
if let Ok(state) = postcard::from_bytes::<device::Device>(&device_bytes)
|
||||
&& let Ok(saves) = postcard::from_bytes(&save_bytes)
|
||||
{
|
||||
device.ui.storage.saves = saves;
|
||||
|
||||
device.cpu = state.cpu;
|
||||
device.pif = state.pif;
|
||||
|
||||
@ -36,8 +36,10 @@ fn check_latest_version(weak: slint::Weak<AppWindow>) {
|
||||
if let Ok(response) = response {
|
||||
let data: Result<GithubData, reqwest::Error> = response.json().await;
|
||||
|
||||
let latest_version = if let Ok(data) = data {
|
||||
semver::Version::parse(&data.tag_name[1..]).unwrap()
|
||||
let latest_version = if let Ok(data) = data
|
||||
&& let Ok(github_version) = semver::Version::parse(&data.tag_name[1..])
|
||||
{
|
||||
github_version
|
||||
} else {
|
||||
semver::Version::parse(env!("CARGO_PKG_VERSION")).unwrap()
|
||||
};
|
||||
@ -108,15 +110,7 @@ fn local_game_window(
|
||||
config
|
||||
.recent_roms
|
||||
.iter()
|
||||
.filter(|x| {
|
||||
if let Ok(exists) = std::fs::exists(x)
|
||||
&& exists
|
||||
{
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
})
|
||||
.filter(|x| std::fs::exists(x).unwrap_or(false))
|
||||
.map(|x| {
|
||||
(
|
||||
x.into(),
|
||||
|
||||
@ -316,7 +316,7 @@ fn hotkey_pressed(
|
||||
sdl3_sys::gamepad::SDL_GamepadButton(controller_button.id),
|
||||
)
|
||||
};
|
||||
} else if controller_axis.enabled {
|
||||
} else if controller_axis.enabled && !controller.is_null() {
|
||||
let axis_position = unsafe {
|
||||
sdl3_sys::gamepad::SDL_GetGamepadAxis(
|
||||
controller,
|
||||
@ -332,7 +332,7 @@ fn hotkey_pressed(
|
||||
pressed = (unsafe { sdl3_sys::joystick::SDL_GetJoystickHat(joystick, joystick_hat.id) }
|
||||
& joystick_hat.direction)
|
||||
!= 0;
|
||||
} else if joystick_axis.enabled {
|
||||
} else if joystick_axis.enabled && !joystick.is_null() {
|
||||
let axis_position =
|
||||
unsafe { sdl3_sys::joystick::SDL_GetJoystickAxis(joystick, joystick_axis.id) };
|
||||
pressed = axis_position as isize * joystick_axis.axis as isize > 0
|
||||
|
||||
@ -228,8 +228,10 @@ pub fn load_saves(ui: &mut ui::Ui, netplay: &mut Option<netplay::Netplay>) {
|
||||
ui.storage.saves.sdcard.data = sdcard;
|
||||
}
|
||||
let romsave = std::fs::read(&ui.storage.paths.romsave_file_path);
|
||||
if let Ok(romsave) = romsave {
|
||||
ui.storage.saves.romsave.data = postcard::from_bytes(romsave.as_ref()).unwrap();
|
||||
if let Ok(romsave) = romsave
|
||||
&& let Ok(romsave_data) = postcard::from_bytes(romsave.as_ref())
|
||||
{
|
||||
ui.storage.saves.romsave.data = romsave_data;
|
||||
}
|
||||
}
|
||||
|
||||
@ -316,7 +318,9 @@ pub fn load_saves(ui: &mut ui::Ui, netplay: &mut Option<netplay::Netplay>) {
|
||||
netplay::receive_save(netplay.as_mut().unwrap(), "rom", &mut compressed_romsave);
|
||||
if !compressed_romsave.is_empty() {
|
||||
let romsave_bytes = decompress_file(&compressed_romsave, "save");
|
||||
ui.storage.saves.romsave.data = postcard::from_bytes(&romsave_bytes).unwrap();
|
||||
if let Ok(romsave_data) = postcard::from_bytes(&romsave_bytes) {
|
||||
ui.storage.saves.romsave.data = romsave_data;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user