13
114
Fork
You've already forked zig-sdl3
19

Gamepad subsystem crash #167

Closed
opened 2026年02月04日 19:24:23 +01:00 by e820 · 2 comments

Frankly I'm not sure if this is the right place to file this issue but considering I can't reproduce it in C I'll put it here for now.

constsubsystems:sdl.InitFlags=.{.video=true,.gamepad=true};trysdl.init(subsystems);

Trying to initialize the gamepad subsystem dies with the following backtrace:

Illegal instruction at address 0x146dbd6
/home/lauree/.cache/zig/p/sdl-0.4.0+3.4.0-SDL--u6yowGyvoiJ5qkFm_T1-MpmvnHShh2q2mTZf1fo/src/hidapi/SDL_hidapi.c:1514:12: 0x146dbd6 in SDL_hid_set_nonblocking_REAL (/home/lauree/.cache/zig/p/sdl-0.4.0+3.4.0-SDL--u6yowGyvoiJ5qkFm_T1-MpmvnHShh2q2mTZf1fo/src/hidapi/SDL_hidapi.c)
 return device->backend->hid_set_nonblocking(device->device, nonblock);
 ^
/home/lauree/.cache/zig/p/sdl-0.4.0+3.4.0-SDL--u6yowGyvoiJ5qkFm_T1-MpmvnHShh2q2mTZf1fo/src/joystick/hidapi/SDL_hidapijoystick.c:501:13: 0x1e26c11 in HIDAPI_SetupDeviceDriver (/home/lauree/.cache/zig/p/sdl-0.4.0+3.4.0-SDL--u6yowGyvoiJ5qkFm_T1-MpmvnHShh2q2mTZf1fo/src/joystick/hidapi/SDL_hidapijoystick.c)
 SDL_hid_set_nonblocking(dev, 1);
 ^
/home/lauree/.cache/zig/p/sdl-0.4.0+3.4.0-SDL--u6yowGyvoiJ5qkFm_T1-MpmvnHShh2q2mTZf1fo/src/joystick/hidapi/SDL_hidapijoystick.c:970:5: 0x1e23ef6 in HIDAPI_AddDevice (/home/lauree/.cache/zig/p/sdl-0.4.0+3.4.0-SDL--u6yowGyvoiJ5qkFm_T1-MpmvnHShh2q2mTZf1fo/src/joystick/hidapi/SDL_hidapijoystick.c)
 HIDAPI_SetupDeviceDriver(device, &removed);
 ^
/home/lauree/.cache/zig/p/sdl-0.4.0+3.4.0-SDL--u6yowGyvoiJ5qkFm_T1-MpmvnHShh2q2mTZf1fo/src/joystick/hidapi/SDL_hidapijoystick.c:1145:21: 0x1e1e406 in HIDAPI_UpdateDeviceList (/home/lauree/.cache/zig/p/sdl-0.4.0+3.4.0-SDL--u6yowGyvoiJ5qkFm_T1-MpmvnHShh2q2mTZf1fo/src/joystick/hidapi/SDL_hidapijoystick.c)
 HIDAPI_AddDevice(info, 0, NULL);
 ^
/home/lauree/.cache/zig/p/sdl-0.4.0+3.4.0-SDL--u6yowGyvoiJ5qkFm_T1-MpmvnHShh2q2mTZf1fo/src/joystick/hidapi/SDL_hidapijoystick.c:580:5: 0x1e1dff0 in HIDAPI_JoystickInit (/home/lauree/.cache/zig/p/sdl-0.4.0+3.4.0-SDL--u6yowGyvoiJ5qkFm_T1-MpmvnHShh2q2mTZf1fo/src/joystick/hidapi/SDL_hidapijoystick.c)
 HIDAPI_UpdateDeviceList();
 ^
/home/lauree/.cache/zig/p/sdl-0.4.0+3.4.0-SDL--u6yowGyvoiJ5qkFm_T1-MpmvnHShh2q2mTZf1fo/src/joystick/SDL_joystick.c:860:13: 0x14a46e7 in SDL_InitJoysticks (/home/lauree/.cache/zig/p/sdl-0.4.0+3.4.0-SDL--u6yowGyvoiJ5qkFm_T1-MpmvnHShh2q2mTZf1fo/src/joystick/SDL_joystick.c)
 if (SDL_joystick_drivers[i]->Init()) {
 ^
/home/lauree/.cache/zig/p/sdl-0.4.0+3.4.0-SDL--u6yowGyvoiJ5qkFm_T1-MpmvnHShh2q2mTZf1fo/src/SDL.c:435:18: 0x130f0b0 in SDL_InitSubSystem_REAL (/home/lauree/.cache/zig/p/sdl-0.4.0+3.4.0-SDL--u6yowGyvoiJ5qkFm_T1-MpmvnHShh2q2mTZf1fo/src/SDL.c)
 if (!SDL_InitJoysticks()) {
 ^
/home/lauree/.cache/zig/p/sdl-0.4.0+3.4.0-SDL--u6yowGyvoiJ5qkFm_T1-MpmvnHShh2q2mTZf1fo/src/SDL.c:256:12: 0x130faca in SDL_InitOrIncrementSubsystem (/home/lauree/.cache/zig/p/sdl-0.4.0+3.4.0-SDL--u6yowGyvoiJ5qkFm_T1-MpmvnHShh2q2mTZf1fo/src/SDL.c)
 return SDL_InitSubSystem(subsystem);
 ^
/home/lauree/.cache/zig/p/sdl-0.4.0+3.4.0-SDL--u6yowGyvoiJ5qkFm_T1-MpmvnHShh2q2mTZf1fo/src/SDL.c:456:18: 0x130f144 in SDL_InitSubSystem_REAL (/home/lauree/.cache/zig/p/sdl-0.4.0+3.4.0-SDL--u6yowGyvoiJ5qkFm_T1-MpmvnHShh2q2mTZf1fo/src/SDL.c)
 if (!SDL_InitOrIncrementSubsystem(SDL_INIT_JOYSTICK)) {
 ^
/home/lauree/.cache/zig/p/sdl-0.4.0+3.4.0-SDL--u6yowGyvoiJ5qkFm_T1-MpmvnHShh2q2mTZf1fo/src/SDL.c:558:12: 0x130fcca in SDL_Init_REAL (/home/lauree/.cache/zig/p/sdl-0.4.0+3.4.0-SDL--u6yowGyvoiJ5qkFm_T1-MpmvnHShh2q2mTZf1fo/src/SDL.c)
 return SDL_InitSubSystem(flags);
 ^
/home/lauree/.cache/zig/p/sdl-0.4.0+3.4.0-SDL--u6yowGyvoiJ5qkFm_T1-MpmvnHShh2q2mTZf1fo/src/dynapi/SDL_dynapi_procs.h:638:1: 0x13db024 in SDL_Init_DEFAULT (/home/lauree/.cache/zig/p/sdl-0.4.0+3.4.0-SDL--u6yowGyvoiJ5qkFm_T1-MpmvnHShh2q2mTZf1fo/src/dynapi/SDL_dynapi.c)
SDL_DYNAPI_PROC(bool,SDL_Init,(SDL_InitFlags a),(a),return)
^
/home/lauree/.cache/zig/p/sdl-0.4.0+3.4.0-SDL--u6yowGyvoiJ5qkFm_T1-MpmvnHShh2q2mTZf1fo/src/dynapi/SDL_dynapi_procs.h:638:1: 0x13a5a2f in SDL_Init (/home/lauree/.cache/zig/p/sdl-0.4.0+3.4.0-SDL--u6yowGyvoiJ5qkFm_T1-MpmvnHShh2q2mTZf1fo/src/dynapi/SDL_dynapi.c)
SDL_DYNAPI_PROC(bool,SDL_Init,(SDL_InitFlags a),(a),return)
^
/home/lauree/.cache/zig/p/sdl3-0.1.7-NmT1Q00HJwBQEXnwv_YWydIXUCKazlnPDACaXwwVQoHo/src/sdl3.zig:1111:27: 0x12d4a5e in init (sdl3.zig)
 const ret = c.SDL_Init(
 ^
/home/lauree/dev/test/src/main.zig:11:17: 0x12d63bb in main (main.zig)
 try sdl.init(subsystems);
 ^
/usr/lib/zig/std/start.zig:627:37: 0x12d6fd1 in main (std.zig)
 const result = root.main() catch |err| {
 ^
???:?:?: 0x7f6f182ad634 in ??? (libc.so.6)
Unwind information for `libc.so.6:0x7f6f182ad634` was not available, trace may be incomplete
???:?:?: 0x7f6f182ad6e8 in ??? (libc.so.6)
???:?:?: 0x130e8d4 in ??? (???)

On one hand it very much looks like it's an issue with SDL, or at least my SDL installation, but as mentioned above it works just fine when using C so I wonder if anyone has any ideas.

Frankly I'm not sure if this is the right place to file this issue but considering I can't reproduce it in C I'll put it here for now. ```zig const subsystems: sdl.InitFlags = .{ .video = true, .gamepad = true }; try sdl.init(subsystems); ``` Trying to initialize the gamepad subsystem dies with the following backtrace: ``` Illegal instruction at address 0x146dbd6 /home/lauree/.cache/zig/p/sdl-0.4.0+3.4.0-SDL--u6yowGyvoiJ5qkFm_T1-MpmvnHShh2q2mTZf1fo/src/hidapi/SDL_hidapi.c:1514:12: 0x146dbd6 in SDL_hid_set_nonblocking_REAL (/home/lauree/.cache/zig/p/sdl-0.4.0+3.4.0-SDL--u6yowGyvoiJ5qkFm_T1-MpmvnHShh2q2mTZf1fo/src/hidapi/SDL_hidapi.c) return device->backend->hid_set_nonblocking(device->device, nonblock); ^ /home/lauree/.cache/zig/p/sdl-0.4.0+3.4.0-SDL--u6yowGyvoiJ5qkFm_T1-MpmvnHShh2q2mTZf1fo/src/joystick/hidapi/SDL_hidapijoystick.c:501:13: 0x1e26c11 in HIDAPI_SetupDeviceDriver (/home/lauree/.cache/zig/p/sdl-0.4.0+3.4.0-SDL--u6yowGyvoiJ5qkFm_T1-MpmvnHShh2q2mTZf1fo/src/joystick/hidapi/SDL_hidapijoystick.c) SDL_hid_set_nonblocking(dev, 1); ^ /home/lauree/.cache/zig/p/sdl-0.4.0+3.4.0-SDL--u6yowGyvoiJ5qkFm_T1-MpmvnHShh2q2mTZf1fo/src/joystick/hidapi/SDL_hidapijoystick.c:970:5: 0x1e23ef6 in HIDAPI_AddDevice (/home/lauree/.cache/zig/p/sdl-0.4.0+3.4.0-SDL--u6yowGyvoiJ5qkFm_T1-MpmvnHShh2q2mTZf1fo/src/joystick/hidapi/SDL_hidapijoystick.c) HIDAPI_SetupDeviceDriver(device, &removed); ^ /home/lauree/.cache/zig/p/sdl-0.4.0+3.4.0-SDL--u6yowGyvoiJ5qkFm_T1-MpmvnHShh2q2mTZf1fo/src/joystick/hidapi/SDL_hidapijoystick.c:1145:21: 0x1e1e406 in HIDAPI_UpdateDeviceList (/home/lauree/.cache/zig/p/sdl-0.4.0+3.4.0-SDL--u6yowGyvoiJ5qkFm_T1-MpmvnHShh2q2mTZf1fo/src/joystick/hidapi/SDL_hidapijoystick.c) HIDAPI_AddDevice(info, 0, NULL); ^ /home/lauree/.cache/zig/p/sdl-0.4.0+3.4.0-SDL--u6yowGyvoiJ5qkFm_T1-MpmvnHShh2q2mTZf1fo/src/joystick/hidapi/SDL_hidapijoystick.c:580:5: 0x1e1dff0 in HIDAPI_JoystickInit (/home/lauree/.cache/zig/p/sdl-0.4.0+3.4.0-SDL--u6yowGyvoiJ5qkFm_T1-MpmvnHShh2q2mTZf1fo/src/joystick/hidapi/SDL_hidapijoystick.c) HIDAPI_UpdateDeviceList(); ^ /home/lauree/.cache/zig/p/sdl-0.4.0+3.4.0-SDL--u6yowGyvoiJ5qkFm_T1-MpmvnHShh2q2mTZf1fo/src/joystick/SDL_joystick.c:860:13: 0x14a46e7 in SDL_InitJoysticks (/home/lauree/.cache/zig/p/sdl-0.4.0+3.4.0-SDL--u6yowGyvoiJ5qkFm_T1-MpmvnHShh2q2mTZf1fo/src/joystick/SDL_joystick.c) if (SDL_joystick_drivers[i]->Init()) { ^ /home/lauree/.cache/zig/p/sdl-0.4.0+3.4.0-SDL--u6yowGyvoiJ5qkFm_T1-MpmvnHShh2q2mTZf1fo/src/SDL.c:435:18: 0x130f0b0 in SDL_InitSubSystem_REAL (/home/lauree/.cache/zig/p/sdl-0.4.0+3.4.0-SDL--u6yowGyvoiJ5qkFm_T1-MpmvnHShh2q2mTZf1fo/src/SDL.c) if (!SDL_InitJoysticks()) { ^ /home/lauree/.cache/zig/p/sdl-0.4.0+3.4.0-SDL--u6yowGyvoiJ5qkFm_T1-MpmvnHShh2q2mTZf1fo/src/SDL.c:256:12: 0x130faca in SDL_InitOrIncrementSubsystem (/home/lauree/.cache/zig/p/sdl-0.4.0+3.4.0-SDL--u6yowGyvoiJ5qkFm_T1-MpmvnHShh2q2mTZf1fo/src/SDL.c) return SDL_InitSubSystem(subsystem); ^ /home/lauree/.cache/zig/p/sdl-0.4.0+3.4.0-SDL--u6yowGyvoiJ5qkFm_T1-MpmvnHShh2q2mTZf1fo/src/SDL.c:456:18: 0x130f144 in SDL_InitSubSystem_REAL (/home/lauree/.cache/zig/p/sdl-0.4.0+3.4.0-SDL--u6yowGyvoiJ5qkFm_T1-MpmvnHShh2q2mTZf1fo/src/SDL.c) if (!SDL_InitOrIncrementSubsystem(SDL_INIT_JOYSTICK)) { ^ /home/lauree/.cache/zig/p/sdl-0.4.0+3.4.0-SDL--u6yowGyvoiJ5qkFm_T1-MpmvnHShh2q2mTZf1fo/src/SDL.c:558:12: 0x130fcca in SDL_Init_REAL (/home/lauree/.cache/zig/p/sdl-0.4.0+3.4.0-SDL--u6yowGyvoiJ5qkFm_T1-MpmvnHShh2q2mTZf1fo/src/SDL.c) return SDL_InitSubSystem(flags); ^ /home/lauree/.cache/zig/p/sdl-0.4.0+3.4.0-SDL--u6yowGyvoiJ5qkFm_T1-MpmvnHShh2q2mTZf1fo/src/dynapi/SDL_dynapi_procs.h:638:1: 0x13db024 in SDL_Init_DEFAULT (/home/lauree/.cache/zig/p/sdl-0.4.0+3.4.0-SDL--u6yowGyvoiJ5qkFm_T1-MpmvnHShh2q2mTZf1fo/src/dynapi/SDL_dynapi.c) SDL_DYNAPI_PROC(bool,SDL_Init,(SDL_InitFlags a),(a),return) ^ /home/lauree/.cache/zig/p/sdl-0.4.0+3.4.0-SDL--u6yowGyvoiJ5qkFm_T1-MpmvnHShh2q2mTZf1fo/src/dynapi/SDL_dynapi_procs.h:638:1: 0x13a5a2f in SDL_Init (/home/lauree/.cache/zig/p/sdl-0.4.0+3.4.0-SDL--u6yowGyvoiJ5qkFm_T1-MpmvnHShh2q2mTZf1fo/src/dynapi/SDL_dynapi.c) SDL_DYNAPI_PROC(bool,SDL_Init,(SDL_InitFlags a),(a),return) ^ /home/lauree/.cache/zig/p/sdl3-0.1.7-NmT1Q00HJwBQEXnwv_YWydIXUCKazlnPDACaXwwVQoHo/src/sdl3.zig:1111:27: 0x12d4a5e in init (sdl3.zig) const ret = c.SDL_Init( ^ /home/lauree/dev/test/src/main.zig:11:17: 0x12d63bb in main (main.zig) try sdl.init(subsystems); ^ /usr/lib/zig/std/start.zig:627:37: 0x12d6fd1 in main (std.zig) const result = root.main() catch |err| { ^ ???:?:?: 0x7f6f182ad634 in ??? (libc.so.6) Unwind information for `libc.so.6:0x7f6f182ad634` was not available, trace may be incomplete ???:?:?: 0x7f6f182ad6e8 in ??? (libc.so.6) ???:?:?: 0x130e8d4 in ??? (???) ``` On one hand it very much looks like it's an issue with `SDL`, or at least my `SDL` installation, but as mentioned above it works just fine when using C so I wonder if anyone has any ideas.
Owner
Copy link

What if you try running the C version with the -ftrapv and -fsanitize=undefined compiler flags? Also, looking at the release notes this might be fixed by 3.4.2? https://github.com/libsdl-org/SDL/releases/tag/release-3.4.2 (Castholm's repo is currently at 3.4.0). If it does not trap in 3.4.0 I'm not sure what the problem is. If it traps in 3.4.0 but not in 3.4.2 it's just waiting for the SDL3 version to be updated. If it traps in both then it's nothing I can do.

What if you try running the C version with the `-ftrapv` and `-fsanitize=undefined` compiler flags? Also, looking at the release notes this might be fixed by 3.4.2? https://github.com/libsdl-org/SDL/releases/tag/release-3.4.2 (Castholm's repo is currently at 3.4.0). If it does not trap in 3.4.0 I'm not sure what the problem is. If it traps in 3.4.0 but not in 3.4.2 it's just waiting for the SDL3 version to be updated. If it traps in both then it's nothing I can do.
Gota7 added this to the Jupiter project 2026年03月04日 06:26:39 +01:00

hi,
I believe this issue has been fixed in SDL and will be in the 3.4.12 release. Specifically by this commit.

Castholm's repo doesn't have it yet, as this PR was merged yesterday.

For more information: this happens in Zig and not (so easily) in C because Zig's default UBSan is more extensive (in terms of the flags it enables by default). The error is reproducible in C with the proper compilation flags as shown in this issue.

hi, I believe this issue has been fixed in SDL and will be in the 3.4.12 release. Specifically by [this commit](https://github.com/libsdl-org/SDL/commit/46d0ecead0f98c0987e86bb01a028f11bc7e5e77). Castholm's repo doesn't have it yet, as this PR was merged yesterday. For more information: this happens in Zig and not (so easily) in C because Zig's default UBSan is more extensive (in terms of the flags it enables by default). The error is reproducible in C with the proper compilation flags as shown in [this issue](https://github.com/libsdl-org/SDL/issues/15821).
Gota7 2026年06月14日 20:24:58 +02:00
Sign in to join this conversation.
No Branch/Tag specified
master
master-gpu
docs
image-updates
net-cleanup
vulkan-template
shadercross
better-documentation-and-examples
145-web-ci
yaml-rework
v0.2.2
v0.2.1
v0.2.0
v0.1.9
v0.1.8
v0.1.7
v0.1.6
v0.1.5
v0.1.4
v0.1.3
v0.1.2
v0.1.1
v0.1.0
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
7Games/zig-sdl3#167
Reference in a new issue
7Games/zig-sdl3
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?