views:

410

answers:

1

Well I had an app I was developing in iPhone SDK 2.2 and I recently built and launched it in the 3.0 simulator. The base SDK is still set to 2.2. I figured that would avoid issues. Instead I get

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x00000000a1b1c1f3
Crashed Thread:  0

Thread 0 Crashed:
0   libobjc.A.dylib                 0x92f4b688 objc_msgSend + 24
1   Foundation                      0x305085bd -[NSCFString isEqualToString:] + 61
2   HappyApp                        0x00002c27 -[CombinationsTableViewController loadData] + 220 (CombinationsTableViewController.m:64)

The crash is occurring on a very simple line, where total is a UITextField

if (![total.text isEqualToString:@""] ) {

Has anyone encountered this? I feel like it's a thread contention issue, or my whole app isn't compiling correctly. It works in the 2.2.1 simulator. If this turns out not to be the way to test a 2.2 app in OS 3.0, then what should I be doing other than switching that drop down box?

Update: Andrew Pouliot was right in that this was a released reference issue. The debugger was pointing one line off so I got the wrong hints. The culprit was actually this first line:

if(!([total.text isEqual:totalTextCache]
  && [divisions.text isEqual:divisionsTextCache])) {
  //Loads the data for the table only if the values were actually changed
  totalTextCache = total.text; //ditto for divisions
}

These lines are the only uses of totalTextCache, and it became invalid if total.text was changed. This never caused a problem in the 2.2.1 sim probably because the old total.text was never released by the runtime when it changed value. But this code was wrong. I fixed it by changing it to do exactly what I thought isEqual was doing:

if(!(total.text==totalTextCache && divisions.text==divisionsTextCache))

Because I didn't actually want to copy the NSStrings, but just check if they'd changed (and therefore the reference would have changed, this works. The bad code ran fine in the 2.2.1 runtime because the old reference could still have it's hash property checked and compared by isEqual.

+1  A: 

When I installed my 3.0 SDK my 2.0 tools went away, so not sure if this is applicable, but I don't think simulator builds are designed to be binary compatible to future runtimes.

It is likely though that the problem lies in your code. If so, I can say is that you have a memory management issue and not "thread contention". Everything happens on the main thread in UIKit (not thread safe).

Check where you set up your total variable; it's probably already been released by the time you hit this method. Make sure your retainCount is sensible.

Do you have the same error when you build for 3.0?

Andrew Pouliot
I am building for 3.0. I do not have the error building for 2.2.1. I never release the TextField it's an IBOutlet and it's part of my only view. The other string is a literal. The debugger could be pointing a tad off in my code, seen that a few times.Also to bring back your 2.0 tools go to Project > Edit Project settings, in the General tab set Base SDK for All Configurations to a 2.x SDK.
dlamblin