Skip to content

Conversation

@Zarithya
Copy link
Contributor

Wiimotes were not being cleared from the active bitmask and were taking their own slots if WPAD was shutdown and reinit in the same app. This clears the active and used bitmasks, ensuring those slots are properly marked as not in use upon shutdown, and also adds in a check to ensure that the owner of a slot can always get it back.

@DacoTaco DacoTaco changed the title Clear used wiimotes wiimote: Clear used wiimotes on shutdown Aug 12, 2025
@DacoTaco DacoTaco merged commit 24c137d into devkitPro:master Aug 12, 2025
1 check passed
@fincs
Copy link
Member

fincs commented Aug 12, 2025

@Zarithya Somewhere within your last three merged PRs there seems to be a regression. Wii applications (I've tested the application template) crash on startup within the wiiuse code; it seems to be a NULL pointer issue. The stack trace goes something like this: memcpy -> wiiuse_sendcmd -> l2cap_accepted -> l2cap_process_sig -> l2cap_input -> SYS_SwitchFiber -> __readbulkdataCB -> __usbv0_messageCB -> __ipc_interrupthandler. Could you look at this please?

@DacoTaco
Copy link
Member

DacoTaco commented Aug 12, 2025

@Zarithya Somewhere within your last three merged PRs there seems to be a regression. Wii applications (I've tested the application template) crash on startup within the wiiuse code; it seems to be a NULL pointer issue. The stack trace goes something like this: memcpy -> wiiuse_sendcmd -> l2cap_accepted -> l2cap_process_sig -> l2cap_input -> SYS_SwitchFiber -> __readbulkdataCB -> __usbv0_messageCB -> __ipc_interrupthandler. Could you look at this please?

to be investigated first, because my builds work fine on my wii and dolphin...
which resulted in following elf's

wiimote.zip

@fincs
Copy link
Member

fincs commented Aug 12, 2025

False alarm, sorry for the inconvenience. The problem is entirely in my machine.

@Zarithya
Copy link
Contributor Author

False alarm, sorry for the inconvenience. The problem is entirely in my machine.

Actually, I was getting similar issues with devkitPPC r47 - downgrading to r46 fixed it.
There was another similar bug that was seemingly "caused" by r47 that was actually undefined behavior in libogc that had been there for years which only cropped up with r47, and I have a strong suspicion this will be the same.

@fincs
Copy link
Member

fincs commented Aug 12, 2025

Turns out the addition of ca84f9d#diff-e1a91d721b2cdc2e35fd08cb1c80abc9890b0deeeca11b7b1d76d8826b4895f1R46 caused WPAD_MAX_DEVICES to become 6. MAX_WIIMOTES is 5 ( https://github.com/devkitPro/libogc/blob/master/wiiuse/io_wii.c#L16 ), which causes a heap buffer overrun when wiiuse_init initializes the 6th wiimote. By pure chance the linker placed the global __wm pointer right after __queue_buffer, which caused this 6th wiimote to corrupt the list of pointers to wiimote structures.

It looks like WPAD_CHAN_UNKNOWN isn't used at all anywhere, so it should be removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants