mirror of
https://github.com/love2d/love.git
synced 2026-08-19 20:19:42 +02:00
Sensor: Check if getConstant is successful.
This commit is contained in:
@@ -463,8 +463,10 @@ Message *Event::convert(const SDL_Event &e)
|
|||||||
if (e.sensor.which == id)
|
if (e.sensor.which == id)
|
||||||
{
|
{
|
||||||
// Found sensor
|
// Found sensor
|
||||||
const char *sensorType = "unknown";
|
const char *sensorType;
|
||||||
sensor::Sensor::getConstant(sensor::sdl::Sensor::convert(SDL_SensorGetType(sensor)), sensorType);
|
if (!sensor::Sensor::getConstant(sensor::sdl::Sensor::convert(SDL_SensorGetType(sensor)), sensorType))
|
||||||
|
sensorType = "unknown";
|
||||||
|
|
||||||
vargs.emplace_back(sensorType, strlen(sensorType));
|
vargs.emplace_back(sensorType, strlen(sensorType));
|
||||||
// Both accelerometer and gyroscope only pass up to 3 values.
|
// Both accelerometer and gyroscope only pass up to 3 values.
|
||||||
// https://github.com/libsdl-org/SDL/blob/SDL2/include/SDL_sensor.h#L81-L127
|
// https://github.com/libsdl-org/SDL/blob/SDL2/include/SDL_sensor.h#L81-L127
|
||||||
@@ -603,9 +605,10 @@ Message *Event::convertJoystickEvent(const SDL_Event &e) const
|
|||||||
{
|
{
|
||||||
using Sensor = love::sensor::Sensor;
|
using Sensor = love::sensor::Sensor;
|
||||||
|
|
||||||
const char *sensorName = "unknown";
|
const char *sensorName;
|
||||||
Sensor::SensorType sensorType = love::sensor::sdl::Sensor::convert((SDL_SensorType) e.csensor.sensor);
|
Sensor::SensorType sensorType = love::sensor::sdl::Sensor::convert((SDL_SensorType) e.csensor.sensor);
|
||||||
Sensor::getConstant(sensorType, sensorName);
|
if (!Sensor::getConstant(sensorType, sensorName))
|
||||||
|
sensorName = "unknown";
|
||||||
|
|
||||||
vargs.emplace_back(joysticktype, stick);
|
vargs.emplace_back(joysticktype, stick);
|
||||||
vargs.emplace_back(sensorName, strlen(sensorName));
|
vargs.emplace_back(sensorName, strlen(sensorName));
|
||||||
|
|||||||
Reference in New Issue
Block a user