mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-02-08 13:43:33 +01:00
Fix OS X code.
- Close the connection properly on destruction. - Work around what seems like an Apple bug.
This commit is contained in:
parent
872e9ce3da
commit
dc87b6d431
@ -140,10 +140,11 @@ void WiimoteScanner::FindWiimotes(std::vector<Wiimote*> & found_wiimotes, Wiimot
|
|||||||
[bti setDelegate: sbt];
|
[bti setDelegate: sbt];
|
||||||
[bti setInquiryLength: 2];
|
[bti setInquiryLength: 2];
|
||||||
|
|
||||||
if ([bti start] == kIOReturnSuccess)
|
if ([bti start] != kIOReturnSuccess)
|
||||||
[bti retain];
|
{
|
||||||
else
|
|
||||||
ERROR_LOG(WIIMOTE, "Unable to do bluetooth discovery");
|
ERROR_LOG(WIIMOTE, "Unable to do bluetooth discovery");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
@ -164,7 +165,7 @@ void WiimoteScanner::FindWiimotes(std::vector<Wiimote*> & found_wiimotes, Wiimot
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
Wiimote *wm = new Wiimote();
|
Wiimote *wm = new Wiimote();
|
||||||
wm->btd = dev;
|
wm->btd = [dev retain];
|
||||||
|
|
||||||
if(IsBalanceBoardName([[dev name] UTF8String]))
|
if(IsBalanceBoardName([[dev name] UTF8String]))
|
||||||
{
|
{
|
||||||
@ -195,17 +196,27 @@ bool Wiimote::ConnectInternal()
|
|||||||
|
|
||||||
ConnectBT *cbt = [[ConnectBT alloc] init];
|
ConnectBT *cbt = [[ConnectBT alloc] init];
|
||||||
|
|
||||||
|
cchan = ichan = nil;
|
||||||
|
|
||||||
[btd openL2CAPChannelSync: &cchan
|
[btd openL2CAPChannelSync: &cchan
|
||||||
withPSM: kBluetoothL2CAPPSMHIDControl delegate: cbt];
|
withPSM: kBluetoothL2CAPPSMHIDControl delegate: cbt];
|
||||||
[btd openL2CAPChannelSync: &ichan
|
[btd openL2CAPChannelSync: &ichan
|
||||||
withPSM: kBluetoothL2CAPPSMHIDInterrupt delegate: cbt];
|
withPSM: kBluetoothL2CAPPSMHIDInterrupt delegate: cbt];
|
||||||
if (ichan == NULL || cchan == NULL)
|
// Apple docs claim:
|
||||||
|
// "The L2CAP channel object is already retained when this function returns
|
||||||
|
// success; the channel must be released when the caller is done with it."
|
||||||
|
// But without this, the channels get over-autoreleased, even though the
|
||||||
|
// refcounting behavior here is clearly correct.
|
||||||
|
[ichan retain];
|
||||||
|
[cchan retain];
|
||||||
|
if (ichan == nil || cchan == nil)
|
||||||
{
|
{
|
||||||
ERROR_LOG(WIIMOTE, "Unable to open L2CAP channels "
|
ERROR_LOG(WIIMOTE, "Unable to open L2CAP channels "
|
||||||
"for wiimote %i", index + 1);
|
"for wiimote %i", index + 1);
|
||||||
DisconnectInternal();
|
DisconnectInternal();
|
||||||
|
|
||||||
[cbt release];
|
[cbt release];
|
||||||
|
[ichan release];
|
||||||
|
[cchan release];
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,19 +232,18 @@ bool Wiimote::ConnectInternal()
|
|||||||
// Disconnect a wiimote.
|
// Disconnect a wiimote.
|
||||||
void Wiimote::DisconnectInternal()
|
void Wiimote::DisconnectInternal()
|
||||||
{
|
{
|
||||||
if (ichan != NULL)
|
[ichan closeChannel];
|
||||||
[ichan release];
|
[ichan release];
|
||||||
|
|
||||||
if (cchan != NULL)
|
|
||||||
[cchan release];
|
|
||||||
|
|
||||||
if (btd != NULL)
|
|
||||||
[btd closeConnection];
|
|
||||||
|
|
||||||
btd = NULL;
|
|
||||||
cchan = NULL;
|
|
||||||
ichan = NULL;
|
ichan = NULL;
|
||||||
|
|
||||||
|
[cchan closeChannel];
|
||||||
|
[cchan release];
|
||||||
|
cchan = NULL;
|
||||||
|
|
||||||
|
[btd closeConnection];
|
||||||
|
[btd release];
|
||||||
|
btd = NULL;
|
||||||
|
|
||||||
if (!IsConnected())
|
if (!IsConnected())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user