Comments (4)
Feel free to make a PR!
from sdl.
If the issue is only in RAWINPUT_JoystickOpen
, are the following OK?
For SDL3:
diff --git a/src/joystick/windows/SDL_rawinputjoystick.c b/src/joystick/windows/SDL_rawinputjoystick.c
index 4b0213c..24422e7 100644
--- a/src/joystick/windows/SDL_rawinputjoystick.c
+++ b/src/joystick/windows/SDL_rawinputjoystick.c
@@ -1294,6 +1294,7 @@ static int RAWINPUT_JoystickOpen(SDL_Joystick *joystick, int device_index)
value_caps = SDL_stack_alloc(HIDP_VALUE_CAPS, caps.NumberInputValueCaps);
if (SDL_HidP_GetValueCaps(HidP_Input, value_caps, &caps.NumberInputValueCaps, ctx->preparsed_data) != HIDP_STATUS_SUCCESS) {
RAWINPUT_JoystickClose(joystick);
+ SDL_stack_free(button_caps);
return SDL_SetError("Couldn't get device value capabilities");
}
@@ -1322,6 +1323,8 @@ static int RAWINPUT_JoystickOpen(SDL_Joystick *joystick, int device_index)
ctx->button_indices = (USHORT *)SDL_malloc(joystick->nbuttons * sizeof(*ctx->button_indices));
if (!ctx->button_indices) {
RAWINPUT_JoystickClose(joystick);
+ SDL_stack_free(value_caps);
+ SDL_stack_free(button_caps);
return -1;
}
@@ -1369,12 +1372,15 @@ static int RAWINPUT_JoystickOpen(SDL_Joystick *joystick, int device_index)
joystick->naxes += 1;
}
+ SDL_stack_free(button_caps);
+
if (joystick->naxes > 0) {
int axis_index = 0;
ctx->axis_indices = (USHORT *)SDL_malloc(joystick->naxes * sizeof(*ctx->axis_indices));
if (!ctx->axis_indices) {
RAWINPUT_JoystickClose(joystick);
+ SDL_stack_free(value_caps);
return -1;
}
@@ -1408,6 +1414,7 @@ static int RAWINPUT_JoystickOpen(SDL_Joystick *joystick, int device_index)
ctx->hat_indices = (USHORT *)SDL_malloc(joystick->nhats * sizeof(*ctx->hat_indices));
if (!ctx->hat_indices) {
RAWINPUT_JoystickClose(joystick);
+ SDL_stack_free(value_caps);
return -1;
}
@@ -1426,6 +1433,8 @@ static int RAWINPUT_JoystickOpen(SDL_Joystick *joystick, int device_index)
}
}
+ SDL_stack_free(value_caps);
+
#ifdef SDL_JOYSTICK_RAWINPUT_XINPUT
if (ctx->is_xinput) {
SDL_SetBooleanProperty(SDL_GetJoystickProperties(joystick), SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN, true);
For SDL2:
diff --git a/src/joystick/windows/SDL_rawinputjoystick.c b/src/joystick/windows/SDL_rawinputjoystick.c
index 2e10708..9f9d3f2 100644
--- a/src/joystick/windows/SDL_rawinputjoystick.c
+++ b/src/joystick/windows/SDL_rawinputjoystick.c
@@ -1290,6 +1290,7 @@ static int RAWINPUT_JoystickOpen(SDL_Joystick *joystick, int device_index)
value_caps = SDL_stack_alloc(HIDP_VALUE_CAPS, caps.NumberInputValueCaps);
if (SDL_HidP_GetValueCaps(HidP_Input, value_caps, &caps.NumberInputValueCaps, ctx->preparsed_data) != HIDP_STATUS_SUCCESS) {
RAWINPUT_JoystickClose(joystick);
+ SDL_stack_free(button_caps);
return SDL_SetError("Couldn't get device value capabilities");
}
@@ -1318,6 +1319,8 @@ static int RAWINPUT_JoystickOpen(SDL_Joystick *joystick, int device_index)
ctx->button_indices = (USHORT *)SDL_malloc(joystick->nbuttons * sizeof(*ctx->button_indices));
if (!ctx->button_indices) {
RAWINPUT_JoystickClose(joystick);
+ SDL_stack_free(value_caps);
+ SDL_stack_free(button_caps);
return SDL_OutOfMemory();
}
@@ -1365,12 +1368,15 @@ static int RAWINPUT_JoystickOpen(SDL_Joystick *joystick, int device_index)
joystick->naxes += 1;
}
+ SDL_stack_free(button_caps);
+
if (joystick->naxes > 0) {
int axis_index = 0;
ctx->axis_indices = (USHORT *)SDL_malloc(joystick->naxes * sizeof(*ctx->axis_indices));
if (!ctx->axis_indices) {
RAWINPUT_JoystickClose(joystick);
+ SDL_stack_free(value_caps);
return SDL_OutOfMemory();
}
@@ -1404,6 +1410,7 @@ static int RAWINPUT_JoystickOpen(SDL_Joystick *joystick, int device_index)
ctx->hat_indices = (USHORT *)SDL_malloc(joystick->nhats * sizeof(*ctx->hat_indices));
if (!ctx->hat_indices) {
RAWINPUT_JoystickClose(joystick);
+ SDL_stack_free(value_caps);
return SDL_OutOfMemory();
}
@@ -1422,6 +1429,8 @@ static int RAWINPUT_JoystickOpen(SDL_Joystick *joystick, int device_index)
}
}
+ SDL_stack_free(value_caps);
+
joystick->epowerlevel = SDL_JOYSTICK_POWER_UNKNOWN;
return 0;
from sdl.
This patch looks correct from here.
from sdl.
OK, patch applied to all active branches and pushed
from sdl.
Related Issues (20)
- SDL3: SDL_ConvertEventToRenderCoordinates doesn't work with SDL_AppEvent HOT 1
- GPU: Remove stride parameter from DrawPrimitivesIndirect HOT 1
- Linux: Gamesir-T1s and Logitech G29 Wheel are not detected HOT 6
- output from camera is black on LUbuntu HOT 5
- GPU: CreateGPUGraphicsPipeline fails with non-empty color attachment descriptions HOT 5
- GPU: Consider timeout parameter on AcquireSwapchainTexture/Wait/WaitForFences HOT 3
- GPU: Default struct initializer functions
- [GPU] MinGW build issues HOT 3
- testthread isn't thread-safe: non-locked access to global variable 'alive'
- change SDL_GPU_VULKAN to match the other preprocessor definitions HOT 1
- GPU: Prioritize Vulkan backend on Windows
- `GL.currentContext.tempVertexBufferCounters1 is undefined` when trying to use OpenGL ES in Emscripten with SDL3
- Remove UWP support HOT 14
- sdl_videodriver=wayland performance hit in full screen mode with current nvidia NFB drivers 560.35.03 if libdecor enabled HOT 4
- GPU: Compute Samplers? HOT 1
- GPU: Vulkan drawIndirectFirstInstance
- SDL_PRESSED and SDL_RELEASED as bool? (take 2) HOT 1
- WinRT readme was restored by the wiki bridge HOT 1
- Custom log categories ABI HOT 1
- Move gendynapi? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sdl.