1

I am trying to migrate to using Xcode 10 on Mojave, coming from using Xcode 8.3.3 on High Sierra. I have a sizeable app containing a fair bit of legacy (non-ARC) code. The app is currently live in the Mac App Store, built with 8.3.3 on High Sierra.

I encountered problems with Xcode 10 and Mojave which took me down a rabbit hole, so I decided to back up and limit the migration to one step at a time. I'm currently attempting (unsuccessfully) to build and run using Xcode 9.4.1 on High Sierra.

Using exactly the same code base (new repo checkout) my app builds and runs fine using Xcode 8.3.3. It builds fine using 9.4.1, but crashes on running.

The problem appears to be memory/reference-counting related. I always get a crash when the app tries to show a window, and the trace is not very helpful. Runtime debug output consistently indicates that I'm sending a message to a deallocated object. Here's a typical stack trace:

stack trace

Whenever the app tries to show a window, I get messages such as (the old favourite) "message sent to deallocated instance". I don't always recognise the receiver as being one of my properties, so it looks like this is just a symptom, not a cause. Here's a typical message: *** -[NSCalibratedRGBColor release]: message sent to deallocated instance 0x60000605ce60

I've tried in vain to get anything back from Xcode's diagnostics, such as zombies and malloc scribble. Radio silence. Also the static analyser reports no problems. All I can think is that manual reference counting is somehow being treated differently by Xcode 9. I've checked through all the build flags to see if Xcode 9 changed anything. No changes. I've checked the release notes and can find no mention of changes to reference counting.

I can push the problem around by commenting out the display of various panels and windows, but the crash always takes the same form.

Has anyone else come across similar issues and found a solution? Am I missing something with Xcode 9? Any help greatly appreciated.

SaxmanBob
  • 31
  • 4
  • If the stack trace is representative, it's a problem with your storyboard/XIB file(s). I think you were going along the right lines when you were commenting out various panels/windows. Also worth double-checking whether your references are strong/weak. See here: https://stackoverflow.com/questions/7678469/should-iboutlets-be-strong-or-weak-under-arc/31395938#31395938 – Stephen Darlington Oct 12 '18 at 12:19
  • Did you create a new Xcode project? Which SDK is used with Xcode 8 and 9? – Willeke Oct 12 '18 at 15:36
  • Maybe related: "If your application is linked on macOS 10.13 SDK or later, NSWindows that are ordered-in will be strongly referenced by AppKit, until they are explicitly ordered-out or closed (not including hide or minimize operations). This means that, generally, an on-screen window will not be deallocated (and close/order-out as a side-effect of deallocation)." [AppKit Release Notes for macOS 10.13](https://developer.apple.com/library/archive/releasenotes/AppKit/RN-AppKit/) – Willeke Oct 12 '18 at 15:37

1 Answers1

2

Thanks @sdarlington and Willeke for very helpful answers. I finally found and fixed the problem. I did have to use the caveman approach and gradually remove stuff from a crashing window (as you rightly identified Stephen). Turns out it was a legacy retain/release issue that none of Xcode's diagnostics was catching. I inherited an old graphics framework that doesn't use ARC. It declares ivars like this:

@interface ColourFiller : NSObject
{
    NSColor*            m_PrimaryColour;
    NSColor*            m_SecondaryColour;
}
...
@end

then sets them like this in its init method:

m_PrimaryColour = [NSColor colorWithCalibratedRed:1 green:1 blue:1 alpha:1];
m_SecondaryColour = [NSColor colorWithCalibratedRed:0 green:0 blue:0 alpha:1];

Note the lack of manual retain. So I added one, and all is well:

m_PrimaryColour = [[NSColor colorWithCalibratedRed:1 green:1 blue:1 alpha:1] retain];
m_SecondaryColour = [[NSColor colorWithCalibratedRed:0 green:0 blue:0 alpha:1] retain];

I have no idea why Xcode wasn't flagging this, or indeed why all previous builds/xcode versions were running fine. This code has happily existed without symptoms for years. Some library changes must have been made by Apple in Xcode 9 that finally exposed it.

Thanks again for your help - I can now progress to Xcode 10 and Mojave.

SaxmanBob
  • 31
  • 4