fix crash when switching to real wiimote with "connect real wiimote" already enabled.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4767 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Shawn Hoffman 2010-01-01 02:19:19 +00:00
parent 195f734054
commit eb16c51d5f
1 changed files with 16 additions and 19 deletions

View File

@ -271,6 +271,7 @@ void SendAcc(u8 _ReportID)
void ClearEvents() void ClearEvents()
{ {
for (int i = 0; i < g_NumberOfWiiMotes; i++) for (int i = 0; i < g_NumberOfWiiMotes; i++)
if (g_WiimoteInUse[i])
g_WiiMotes[i]->ClearEvents(); g_WiiMotes[i]->ClearEvents();
} }
@ -296,7 +297,7 @@ void FlashLights(bool Connect)
} }
} }
int Initialize() int Initialize() // None of this code is intelligible, oh well...
{ {
// Return if already initialized // Return if already initialized
if (g_RealWiiMoteInitialized) if (g_RealWiiMoteInitialized)
@ -362,20 +363,13 @@ int Initialize()
FlashLights(true); FlashLights(true);
// Create Wiimote classes // Create Wiimote classes
int current_number = 0; for (int i = 0; i < g_NumberOfWiiMotes; i++)
for (int i = 0; i < g_NumberOfWiiMotes; i++) {
// Determine the number of the current WiiMote
for (; current_number < MAX_WIIMOTES; current_number++)
{ {
if (g_WiimoteInUse[current_number] == true) // Why the fuck are there 2 values for "real wiimote"??? NOBODY KNOWS
continue; if ((WiiMoteEmu::WiiMapping[i].Source == -1) || (WiiMoteEmu::WiiMapping[i].Source == 2))
if (WiiMoteEmu::WiiMapping[current_number].Source < 0) {
break; g_WiimoteInUse[i] = true;
} switch (i)
g_WiiMotes[current_number] = new CWiiMote(current_number, g_WiiMotesFromWiiUse[i]);
g_WiimoteInUse[current_number] = true;
switch (current_number)
{ {
case 0: case 0:
wiiuse_set_leds(g_WiiMotesFromWiiUse[i], WIIMOTE_LED_1); wiiuse_set_leds(g_WiiMotesFromWiiUse[i], WIIMOTE_LED_1);
@ -387,11 +381,14 @@ int Initialize()
wiiuse_set_leds(g_WiiMotesFromWiiUse[i], WIIMOTE_LED_3); wiiuse_set_leds(g_WiiMotesFromWiiUse[i], WIIMOTE_LED_3);
break; break;
case 3: case 3:
wiiuse_set_leds(g_WiiMotesFromWiiUse[i], WIIMOTE_LED_4);
break;
default: default:
wiiuse_set_leds(g_WiiMotesFromWiiUse[i], WIIMOTE_LED_NONE); PanicAlert("Trying to create real wiimote %i WTF", i);
break; break;
} }
DEBUG_LOG(WIIMOTE, "Real WiiMote allocated as WiiMote #%i", current_number); g_WiiMotes[i] = new CWiiMote(i, g_WiiMotesFromWiiUse[i]);
}
} }
// Create a new thread and start listening for Wiimote data // Create a new thread and start listening for Wiimote data