EXE_BAD_BADACCESS 正在尝试访问 GKMatch?
EXE_BAD_BADACCESS trying to access GKMatch?
问题简述
尝试使用 gamecenter 与朋友实时玩游戏导致游戏崩溃
项目详情
- 我正在使用 gamecenter 和 cocos2dx
- 我正在使用 SANDBOX 模式:正在测试的两个帐户都处于沙盒模式
- 2台Ipad用于测试(IOS 8.3)
- 我正在使用 GKMatchMaker 来匹配玩家
- 与 'Random' 又名 'Play Now' 的实时匹配没有问题
- 实时匹配 'Invite a Friend' 匹配成功但在访问 GKMatch 对象后崩溃
- 当我使用可靠或不可靠的方法发送数据时发生崩溃(仅在邀请时)
我的调查
- 在比赛期间访问 GKMatch 会创建 EXC_BAD_ACCESS
- 在以下函数中访问时,匹配变量的赋值不为空或无效:
-(void)matchmakerViewController: (GKMatchmakerViewController
*)
viewController didFindMatch:(GKMatch *)match
- 我可能做错了整个过程
我处理邀请的流程
- 来自设备 A 的媒人向设备 B 发送有关邀请的通知
- 设备 B 打开并重定向到匹配房间
- 设备 B 调用以下函数:
{
-(void)player:(GKPlayer *)player didAcceptInvite:(GKInvite *)invite {
self->inviteStarted((int)invite.playerGroup);
NSLog(@"didAcceptInvite");
//Called when another player accepts a match invite from the local player.
NSLog(@"didAcceptInvite was called: Player: %@ accepted our invitation", player);
GKMatchmakerViewController *mmvc = [[[GKMatchmakerViewController alloc] initWithInvite:invite] autorelease];
mmvc.matchmakerDelegate = self;
[[AppController getViewController] presentViewController:mmvc animated:YES completion:nil];
}
}
- 两个设备调用以下函数:
{
-(void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFindMatch:(GKMatch *)match
{
if (match != nil)
{
[[AppController getViewController] dismissViewControllerAnimated:YES completion:nil];
NSLog(@"%@", match);
self->myMatch = match;
//NSLog(@"Match found count!! %lu", (unsigned long)[self->myMatch retainCount]);
match.delegate = self;
if (!self->matchStarted && myMatch.expectedPlayerCount == 0)
{
self->matchStarted = YES;
opponent=[[myMatch players] objectAtIndex:0];
self->matchBegan();
[self loadOppPhoto];
}
}
}
}
- 设备 A 向设备 B 发送数据 (此处发生崩溃)
{
-(无效)sendDataToOppUnreliable:(NSString*)str
{
NSError *error=nil;
NSData *packet = [str dataUsingEncoding:NSUTF8StringEncoding];
//NSLog(@"this: %@", self);
//NSLog(@"Match found count!! %lu", (unsigned long)[self->myMatch retainCount]);
//NSLog(@"match: %@", self->myMatch);//EXC_BAD_ACCESS
[myMatch sendDataToAllPlayers: packet withDataMode:
GKMatchSendDataUnreliable error:&error];//EXC_BAD_ACCESS
if (error!=nil)
{
NSLog(@"Error in sending data: %li", (long)[error code]);
}
}
}
感谢您的帮助:)
- GKMatch 属性 已设置为(分配)并且需要更改为
(保留)
- GKMatch 对象需要在开始时初始化为 nil 所以
可以用
问题简述
尝试使用 gamecenter 与朋友实时玩游戏导致游戏崩溃
项目详情
- 我正在使用 gamecenter 和 cocos2dx
- 我正在使用 SANDBOX 模式:正在测试的两个帐户都处于沙盒模式
- 2台Ipad用于测试(IOS 8.3)
- 我正在使用 GKMatchMaker 来匹配玩家
- 与 'Random' 又名 'Play Now' 的实时匹配没有问题
- 实时匹配 'Invite a Friend' 匹配成功但在访问 GKMatch 对象后崩溃
- 当我使用可靠或不可靠的方法发送数据时发生崩溃(仅在邀请时)
我的调查
- 在比赛期间访问 GKMatch 会创建 EXC_BAD_ACCESS
- 在以下函数中访问时,匹配变量的赋值不为空或无效:
-(void)matchmakerViewController: (GKMatchmakerViewController *) viewController didFindMatch:(GKMatch *)match
- 我可能做错了整个过程
我处理邀请的流程
- 来自设备 A 的媒人向设备 B 发送有关邀请的通知
- 设备 B 打开并重定向到匹配房间
- 设备 B 调用以下函数:
{
-(void)player:(GKPlayer *)player didAcceptInvite:(GKInvite *)invite {
self->inviteStarted((int)invite.playerGroup);
NSLog(@"didAcceptInvite");
//Called when another player accepts a match invite from the local player.
NSLog(@"didAcceptInvite was called: Player: %@ accepted our invitation", player);
GKMatchmakerViewController *mmvc = [[[GKMatchmakerViewController alloc] initWithInvite:invite] autorelease];
mmvc.matchmakerDelegate = self;
[[AppController getViewController] presentViewController:mmvc animated:YES completion:nil];
}
}
- 两个设备调用以下函数:
{
-(void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFindMatch:(GKMatch *)match
{
if (match != nil)
{
[[AppController getViewController] dismissViewControllerAnimated:YES completion:nil];
NSLog(@"%@", match);
self->myMatch = match;
//NSLog(@"Match found count!! %lu", (unsigned long)[self->myMatch retainCount]);
match.delegate = self;
if (!self->matchStarted && myMatch.expectedPlayerCount == 0)
{
self->matchStarted = YES;
opponent=[[myMatch players] objectAtIndex:0];
self->matchBegan();
[self loadOppPhoto];
}
}
}
}
- 设备 A 向设备 B 发送数据 (此处发生崩溃)
{ -(无效)sendDataToOppUnreliable:(NSString*)str
{
NSError *error=nil;
NSData *packet = [str dataUsingEncoding:NSUTF8StringEncoding];
//NSLog(@"this: %@", self);
//NSLog(@"Match found count!! %lu", (unsigned long)[self->myMatch retainCount]);
//NSLog(@"match: %@", self->myMatch);//EXC_BAD_ACCESS
[myMatch sendDataToAllPlayers: packet withDataMode:
GKMatchSendDataUnreliable error:&error];//EXC_BAD_ACCESS
if (error!=nil)
{
NSLog(@"Error in sending data: %li", (long)[error code]);
}
}
}
感谢您的帮助:)
- GKMatch 属性 已设置为(分配)并且需要更改为 (保留)
- GKMatch 对象需要在开始时初始化为 nil 所以 可以用