Hacking WPAD_ButtonsHeld() bug: stuck button!? [with solution]

revvv

Well-Known Member
OP
Newcomer
Joined
May 11, 2019
Messages
73
Trophies
0
XP
391
Country
Germany
I'm new to Wii programming and @Mr_Reaper found an interesting bug in my games:

If you press very shortly a direction button, it happens that WPAD_ButtonsHeld() reports that the button is held forever.
This sounds like a newbie problem (which I am), but I have a test case. :evil:

@Mr_Reaper found out what I did wrong: I did not call WPAD_SetDataFormat().
It surprised me, that I saw so many examples without it. My conclusion is, that it works as long as you call WPAD_ButtonsHeld() very often.
My game logic consumes 44 millis, which is too long. I could also reproduce it with 20 millis.

And I also wonder if there are other games in the wild with this bug.
Without @Mr_Reaper I would probably think my WiiMote is dead or something. Thanks a lot!

Hopefully this will help other programmers... :yaywii:

Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <ogcsys.h>
#include <gccore.h>
#include <sys/time.h>
#include <sys/unistd.h>
#include <wiiuse/wpad.h>

static u32 *xfb;
static GXRModeObj *rmode;

void Initialise() {
    
    VIDEO_Init();
    WPAD_Init();
    // This line fixes the stuck button problem (by Mr_Reaper)
    //WPAD_SetDataFormat(WPAD_CHAN_ALL, WPAD_FMT_BTNS_ACC_IR);
    
    rmode = VIDEO_GetPreferredMode(NULL);
    
    xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
    console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);
    
    VIDEO_Configure(rmode);
    VIDEO_SetNextFramebuffer(xfb);
    VIDEO_SetBlack(FALSE);
    VIDEO_Flush();
    VIDEO_WaitVSync();
    if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();
}

int main() {
    Initialise();

    printf("\n\nTest stuck button...\n\n");
    printf("Press a direction button on your Wiimote for a very short moment...\n");
    printf("And held is fired forever...\n\n");
    while (true)
    {
        WPAD_ScanPads();
        u16 buttonsDown = WPAD_ButtonsDown(0);
        u16 buttonsHeld = WPAD_ButtonsHeld(0);
        u16 buttonsUp = WPAD_ButtonsUp(0);

        printf("down=%04d held=%04d up=%04d\r", buttonsDown, buttonsHeld, buttonsUp);

        // reproducible with 44 millis
        usleep(1000 * 44);

        if (buttonsDown & WPAD_BUTTON_HOME)
        {
            exit(0);
        }
    }

    return 0;
}

You can find my games here:
VVVV4K
MEG4kMAN
 

revvv

Well-Known Member
OP
Newcomer
Joined
May 11, 2019
Messages
73
Trophies
0
XP
391
Country
Germany
@Mr_Reaper told me
Just to be accurate, WPAD_SetDataFormat() takes the following parameters depending on what you want to read from the wiimote:

WPAD_FMT_BTNS
WPAD_FMT_BTNS_ACC
WPAD_FMT_BTNS_ACC_IR

If you only wanted to read the buttons, you should only need to use WPAD_FMT_BTNS, except then you still get the bug!

I tried and the bug is still there...

I guess the default format (used when you don't specify another one by calling the function) behaves similarly (bugged).

You have to use the full parameter WPAD_FMT_BTNS_ACC_IR to prevent the bug.

Actually I didn't try the middle parameter, WPAD_FMT_BTNS_ACC

So I don't know if the bug shows up when you use that one.

I am guessing that when you're reading the full information from the Wiimote, it polls for information more often so it never gets stuck in an improper state without noticing the state changed.

(You might wanna add this info to your post.)
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • SylverReZ @ SylverReZ:
    @AcuteBulbasaurappears, A cute bulbasaur appears. :D
    +2
  • SylverReZ @ SylverReZ:
    @Psionic Roshambo, The Wii U gamepads are tied to the console's region, so its impossible to find a cheap gamepad that supports your model.
  • SylverReZ @ SylverReZ:
    Unless you modify your system, of course, and remove the region check.
  • Xdqwerty @ Xdqwerty:
    @SylverReZ, im now by episode 8 of lain
  • S @ salazarcosplay:
    @Xdqwerty can we discuss chrono trigger
  • S @ salazarcosplay:
    @Xdqwerty I like how the game had the middle ages 1000AD, the dark ages 600AD.It was great seeing the post robot apocalypse 2300 like Terminator and enter the matrix. some of mad max and fallout. 2300ad though it could had used more elements instead of just a generic ai uprising. It was a great idea for their judgement day to be 1999 Y2K.

    -great additions if they would have made an expansion or dlc in my opinion would be finding out humans trapped in a matrix -

    a follower having a cyborg character living tissue over metal endoskelleton like terminator, and the synths from fallout
  • S @ salazarcosplay:
    4After Zeal fell it would have been good to see more ancient eras. Perhaps Sumeria based in one area, then Egypt based in another area, Greek based in another area, then roman based in another area before the middle ages.---------

    ----between 1000ad and 1999 is a big gap they should have had the age of revolution like the american and French Revolution

    then the cowboyy era in one area of map and the Industrial revolution/age of enlightmentthen a ww1 and ww2 and a cold war era
  • S @ salazarcosplay:
    they could have added 75,000 bc like assassins creed. zeal was already establish in 12, 000 bc , soething before the kindom rose
  • S @ salazarcosplay:
    @Xdqwerty they could also add age of dscover, colonialism ect
    +1
  • S @ salazarcosplay:
    renaissance
  • S @ salazarcosplay:
    @Xdqwerty what did you think
  • S @ salazarcosplay:
    @Xdqwerty I think glenn (the frog) after becomming human had an affair with the queen
  • S @ salazarcosplay:
    so he is the great great great great grandfather of marle @Xdqwerty
  • S @ salazarcosplay:
    they made it like Lancelot from king arthur legends
  • BakerMan @ BakerMan:
    just found out i'm now taller than my dad
  • Xdqwerty @ Xdqwerty:
    @salazarcosplay, sorry i was busy
  • S @ salazarcosplay:
    @Xdqwerty thats completely fine
    +1
  • Xdqwerty @ Xdqwerty:
    @salazarcosplay,
    the ds version added a secret boss reference to chrono cross
  • S @ salazarcosplay:
    @Xdqwerty did you finish watching naruto shippuden and Boruto
  • Xdqwerty @ Xdqwerty:
    @salazarcosplay, i havent even started lol
  • Xdqwerty @ Xdqwerty:
    anyone here?
  • K3Nv2 @ K3Nv2:
    Yawn
    K3Nv2 @ K3Nv2: Yawn