Hack: Workaround crash when loading state and gyro is used

This commit is contained in:
James Rowe 2020-01-16 23:17:07 -07:00 committed by zhupengfei
parent 0effb229cd
commit 3e34ad6890

View file

@ -207,6 +207,10 @@ void Module::UpdateAccelerometerCallback(u64 userdata, s64 cycles_late) {
next_accelerometer_index = (next_accelerometer_index + 1) % mem->accelerometer.entries.size(); next_accelerometer_index = (next_accelerometer_index + 1) % mem->accelerometer.entries.size();
Common::Vec3<float> accel; Common::Vec3<float> accel;
if (!motion_device) {
is_device_reload_pending.exchange(true);
return;
}
std::tie(accel, std::ignore) = motion_device->GetStatus(); std::tie(accel, std::ignore) = motion_device->GetStatus();
accel *= accelerometer_coef; accel *= accelerometer_coef;
// TODO(wwylele): do a time stretch like the one in UpdateGyroscopeCallback // 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]; GyroscopeDataEntry& gyroscope_entry = mem->gyroscope.entries[mem->gyroscope.index];
Common::Vec3<float> gyro; Common::Vec3<float> gyro;
if (!motion_device) {
is_device_reload_pending.exchange(true);
return;
}
std::tie(std::ignore, gyro) = motion_device->GetStatus(); std::tie(std::ignore, gyro) = motion_device->GetStatus();
double stretch = system.perf_stats->GetLastFrameTimeScale(); double stretch = system.perf_stats->GetLastFrameTimeScale();
gyro *= gyroscope_coef * static_cast<float>(stretch); gyro *= gyroscope_coef * static_cast<float>(stretch);