Add error handling in love.sensor.getData and only pass 3 values on love.sensorupdate.

This commit is contained in:
Miku AuahDark
2022-12-05 22:22:25 +08:00
parent a4b94cd848
commit bdbd4a9a58
2 changed files with 11 additions and 7 deletions
+9 -3
View File
@@ -104,10 +104,16 @@ std::vector<float> Sensor::getData(SensorType type)
throw love::Exception("\"%s\" sensor is not enabled", name);
}
std::vector<float> values;
values.resize(3);
std::vector<float> values(3);
if (SDL_SensorGetData(sensors[type], values.data(), values.size()) != 0)
{
const char *name = nullptr;
getConstant(type, name);
throw love::Exception("Could not get \"%s\" SDL sensor data (%s)", name, SDL_GetError());
}
SDL_SensorGetData(sensors[type], values.data(), 3);
return values;
}