From 3e34ad6890a08bc2572da52a6b4fc2f967b4681d Mon Sep 17 00:00:00 2001 From: James Rowe Date: Thu, 16 Jan 2020 23:17:07 -0700 Subject: [PATCH] Hack: Workaround crash when loading state and gyro is used --- src/core/hle/service/hid/hid.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp index 012a37e6bc..6898c1024e 100644 --- a/src/core/hle/service/hid/hid.cpp +++ b/src/core/hle/service/hid/hid.cpp @@ -207,6 +207,10 @@ void Module::UpdateAccelerometerCallback(u64 userdata, s64 cycles_late) { next_accelerometer_index = (next_accelerometer_index + 1) % mem->accelerometer.entries.size(); Common::Vec3 accel; + if (!motion_device) { + is_device_reload_pending.exchange(true); + return; + } std::tie(accel, std::ignore) = motion_device->GetStatus(); accel *= accelerometer_coef; // TODO(wwylele): do a time stretch like the one in UpdateGyroscopeCallback @@ -254,6 +258,10 @@ void Module::UpdateGyroscopeCallback(u64 userdata, s64 cycles_late) { GyroscopeDataEntry& gyroscope_entry = mem->gyroscope.entries[mem->gyroscope.index]; Common::Vec3 gyro; + if (!motion_device) { + is_device_reload_pending.exchange(true); + return; + } std::tie(std::ignore, gyro) = motion_device->GetStatus(); double stretch = system.perf_stats->GetLastFrameTimeScale(); gyro *= gyroscope_coef * static_cast(stretch);