views:

808

answers:

6

Hi,

I'm amused by a strange error that I'm encountering in my program.

I have a tableViewController with a navigationBar. When the user clicks on an ADD button on the navigationBar, they're presented with a modal tableViewController. This viewController has a CANCEL button on its navigationBar (which dismisses the viewController via delegation)

The tableViewController has custom cells containing UIButtons, a UITextField and a UITextView.

The error is caused by following this sequence of actions (and no other):

  • I type some text into the UITextView (which is located in one of the cells)
  • Without dismissing the keyboard, I then scroll the tableView upwards.
  • I hit the cancel button (so that the modal view controller is dismissed)
  • Back in the main tableViewController, I tap the ADD button again,

I get the exec_bad_access error.

Nothing else causes this error.

If I try exactly the same procedure but with the UITextField instead, things are fine.

Also if I exclude any of the listed steps from the above sequence, things are fine.

I'm pretty confused. Could it be a bug?


Update

i tried using NSZombie to figure out what's causing the error. This is what I see in the console:

MyApp[14402:207] *** -[UIWebDocumentView isKindOfClass:]: message sent to deallocated instance 0x200a800

I don't have much code for this. The cell's are created in interface builder. Here's the method which brings up the modalViewController

- (void)createNewEntry:(id)sender {

CreateNewEntryViewController *createNewEntryVC = [[CreateNewEntryViewController alloc] initWithNibName:@"CreateNewEntryViewController" bundle:nil];
createNewEntryVC.delegate = self;

UINavigationController *createNewEntryNavigationController = [[UINavigationController alloc] initWithRootViewController:createNewEntryVC];
[createNewEntryVC release];

[self presentModalViewController:createNewEntryNavigationController animated:YES];
[createNewEntryNavigationController release]; }
A: 

In these kind of situations, I usually start commenting out code until it stops breaking. Then you know where the problem is. I would start with any release statements you have in the CreateNewEntryViewController, even the ones that seem mundane

coneybeare
Thanks, I tried a bunch of things already. The issue seems to persist. I have disabled scrolling for the tableView for now (as I don't really need it). But the issue certainly remains.
cocoaholic
A: 

This is definitely a memory management issue, as coneybeare said, very probably an issue with the way CreateNewEntryViewController is releasing its objects.

Questions:

  1. What does the dealloc method of CreateNewEntryViewController look like?
  2. Why are you creating a new UINavigationController instance here? Sounds like your main tableViewController is already in a UINavigationController, why create a new one here?
  3. If you leave out the 4th step in your sequence of actions (don't hit the add button again, just wait after canceling your modal view controller), does the app crash?

Also, if you could post any more code, that would be helpful.

Another thing that might be worth pursuing is, as was already suggested, start simpifying/commenting out code until it works, then retrace your steps. Maybe start removing objects from your IB files, make the CreateNewEntryViewController blank with only a cancel button, see if that works.

jenningj
thanks.. i'll get back to you with the answers soon!
cocoaholic
+1  A: 

Final Edit:

I found the solution to my problem, maybe it will solve yours too. (Look at my answer to this question:) http://stackoverflow.com/questions/1575529

Specifically, if your buttons have any images, try deleting them from your project, getting fresh copies, renaming them, re-adding them to the project and then hooking them up again. Seems to have worked in my case.


Previous randomness from me:

(Not an answer, but...) For what it's worth, I'm getting a similar message. Maybe adding what I'm seeing might help figure this all out. I get this both in the Simulator and on the device.

-[UIImage isKindOfClass:]: message sent to deallocated instance 0x1661f0

This message is not always identical for me, sometimes its about retaining an invalid instance, or a few other similar sorts of things. None of these are things I'm doing myself, but behind the scenes stuff.

EDIT: Here's another one:

-[UIImage retain]: message sent to deallocated instance 0x3b621a0

Here's the code where I'm getting dumped (like you, I'm showing a modal dialog, though mine's a custom UIView). In my case, I'm forcing the run loop to wait for a user response like this:

[modalDialog showInView:self.view
                  title:@"Illegal Move"
                message:message 
             cancelText:@"Cancel" 
            proceedText:@"Cheat"];

while (waitingForDialogToDismiss == YES) {
    //this line is where NSZombies puts me:
    [[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode 
                             beforeDate: [NSDate dateWithTimeIntervalSinceNow:1.5]];
}

This modal dialog is built completely from a nib, and has a couple button images and shows correctly almost always. However, if I try to "rush it" by tapping many different UI elements before it comes up, I can get this error about 30-40% of the time. On one occasion, even though the dialog showed up, its Cancel button had the wrong graphic.

It almost seems like the showing of the view isn't always completely loading everything correctly, or maybe in a timely manner.

For the moment, I'm going to try rewriting a bunch of code to remove the NSRunLoop business. We'll see.

EDIT 2: No help

The NSRunLoop was definitely not the problem. I've narrowed it down much more and started a new question here: http://stackoverflow.com/questions/1575529

Rob
A: 

I had the same issue (or one very similar).

In my case the crash was occurring because I had implemented the UITextView delegate method textViewShouldEndEditing: to always return NO.

Brett
A: 

In my case, I was using a CustomTextView as described here: http://www.iphonedevsdk.com/forum/iphone-sdk-development/4864-adding-border-uitextview.html

The problem is the [backgroundImage release]; line. It should be [myImageView release];

I know this is a far cry from the original question, but my search led me here, so hopefully this helps someone in the future.

alku83
A: 

This can also happen if you accidentally call a [delegate release] in the dealloc method of your modal controller. Your modal controller will exit but you'll be ticking toward a bad access crash in the parent controller. Typically you use something like:

@property (nonatomic, assign) id delegate;

Cover it with @synthesize in your implementation but don't release it--your modal VC doesn't own a copy.

indigosplinter