- [CFString retain]:消息发送到释放的实例0x215076c0 [英] -[CFString retain]: message sent to deallocated instance 0x215076c0

查看:389
本文介绍了 - [CFString retain]:消息发送到释放的实例0x215076c0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这个主题已经讨论过几次,但我不知道是什么原因导致此错误消息。我已经被困在这里了几个星期,它驱使我疯了。该方法的第一部分为2-4个玩家设置匹配。一旦找到匹配,它会尝试在一定限制内添加3和4个玩家。现在,限制只是设置为3秒,但我想,一旦准备好发布就更大了。



我知道这是一个内存错误matchmakerViewController代码。当我注释掉改变场景的代码时,我仍然得到错误。

   - (void)matchmakerViewController:(GKMatchmakerViewController *)你可以看看我做错了什么, viewController didFindMatch:(GKMatch *)match 
{
NSLog(@IN matchmakerViewController!);

NSLog(@Found a match!);
// startDate = [[NSDate date] retain];

// NSArray * playerIds1 = match.playerIDs;
// [marray_players addObject:playerIds1];

//设置匹配
TXGameCenterManager * gameCenterManager = [TXGameCenterManager sharedTXGameCenterManager];
gameCenterManager.multiplayerMatch = match;
//匹配的委托是HelloWorldLayer
gameCenterManager.multiplayerMatch.delegate = self;
AppDelegate * delegate =(AppDelegate *)[UIApplication sharedApplication] .delegate;
[delegate.viewController dismissModalViewControllerAnimated:NO];


GKMatchRequest * matchRequest = [[[GKMatchRequest alloc] init] autorelease];


NSLog(@playerIDs count is%d,[match.playerIDs count]);


if(match.expectedPlayerCount == 0)
{
//在不等待连接更改消息的情况下启动游戏
NSLog游戏无需等待匹配连接更改消息);
//确定主机,本地或远程
NSArray * playerIds = match.playerIDs;
NSLog(@玩家人数:%d,[playerIds count]);
NSLog(@播放器ID:%@,[playerIds lastObject]);
NSLog(@我有玩家ids);


[GKPlayer loadPlayersForIdentifiers:playerIds withCompletionHandler:^(NSArray * players,NSError * error)
{

NSLog(@Player 1%@ ,[[players objectAtIndex:0] alias]);
// NSLog(@Player 2%@,[[players objectAtIndex:1] alias]);


if(!error)
{
NSLog(@本地播放器:%@,[[GKLocalPlayer localPlayer] alias]);
NSLog(@远程播放器:%@,[[players lastObject]别名]);
NSLog(@远程播放器:%@,[[players lastObject]别名]);

// NSArray * nsarray_player2 = [marray_players objectAtIndex:1];

// remote1name = [[nsarray_player1 lastObject] alias]

int_totalremoteplayers = [match.playerIDs count];
boo_playersfound = true;


localName = [[GKLocalPlayer localPlayer] alias];
remoteName = [[players objectAtIndex:0] alias];

NSLog(@Player 1%@,[[players objectAtIndex:0] alias]);
// NSLog(@Player 2%@,[[players objectAtIndex:1] alias]);


// remote1name = [[nsarray_player1 lastObject] alias];

if([match.playerIDs count] == 1)
{
NSLog(@IN [match.playerIDs count] == 1);

remoteplayer1name = [[players objectAtIndex:0] alias];
[playernames addObject:remoteplayer1name];
[playernames addObject:localName];

NSArray * sortedArray;
sortedArray = [playernames sortedArrayUsingSelector:
@selector(localizedCaseInsensitiveCompare :)];

NSLog(@Host:%@,[sortedArray objectAtIndex:0]);
NSLog(@Player1:%@,[sortedArray objectAtIndex:1]);


hostName = [sortedArray objectAtIndex:0];
remoteplayer1name = [sortedArray objectAtIndex:1];

if([hostName isEqualToString:localName])
{
[[TXGameCenterManager sharedTXGameCenterManager] setHost:YES];
}

}

if([match.playerIDs count] == 2)
{
NSLog(@IN [match .playerIDs count] == 2);
NSLog(@[match.playerIDs count] == 2 Player 1%@,[[players objectAtIndex:0] alias]);
NSLog(@[match.playerIDs count] == 2 Player 2%@,[[players objectAtIndex:1] alias]);
NSLog(@[match.playerIDs count] == 2 localName%@,localName);

remoteplayer1name = [[players objectAtIndex:0] alias];
remoteplayer2name = [[players objectAtIndex:1] alias];
[playernames addObject:remoteplayer1name];
[playernames addObject:remoteplayer2name];
[playernames addObject:localName];


NSLog(@Players in playernames%d,[playernames count]);


NSArray * sortedArray;
sortedArray = [playernames sortedArrayUsingSelector:
@selector(localizedCaseInsensitiveCompare :)];

NSLog(@Host:%@,[sortedArray objectAtIndex:0]);
NSLog(@Player1:%@,[sortedArray objectAtIndex:1]);
NSLog(@Player2:%@,[sortedArray objectAtIndex:2]);


hostName = [sortedArray objectAtIndex:0];
remoteplayer1name = [sortedArray objectAtIndex:1];
remoteplayer2name = [sortedArray objectAtIndex:2];

if([hostName isEqualToString:localName])
{
[[TXGameCenterManager sharedTXGameCenterManager] setHost:YES];
}

NSLog(@match.expectedPlayerCount =%d,match.expectedPlayerCount);


}

else if([match.playerIDs count] == 3)
{
remoteplayer1name = [[players objectAtIndex: 0] alias];
remoteplayer2name = [[players objectAtIndex:1] alias];
remoteplayer3name = [[players objectAtIndex:2] alias];
[playernames addObject:remoteplayer1name];
[playernames addObject:remoteplayer2name];
[playernames addObject:remoteplayer3name];
[playernames addObject:localName];

NSArray * sortedArray;
sortedArray = [playernames sortedArrayUsingSelector:
@selector(localizedCaseInsensitiveCompare :)];

NSLog(@Host:%@,[sortedArray objectAtIndex:0]);
NSLog(@Player 1:%@,[sortedArray objectAtIndex:1]);
NSLog(@Player 2:%@,[sortedArray objectAtIndex:2]);
NSLog(@Player 3:%@,[sortedArray objectAtIndex:3]);


hostName = [sortedArray objectAtIndex:0];
remoteplayer1name = [sortedArray objectAtIndex:1];
remoteplayer2name = [sortedArray objectAtIndex:2];
remoteplayer3name = [sortedArray objectAtIndex:3];

if([hostName isEqualToString:localName])
{
[[TXGameCenterManager sharedTXGameCenterManager] setHost:YES];
}
}


NSLog(@Player names);
// TODO:在全局变量中设置正确的播放器名称
player1 = localName;
player2 = [[NSUserDefaults standardUserDefaults] objectForKey:@player2name];
player3 = [[NSUserDefaults standardUserDefaults] objectForKey:@player3name];
player4 = [[NSUserDefaults standardUserDefaults] objectForKey:@player4name];


NSLog(@启动游戏);
//启动游戏
int_team2tally = 0;
NSLog(@boo_startgame);
boo_startgame = true;
NSLog(@转到所需场景);
//转到所需的场景

}



else
{
NSLog(@错误);
}

NSLog(@StartMultiplayerGameTablehost);
//gameCenterManager.matchController.matchmakerDelegate = nil;
[self performSelector:@selector(StartMultiplayerGameTablehost)withObject:nil afterDelay:1。

}


];

NSLog(@无错误);

}

//相信错误是在下面的代码中的某个地方。
if(boo_gamestarted!= true)
{

if(match.expectedPlayerCount == 0)
{
// if([localName isEqualToString: hostName])
// {
boo_startgame = true;

if([match.playerIDs count] == 1)
{

matchRequest.minPlayers = 3;
matchRequest.maxPlayers = 4;
matchRequest.playersToInvite = nil;

[[GKMatchmaker sharedMatchmaker] addPlayersToMatch:match matchRequest:matchRequest completionHandler:^(NSError * error)
{
if(error)
{
NSLog (@添加播放器匹配时出错:%@,[error localizedDescription]);}
else if(match!= nil)
{NSLog to the match);}
}];
}

else if([match.playerIDs count] == 2)
{
matchRequest.minPlayers = 4;
matchRequest.maxPlayers = 4;
matchRequest.playersToInvite = nil;

[[GKMatchmaker sharedMatchmaker] addPlayersToMatch:match matchRequest:matchRequest completionHandler:^(NSError * error)
{
if(error)
{
NSLog (@添加播放器匹配时出错:%@,[error localizedDescription]);}
else if(match!= nil)
{NSLog to the match);}
}];
}


if([match.playerIDs count] == 3)
{
NSLog(@Starting Game-589);
// [CCTimer timerWithTarget:self selector:@selector(StartMultiplayerGameTablehost)interval:10];
// [self performSelector:@selector(StartMultiplayerGameTablehost)withObject:nil afterDelay:1];

} // end if(match.expectedPlayerCount == 0)

else if(boo_gamestarted == false)
{
NSLog(@ player count =%d,[match.playerIDs count]);
NSLog(@Starting Game-597);
// [self performSelector:@selector(StartMultiplayerGameTablehost)withObject:nil afterDelay:1。

}


// [CCTimer timerWithTarget:self selector:@selector(StartMultiplayerGameTablehost)interval:10];
// [self performSelector:@selector(StartMultiplayerGameTablehost)withObject:nil afterDelay:3。
//}

//
else
{

boo_startgame = true;


matchRequest.minPlayers = 3;
matchRequest.maxPlayers = 4;
matchRequest.playersToInvite = nil;

[[GKMatchmaker sharedMatchmaker] addPlayersToMatch:match matchRequest:matchRequest completionHandler:^(NSError * error)
{
if(error)
{
NSLog (@添加播放器匹配时出错:%@,[error localizedDescription]);}
else if(match!= nil)
{NSLog to the match);}
}];
[self performSelector:@selector(StartMultiplayerGameTablehost)withObject:nil afterDelay:3。



}
}
}
}


- (void)StartMultiplayerGameTablehost
{
boo_gamestarted = true;

[[CCDirector sharedDirector] replaceScene:[HelloWorldLayer node]];
}

- (void)dealloc
{
[super dealloc];
}

最终结果是类似以下的消息:

 #0 0x32499468在___forwarding___()
#1 0x323f0f68在__forwarding_prep_0___()
#2 0x31ffac5e在_Block_object_assign b#3 0x39614614在__copy_helper_block_333()
#4 0x31ffa928在_Block_copy_internal()
#5 0x34a86694在_dispatch_Block_copy()
#6 0x34a8894e在dispatch_group_async $ VARIANT $ up()
# 7 0x39613c4e in - [GKConnectionInternal connectParticipantsWithConnectionData:withSessionInfo:]()
#8 0x32c5e21c in - [GKMatch connectToPeersWithDictionaries:version:sessionToken:cdxTicket:]()
#9 0x32c694b2 in __block_global_17 #10 0x34a8711e in _dispatch_call_block_and_release()
#11 0x34a864b6 in _dispatch_client_callout()
#12 0x34a87dca in _dispatch_main_queue_callback_4CF $ VARIANT $ up()
#13 0x3246af3a在__CFRunLoopRun()
#14在CFRunLoopRunSpecific中的0x323ddebc
#15 0x323ddd48在CFRunLoopRunInMode()
#16 0x3a1db2ea在GSEventRunModal()
#17 0x39c992f8在UIApplicationMain()
#18 0x0009f370在main b $ b

这些都不是我现在的代码。

结果是我需要发布

  matchRequest.minPlayers = 3; 
matchRequest.maxPlayers = 4;

重新定义值之前。


I know this subject has been discussed several times, but I cannot figure out what is causing this error message. I've been stuck here for a couple weeks now and its driving me crazy. The first part of the method sets up a match for 2-4 players. Once a match is found, it tries to add 3 and 4 players within a certain limit. Right now, the limit is just set to 3 seconds, but I envision it being much larger once it is ready for release.

I know this is a memory error somewhere in the matchmakerViewController code. When I comment out the code changing the scene, I still get the error. Can you show me what I've done wrong and how to fix it?

-(void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFindMatch:(GKMatch *)match
{
    NSLog(@"IN matchmakerViewController!");

    NSLog(@"Found a match!");
    //startDate = [[NSDate date] retain];

    //NSArray * playerIds1 = match.playerIDs;
    //[marray_players addObject:playerIds1];

    // Setup match
    TXGameCenterManager *gameCenterManager = [TXGameCenterManager sharedTXGameCenterManager];
    gameCenterManager.multiplayerMatch = match;
    // The delegate of the match is HelloWorldLayer
    gameCenterManager.multiplayerMatch.delegate = self;
    AppDelegate * delegate = (AppDelegate *) [UIApplication sharedApplication].delegate;
    [delegate.viewController dismissModalViewControllerAnimated:NO];


    GKMatchRequest * matchRequest = [[[GKMatchRequest alloc] init] autorelease];


    NSLog(@"playerIDs count is %d",[match.playerIDs count] );


    if( match.expectedPlayerCount==0 )
    {
        // Launching the game without waiting for connection change messages
        NSLog(@"Begin game without waiting for match connection change messages");
        // Determine the host, local or remote
        NSArray * playerIds = match.playerIDs;
        NSLog(@"Number of players: %d", [playerIds count]);
        NSLog(@"ID of player: %@", [playerIds lastObject]);
        NSLog(@"I got the player ids");


        [GKPlayer loadPlayersForIdentifiers:playerIds withCompletionHandler:^(NSArray *players, NSError * error)
         {

             NSLog(@"Player 1 %@", [[players objectAtIndex:0] alias] );
            // NSLog(@"Player 2 %@", [[players objectAtIndex:1] alias] );


            if( !error) 
                {
                NSLog(@"Local player: %@", [[GKLocalPlayer localPlayer] alias]);
                NSLog(@"Remote player: %@", [[players lastObject] alias]);
                NSLog(@"Remote player: %@", [[players lastObject] alias]);

                //NSArray *nsarray_player2 = [marray_players objectAtIndex:1];

               // remote1name= [[nsarray_player1 lastObject] alias];

                int_totalremoteplayers=[match.playerIDs count];
                boo_playersfound=true;


                localName = [[GKLocalPlayer localPlayer] alias];
                remoteName = [[players objectAtIndex:0] alias];

                NSLog(@"Player 1 %@", [[players objectAtIndex:0] alias] );
              //  NSLog(@"Player 2 %@", [[players objectAtIndex:1] alias] );


                //remote1name= [[nsarray_player1 lastObject] alias];

                if ([match.playerIDs count]==1)
                {
                    NSLog(@"IN [match.playerIDs count]==1");

                    remoteplayer1name= [[players objectAtIndex:0] alias];
                    [playernames addObject:remoteplayer1name];
                    [playernames addObject:localName];

                    NSArray *sortedArray;
                    sortedArray = [playernames sortedArrayUsingSelector:
                                   @selector(localizedCaseInsensitiveCompare:)];

                    NSLog(@"Host: %@", [sortedArray objectAtIndex:0]);
                    NSLog(@"Player1: %@", [sortedArray objectAtIndex:1]);


                    hostName=[sortedArray objectAtIndex:0];
                    remoteplayer1name=[sortedArray objectAtIndex:1];

                    if ([hostName isEqualToString:localName])
                    {
                        [[TXGameCenterManager sharedTXGameCenterManager] setHost:YES];
                    }

                }

                if ([match.playerIDs count]==2)
                {
                    NSLog(@"IN [match.playerIDs count]==2");
                    NSLog(@" [match.playerIDs count]==2 Player 1 %@", [[players objectAtIndex:0] alias] );
                    NSLog(@"[match.playerIDs count]==2 Player 2 %@", [[players objectAtIndex:1] alias] );
                    NSLog(@"[match.playerIDs count]==2 localName %@", localName );

                    remoteplayer1name= [[players objectAtIndex:0] alias];
                    remoteplayer2name= [[players objectAtIndex:1] alias];
                    [playernames addObject:remoteplayer1name];
                    [playernames addObject:remoteplayer2name];
                    [playernames addObject:localName];


                     NSLog(@"Players in playernames %d", [playernames count]);


                    NSArray *sortedArray;
                    sortedArray = [playernames sortedArrayUsingSelector:
                                   @selector(localizedCaseInsensitiveCompare:)];

                    NSLog(@"Host: %@", [sortedArray objectAtIndex:0]);
                    NSLog(@"Player1: %@", [sortedArray objectAtIndex:1]);
                    NSLog(@"Player2: %@", [sortedArray objectAtIndex:2]);


                    hostName=[sortedArray objectAtIndex:0];
                    remoteplayer1name=[sortedArray objectAtIndex:1];
                    remoteplayer2name=[sortedArray objectAtIndex:2];

                    if ([hostName isEqualToString:localName])
                    {
                        [[TXGameCenterManager sharedTXGameCenterManager] setHost:YES];
                    }

                     NSLog(@"match.expectedPlayerCount = %d",match.expectedPlayerCount);


                }

                else if ([match.playerIDs count]==3)
                {
                    remoteplayer1name= [[players objectAtIndex:0] alias];
                    remoteplayer2name= [[players objectAtIndex:1] alias];
                    remoteplayer3name= [[players objectAtIndex:2] alias];
                    [playernames addObject:remoteplayer1name];
                    [playernames addObject:remoteplayer2name];
                    [playernames addObject:remoteplayer3name];
                    [playernames addObject:localName];

                    NSArray *sortedArray;
                    sortedArray = [playernames sortedArrayUsingSelector:
                                   @selector(localizedCaseInsensitiveCompare:)];

                    NSLog(@"Host: %@", [sortedArray objectAtIndex:0]);
                    NSLog(@"Player 1: %@", [sortedArray objectAtIndex:1]);
                    NSLog(@"Player 2: %@", [sortedArray objectAtIndex:2]);
                    NSLog(@"Player 3: %@", [sortedArray objectAtIndex:3]);


                    hostName=[sortedArray objectAtIndex:0];
                    remoteplayer1name=[sortedArray objectAtIndex:1];
                    remoteplayer2name=[sortedArray objectAtIndex:2];
                    remoteplayer3name=[sortedArray objectAtIndex:3];

                    if ([hostName isEqualToString:localName])
                    {
                        [[TXGameCenterManager sharedTXGameCenterManager] setHost:YES];
                    }
                }


                NSLog(@"Player names");
                // TODO: Set the correct player names in the globals
                player1 = localName;
                player2 = [[NSUserDefaults standardUserDefaults]  objectForKey:@"player2name"];
                player3 = [[NSUserDefaults standardUserDefaults]  objectForKey:@"player3name"];
                player4 = [[NSUserDefaults standardUserDefaults]  objectForKey:@"player4name"];


                NSLog(@"Launch the game");
                // Launch the game
                int_team2tally=0;
                NSLog(@"boo_startgame");
                boo_startgame=true;
                NSLog(@"go to the required scene");
                //go to the required scene

            }



            else
            {
                NSLog(@"Error");
            }

             NSLog(@"StartMultiplayerGameTablehost");
             //gameCenterManager.matchController.matchmakerDelegate = nil;
             [self performSelector:@selector(StartMultiplayerGameTablehost) withObject:nil afterDelay:1.];

        }


         ];

     NSLog(@"No Error");

    }

// Believe the error is somewhere in the following code.
    if (boo_gamestarted!=true)
    {

        if (match.expectedPlayerCount==0)
        {
           //if([localName isEqualToString:hostName])
           // {
                boo_startgame=true;

                if ([match.playerIDs count]==1)
                {

                matchRequest.minPlayers = 3;
                matchRequest.maxPlayers = 4;
                matchRequest.playersToInvite = nil;

                [[GKMatchmaker sharedMatchmaker] addPlayersToMatch:match matchRequest:matchRequest completionHandler:^(NSError *error)
                 {
                     if (error)
                     {
                         NSLog(@"An error occurred during adding a player to match: %@", [error localizedDescription]);}
                     else if (match != nil)
                     {NSLog(@"A player has been added to the match");}
                 }];
                }

                else if ([match.playerIDs count]==2)
                {
                    matchRequest.minPlayers = 4;
                    matchRequest.maxPlayers = 4;
                    matchRequest.playersToInvite = nil;

                    [[GKMatchmaker sharedMatchmaker] addPlayersToMatch:match matchRequest:matchRequest completionHandler:^(NSError *error)
                     {
                         if (error)
                         {
                             NSLog(@"An error occurred during adding a player to match: %@", [error localizedDescription]);}
                         else if (match != nil)
                         {NSLog(@"A player has been added to the match");}
                     }];
                }


            if ([match.playerIDs count]==3)
            {
                 NSLog(@"Starting Game-589");
                // [CCTimer timerWithTarget:self selector:@selector(StartMultiplayerGameTablehost) interval:10];
                //[self performSelector:@selector(StartMultiplayerGameTablehost) withObject:nil afterDelay: 1.];

            }  // end if (match.expectedPlayerCount==0)

            else if (boo_gamestarted==false)
            {
                NSLog(@"player count = %d",[match.playerIDs count]);
                NSLog(@"Starting Game-597");
               // [self performSelector:@selector(StartMultiplayerGameTablehost) withObject:nil afterDelay:1.];

            }


                //[CCTimer timerWithTarget:self selector:@selector(StartMultiplayerGameTablehost) interval:10];
               // [self performSelector:@selector(StartMultiplayerGameTablehost) withObject:nil afterDelay:3.];
           // }

            //
            else
            {

                boo_startgame=true;


                matchRequest.minPlayers = 3;
                matchRequest.maxPlayers = 4;
                matchRequest.playersToInvite = nil;

                [[GKMatchmaker sharedMatchmaker] addPlayersToMatch:match matchRequest:matchRequest completionHandler:^(NSError *error)
                 {
                     if (error)
                     {
                         NSLog(@"An error occurrred during adding a player to match: %@", [error localizedDescription]);}
                     else if (match != nil)
                     {NSLog(@"A player has been added to the match");}
                 }];
             [self performSelector:@selector(StartMultiplayerGameTablehost) withObject:nil afterDelay:3.];



            }      
        }
    }    
}


-(void)StartMultiplayerGameTablehost
{
    boo_gamestarted=true;

  [[CCDirector sharedDirector] replaceScene:[HelloWorldLayer node]];
}

-(void)dealloc
{
    [super dealloc];
}

The end result is a message that looks like:

#0  0x32499468 in ___forwarding___ ()
#1  0x323f0f68 in __forwarding_prep_0___ ()
#2  0x31ffac5e in _Block_object_assign ()
#3  0x39614614 in __copy_helper_block_333 ()
#4  0x31ffa928 in _Block_copy_internal ()
#5  0x34a86694 in _dispatch_Block_copy ()
#6  0x34a8894e in dispatch_group_async$VARIANT$up ()
#7  0x39613c4e in -[GKConnectionInternal connectParticipantsWithConnectionData:withSessionInfo:] ()
#8  0x32c5e21c in -[GKMatch connectToPeersWithDictionaries:version:sessionToken:cdxTicket:] ()
#9  0x32c694b2 in __block_global_17 ()
#10 0x34a8711e in _dispatch_call_block_and_release ()
#11 0x34a864b6 in _dispatch_client_callout ()
#12 0x34a87dca in _dispatch_main_queue_callback_4CF$VARIANT$up ()
#13 0x3246af3a in __CFRunLoopRun ()
#14 0x323ddebc in CFRunLoopRunSpecific ()
#15 0x323ddd48 in CFRunLoopRunInMode ()
#16 0x3a1db2ea in GSEventRunModal ()
#17 0x39c992f8 in UIApplicationMain ()
#18 0x0009f370 in main ()

None of these are from my now code.

解决方案

The answer ended up being that I needed to release

        matchRequest.minPlayers = 3;
        matchRequest.maxPlayers = 4;

Before re-defining their values.

这篇关于 - [CFString retain]:消息发送到释放的实例0x215076c0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆