Page 1 of 1

Crash on u32 binary comparison

Posted: Tue Nov 11, 2008 6:31 pm
by lnuxguy
I've got an SDL-based game (WiiDoom), and in the startup routines, I'm watching for button presses. The following code works:

Code: Select all

while(true)
{
  WPAD_ScanPads();
  u32 wpaddown = WPAD_ButtonsDown(0);
  if (wpaddown & WPAD_BUTTON_B) exit(0);
  if (wpaddown & WPAD_BUTTON_1) done = true;
}
No problems whatsoever. If I add a check for most other buttons (I haven't tried them all), the game crashes. For instance:

Code: Select all

if (wpaddown & WPAD_BUTTON_LEFT) x = 1;
will crash the game. Every time. I can try other buttons, or move the statement to different parts of the routine, and still crashes. If I take it back out, it works.

Ideas???

Re: Crash on u32 binary comparison

Posted: Tue Nov 11, 2008 8:27 pm
by Samson
Interesting. Is it possible that not the test itself is the problem, but that the extra code moves some data or other stuff to trigger a crash? Does it crash on that instruction? Did you have a look at the assembler output, if the compiler does anything weird? Did you try without optimisations?

Re: Crash on u32 binary comparison

Posted: Tue Nov 11, 2008 9:04 pm
by lnuxguy
I does seem to crash on that instruction. I've had a simple printf() and sleep() in the codeblock, and it still crashes without any screen output or sleep delay.

Re: Crash on u32 binary comparison

Posted: Wed Nov 12, 2008 1:23 am
by lnuxguy
Nevermind, I found the error:

After running the debugger (offline) on the elf and finding the function call that was crashing, it was an unrelated section of code. The weird thing is that the code that was causing the crash has been in place for a few weeks! It only started to show up once I did another button press test?

Very weird, but I'm a firm believer in that crash dump analysis. Here's a link to anyone who experiences what I just did:

http://wiibrew.org/wiki/Debugging