0
votes

I'm working on a cocos2d project on iOS6 and it crash time to time while I'm trying to share something on twitter.

  • It only crashes on physical device (iOS 6.1.3)
  • It runs without any problems on simulator (iOS 6.1)
  • The problem arises when [twitterViewController addImage:] is used
  • I'm using ARC
  • Update: the problem is the \n character on body

When I call shareOnTwitter function, it opens the twitter share. I can close or post and it dismiss the view fine. But the second, third or even more times you press the button it crash with EXC_BAD_ACCESS.

With Enable Zombie Objects I get this error:

[SLTwitterComposeViewController respondsToSelector:]: message sent to deallocated instance

It does not crash on any particular line on my code.

Stack:

libobjc.A.dylib`objc_msgSend:
0x3ad3b5a0:  teq.w  r0, #0
0x3ad3b5a4:  beq    0x3ad3b5e6                ; objc_msgSend + 70
0x3ad3b5a6:  push.w {r3, r4}
0x3ad3b5aa:  ldr    r4, [r0]
0x3ad3b5ac:  lsr.w  r9, r1, #2
0x3ad3b5b0:  ldr    r3, [r4, #8]    <-------- Thread 1: EXC_BAD_ACCESS
0x3ad3b5b2:  add.w  r3, r3, #8
0x3ad3b5b6:  ldr    r12, [r3, #-8]
0x3ad3b5ba:  and.w  r9, r9, r12
0x3ad3b5be:  ldr.w  r4, [r3, r9, lsl #2]

Code:

- (void)shareOnTwitter {

    UIImage *renderedImage = ...;

    NSString *text = ...;

    SLComposeViewController *twitterViewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
    [twitterViewController setInitialText:text];
    [twitterViewController addImage:renderedImage];
    [twitterViewController addURL:[NSURL URLWithString:kAPPURL]];
    [twitterViewController setCompletionHandler:^(SLComposeViewControllerResult result){

        switch (result) {
            case SLComposeViewControllerResultCancelled:
                break;
            case SLComposeViewControllerResultDone:
                break;
            default:
                break;
        }

        [[CCDirector sharedDirector] dismissViewControllerAnimated:YES completion:nil];
    }];

    [[CCDirector sharedDirector] presentViewController:twitterViewController animated:YES completion:nil];
}

Thanks for your help!

UPDATE:

The problem is solved when I comment the line that adds the image:

//[twitterViewController addImage:renderedImage];

Which made me doubt about my render image function, so I replaced the line with:

[twitterViewController addImage:[UIImage imageNamed:@"[email protected]"]];

And the problem is noticeable once again. Weird right?

1
which line does it crash? call stack? ARC or MRC?LearnCocos2D
@LearnCocos2D I updated the post with more details. I'll create a new project to test this later, maybe I'm missing something somewhere.Firula

1 Answers

0
votes

Finally I got it! The problem was a return character on the message text. The most weird is that it seems to only occurs with certain text lenght and parameters sets.

Took me few hours to close up the problem and make an example that produces the app crash. It crashes in only certain circumstances. For example, with the text I'm providing, if you comment addURL it will not crash.

Pay attention to setInitialText in the following code, almost at the end of the text there is a \n character. That is the tiny problem...

[twitterViewController setInitialText:@"########################## ###########? ########### ########: #######\n## #######"];
[twitterViewController addURL:[NSURL URLWithString:@"http://google.com"]];

Now, if you replace this lines on the same code that is in the question, the application will crash after some twitter view dismisses.

I created a new project and paste this same lines... it crashes. It may be a bug on SLComposeViewController