EXE_BAD_BADACCESS尝试访问GKMatch?

时间:2015-06-10 05:26:37

标签: cocos2d-x real-time game-center invite gkmatchmaker

问题简介

尝试使用游戏中心实时与朋友一起玩游戏会导致游戏中的崩溃

项目详情

  • 我正在使用带有cocos2dx的游戏中心
  • 我正在使用SANDBOX模式:正在测试的两个帐户都是沙盒模式
  • 2个Ipads用于测试(IOS 8.3)
  • 我正在使用GKMatchMaker来匹配玩家
  • 实时匹配'随机'又名'现在播放'没有问题的工作
  • 实时与'邀请朋友匹配'匹配成功但访问GKMatch对象后崩溃
  • 使用可靠或不可靠的方法发送数据时发生崩溃(仅限邀请)

我的调查

  • 在比赛期间访问GKMatch会创建EXC_BAD_ACCESS
  • 在以下函数中访问时,匹配变量的赋值不为null或无效:
  

- (void)matchmakerViewController:(GKMatchmakerViewController   *)   viewController didFindMatch:(GKMatch *)匹配

  • 我可能会错误地完成整个过程

我处理邀请的流程

  1. 来自设备A的匹配制造商向设备B发送关于邀请的通知
  2. 设备B打开并重定向以匹配制作室
  3. 设备B调用以下功能:
  4. {

    -(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];
    
      }
    

    }

    1. 两个设备都调用以下功能:
    2. {

      -(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];
          }
      }
      }
      

      }

      1. 设备A向设备B发送数据(此处发生重击)
      2. {      - (void)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]; // EXC_BAD_ACCESS

        if (error!=nil)
        {
            NSLog(@"Error in sending data: %li", (long)[error code]);
        }
        }
        

        }

        感谢您的帮助:)

1 个答案:

答案 0 :(得分:0)

  • GKMatch属性设置为(assign),需要更改为 (保留)
  • GKMatch对象需要在开始时初始化为nil 可以使用