4

When I open a specific Storyboard scene, my app crashes with the error: "incorrect checksum for freed object - object was probably modified after being freed". I've also got some "EXC_BAD_ACCESS" crashes going on, it's usually one or the other. I couldn't find the troubled pointer, so I tested it out with NSZombieEnabled. That lead me to get this message on the crash: *** -[NSContentSizeLayoutConstraint secondItem]: message sent to deallocated instance 0x1e0a5220

Now, I searched the project for [NSContentSizeLayoutConstraint secondItem], and even just NSContentSizeLayoutConstraint and secondItem individually. It exists nowhere in the project. I'm still very new to Objective-C, and have no idea what to do next. Also, it will run just fine like 1 out of 5 times on the device and simulator. This also happened with: -[NSAttributeDictionary release]:, which is no where in my project either. Also, *** -[PitchDetector addSamples:inNumberFrames:]:. They keep changing, and I can't find these anywhere in my project. And it runs just fine sometimes, usually on the simulator, which makes it really frustrating since the error keeps changing on the device when it crashes.

To switch views in the storyboard, I'm using this code. This is in the viewDidLoad on the main screen: x1ViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"x1ViewController"];

And when the button is pushed to load it: - (IBAction)button4:(id)sender { [self presentViewController:x1ViewController animated:YES completion:nil]; }

I've set up all the other page transitions the exact same way and they all switch over just fine. This is the only troubled one.

Here is the stack trace: enter image description here

And here is a weird thing I found during an analysis that I'm unsure of how to fix: enter image description here

Update: I'm also occasionally getting the message "Error: 1768843636" in the console once the page loads. Very strange.

Henry F
  • 4,960
  • 11
  • 55
  • 98
  • show the code how you performing segue or push – santhu Jan 31 '14 at 17:09
  • @santhu Just updated, thank you. – Henry F Jan 31 '14 at 17:13
  • Are you using a Storyboard file, as you imply in your first line, or instantiating all the view controllers yourself? – dpassage Jan 31 '14 at 17:40
  • @dpassage I'm using a storyboard file. – Henry F Jan 31 '14 at 17:42
  • I don't think it has anything to do with the story board though. – Henry F Jan 31 '14 at 18:07
  • Search your project for NSLayoutConstraint (not just NSContentSizeLayoutConstraint). Run the static analyzer via the Product > Analyze menu item and investigate/fix what it reports. And can you include the exception backtrace above? – bneely Jan 31 '14 at 18:48
  • Show us the stack trace. apple shift 4 will let you screenshot an area of the screen. Welcome to views! – Stephen J Jan 31 '14 at 18:49
  • @StephenJ Sure thing! Just added it in. – Henry F Jan 31 '14 at 18:59
  • 1
    @bneely Thanks, I found something questionable but am unsure of how to fix it, I included it in the OP. It may be the cause. – Henry F Jan 31 '14 at 19:02
  • 2
    Based on the backtrace, I would look in your xibs and storyboards for broken connections or autolayout warnings. The exception description is specific to Apple's code and your code is not in the backtrace, so I'm thinking either you have a UI configuration error or an Apple bug. Rule out the first before assuming the second. As for the AudioBufferList issue, you are using two different types there - casting to `AudioBufferList *` while calling `sizeof(AudioBuffer)`. Unrelated to the constraint exception, but you should fix that. – bneely Jan 31 '14 at 19:34
  • @bneely Thank you. I will double check all my connections now and see if anything is broken. I haven't changed anything on the storyboard since it started breaking though... odd. I have messed around with one label I created through code, hopefully that's the issue. Checking now. – Henry F Jan 31 '14 at 19:38

1 Answers1

2

To switch views in the storyboard, I'm using this code. This is in the viewDidLoad on the main screen:

x1ViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] 
                        instantiateViewControllerWithIdentifier:@"x1ViewController"];

Well, there's your problem. viewDidLoad is way too soon. You aren't even in the interface yet and already you are trying to move to the next state of the interface. Moreover, you are running the risk of trying to present the same view controller instance on different occasions.

Move that code to your button-press code. You don't need this view controller instantiated until the moment comes when you present it. Use a new view controller instance each time you present.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • I don't navigate to the x1 screen until a button is pushed though, is that still a problem? – Henry F Jan 31 '14 at 19:06
  • Yeah, I just noticed that. :( – matt Jan 31 '14 at 19:07
  • For sure, thanks though man I'll keep that in mind as I keep building! – Henry F Jan 31 '14 at 19:07
  • 1
    OK, try it this way: don't instantiate x1ViewController until the button is pushed. Humor me and see if that helps. If not I'll just delete this answer and we'll try again. :) – matt Jan 31 '14 at 19:07
  • It is deeply weird to instantiate a view controller long before you need it, or to instantiate a view controller before the current view controller has finished setting itself up. So let's just do things the normal way and see if it straightens things out any. – matt Jan 31 '14 at 19:09
  • I'm betting I've put my finger on it (see the revised answer above). You must not conserve the same view controller _instance_ for multiple presentation. It costs nothing to instantiate a view controller so just do this the totally normal way. – matt Jan 31 '14 at 19:11
  • I made the changes and unfortunately it didn't help. I think I may be having issues with a global variable that I may have messed up with implementing. Could that be the cause? – Henry F Jan 31 '14 at 19:16
  • 1
    The problem appears to be that you have a constraint (designed in the storyboard) to something in the interface that has vanished. The question is why. – matt Jan 31 '14 at 19:31
  • I've actually just narrowed the issue down, I updated my OP at the bottom. – Henry F Jan 31 '14 at 19:49
  • Seems like a possibly different issue (you gotta love the Analyzer), but perhaps you are causing memory corruption here which is biting you in unpredictable ways later. Anyway, fix it and see if it helps! – matt Jan 31 '14 at 21:41
  • I think you're right, just weird memory corruption that I can't narrow down – Henry F Feb 01 '14 at 00:32
  • Well, did you fix the thing the Analyzer found? – matt Feb 01 '14 at 01:38
  • I actually just fixed the whole thing, your answer lead me down the right path. I was initializing waaay too much stuff in the viewDidLoad of the problem'd view controller! – Henry F Feb 01 '14 at 02:00
  • 1
    I've no idea what the real problem was but I'm glad I was able to help somehow! – matt Feb 01 '14 at 03:33