Why is my application crashing in QuickDraw when I'm not using it?

Q: Why is my application crashing in QuickDraw when I'm not using it?

A: The most likely explanation is that you are experiencing an overwritten closed port problem.

This problem affects both Carbon and Cocoa applications.

System frameworks like the HIToolbox, QuickTime, Print and others still need to make QuickDraw calls for compatibility reasons even when your application does not use QuickDraw directly. Those calls (for instance PenNormal) depend on a valid current GrafPort. If the application does not set a current port then QuickDraw provides a fallback GrafPort to prevent crashes.

To work around this problem, locate in the back trace of the crash log the last call made by your application to any function of a system framework and add a SetPort( NULL ); statement prior to that call.

Although it may seem counterintuitive to set the current port to NULL when past experience and recommendations were exactly the opposite, SetPort does not actually set the current port to NULL but instead sets the current port to an internal valid fallback port to make sure that QuickDraw doesn't crash when the previous current port gets disposed and a new current port cannot be determined.

If the last system framework call that your application makes before crashing is RunApplicationEventLoop or [NSApplication run] (and equivalent calls), that probably means that the original problem has been compounded by a long succession of successful QuickDraw calls.

In that case, the workaround would be to add a SetPort( NULL ); statement after each DisposeWindow (and equivalent calls).

It would also be beneficial that you report the problem to Apple with the BugReporter so that we can investigate and eliminate as much offending code as possible.

Document Revision History

DateNotes
2006-11-13First Version

Posted: 2006-11-13


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.