Properly initialize variables + fix changes.txt

This commit is contained in:
snippet
2025-10-14 20:55:49 +11:00
parent a8ed7ac7d9
commit 5f4cfacf8a
2 changed files with 10 additions and 4 deletions
+2 -2
View File
@@ -29,8 +29,8 @@ Released: N/A
* Added Joystick:hasSensor. * Added Joystick:hasSensor.
* Added Joystick:isSensorEnabled and Joystick:setSensorEnabled. * Added Joystick:isSensorEnabled and Joystick:setSensorEnabled.
* Added Joystick:getSensorData. * Added Joystick:getSensorData.
* Added Joystick:getDeviceBatteryPercent and Joystick:getDevicePowerState, these expose how charged batteries in a controller are and if they're charging * Added Joystick:getPowerInfo which exposes infomation about batteries in a controller are and if they're charging.
* Added Joystick:getConnectionState which indicates if a joystick is connected wired or wireless * Added Joystick:getConnectionState which indicates if a joystick is connected wired or wireless.
* Added new Gamepad API buttons: "misc1", "paddle1", "paddle2", "paddle3", "paddle4". and "touchpad". * Added new Gamepad API buttons: "misc1", "paddle1", "paddle2", "paddle3", "paddle4". and "touchpad".
* Added World:getFixturesInArea(). * Added World:getFixturesInArea().
* Added support for saving .exr image files via ImageData:encode. * Added support for saving .exr image files via ImageData:encode.
+8 -2
View File
@@ -465,9 +465,12 @@ void Joystick::getDeviceInfo(int &vendorID, int &productID, int &productVersion)
Joystick::PowerType Joystick::getPowerInfo(int& batteryPercent) const Joystick::PowerType Joystick::getPowerInfo(int& batteryPercent) const
{ {
// Gets the battery state of a joystick/gamepad // Gets the battery state of a joystick/gamepad
Joystick::PowerType powerState; Joystick::PowerType powerState = Joystick::PowerType::POWER_UNKNOWN;
SDL_PowerState batteryState; SDL_PowerState batteryState;
if (!isConnected())
return powerState;
batteryState = SDL_GetJoystickPowerInfo(joyhandle, &batteryPercent); batteryState = SDL_GetJoystickPowerInfo(joyhandle, &batteryPercent);
getConstant(batteryState, powerState); getConstant(batteryState, powerState);
@@ -477,9 +480,12 @@ Joystick::PowerType Joystick::getPowerInfo(int& batteryPercent) const
Joystick::ConnectionType Joystick::getConnectionState() const Joystick::ConnectionType Joystick::getConnectionState() const
{ {
// Gets the connection state of a joystick/gamepad (wired / wireless etc) // Gets the connection state of a joystick/gamepad (wired / wireless etc)
Joystick::ConnectionType connectionState; Joystick::ConnectionType connectionState = Joystick::ConnectionType::CONNECTION_UNKNOWN;
SDL_JoystickConnectionState sdlConnectionState; SDL_JoystickConnectionState sdlConnectionState;
if (!isConnected())
return connectionState;
sdlConnectionState = SDL_GetJoystickConnectionState(joyhandle); sdlConnectionState = SDL_GetJoystickConnectionState(joyhandle);
getConstant(sdlConnectionState, connectionState); getConstant(sdlConnectionState, connectionState);