• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Help with crash
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help with crash


  • Subject: Re: Help with crash
  • From: "John C. Randolph" <email@hidden>
  • Date: Wed, 12 Mar 2003 16:42:00 -0800

On Wednesday, March 12, 2003, at 03:48 PM, Gilbert Mackall wrote:

It's crashing in your Oscilloscope view drawing method.

Could it be possible that you're calling the drawing from your secondary thread?

Yes, I am. I take it that drawing from a secondary thread is a bad thing?

It's usually simpler to do all your drawing on the main thread, but you can draw from a secondary thread.

From the docs:

file:///Developer/Documentation/Cocoa/TasksAndConcepts/ ProgrammingTopics/Multithreading/Tasks/appkit.html

NSView

You can create, destroy, resize, move, and perform other operations with NSViews from different threads. The system ensures that all drawing is deferred while these operations occur (through the lockFocusIfCanDraw and unlockFocus methods). lockFocusIfCanDraw ensures that lockFocus and canDraw methods are called atomically. Subthread drawing, should look like this code fragment:

if ([aView lockFocusIfCanDraw]) {

/* Drawing operations */

[aView unlockFocus];
}


In a multithreaded application, the main thread is still responsible for redisplaying dirty views through the same process as a single-threaded application. The drawRect: method of every dirty view is called in the main thread. If the drawing needs to be done in another thread, the drawRect: method for the view should arrange for the secondary thread to do the drawing and not do any drawing in drawRect:.

If a secondary thread of an application wants to cause portions of the view to be redrawn on the main thread, the normal mechanisms work: setNeedsDisplay:, setNeedsDisplayInRect:, and setViewsNeedDisplay:. An explicit call to the NSView method display on a secondary thread will be treated as if it were a call to setNeedsDisplay: with an argument of YES, and the display will be done on the main thread.

The view systems graphics states (gstates) are per-thread. Using gstates in a multithreaded application improves drawing performance in a way similar to a single-threaded application. Use the public method gState to get at the gstate of the current thread.

HTH,

-jcr


John C. Randolph <email@hidden> (408) 974-8819
Sr. Cocoa Software Engineer,
Apple Worldwide Developer Relations
http://developer.apple.com/cocoa/index.html
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: Help with crash (From: Gilbert Mackall <email@hidden>)

  • Prev by Date: #define
  • Next by Date: Stripping HTML tags
  • Previous by thread: Re: Help with crash
  • Next by thread: Re: Help with crash
  • Index(es):
    • Date
    • Thread