Browse Source

Sensor: Check if getConstant is successful.

Miku AuahDark 2 years ago
parent
commit
bc1c619599
1 changed files with 7 additions and 4 deletions
  1. 7 4
      src/modules/event/sdl/Event.cpp

+ 7 - 4
src/modules/event/sdl/Event.cpp

@@ -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";
-					sensor::Sensor::getConstant(sensor::sdl::Sensor::convert(SDL_SensorGetType(sensor)), sensorType);
+					const char *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));