Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Loopy

Loopy
Thread Tools
Admin Emeritus
Join Date: Oct 2000
Location: Boston, MA
Status: Offline
Reply With Quote
Jan 23, 2001, 11:04 AM
 
In GLUT, you can make a draw loop pretty easily...
How can I make an infinite loop in Cocoa, while keeping the functionality of the buttons and UI?

I want a continuous rotational display, but to have sliders & buttons control the rotation. I can pretty much only trigger my drawing function in response to buttons.
"Against stupidity, the gods themselves contend in vain" (Schiller)
     
Senior User
Join Date: Nov 2000
Status: Offline
Reply With Quote
Jan 23, 2001, 12:22 PM
 
You just need a thread. Try looking at the documentation on NSThread. I'm still learning C/Obj-C so someone else may be able to help you more. It's a start though.

If nothing else it moves your question to the top for a few.
     
Mac Enthusiast
Join Date: Feb 2000
Location: Storrs,Connecticut, USA
Status: Offline
Reply With Quote
Jan 23, 2001, 04:56 PM
 
No not NSThread! Use + (void)detachDrawingThread SEL)selector toTarget id)target withObject id)argument in NSApplication or your program will probably crash when you try to update the interface from another thread.

[This message has been edited by Dalgo (edited 01-23-2001).]
     
Admin Emeritus
Join Date: Oct 2000
Location: Boston, MA
Status: Offline
Reply With Quote
Jan 24, 2001, 08:28 AM
 
I'll try that. Can I use POSIX threads, just out of curiousity?
"Against stupidity, the gods themselves contend in vain" (Schiller)
     
Admin Emeritus
Join Date: Oct 2000
Location: Boston, MA
Status: Offline
Reply With Quote
Jan 24, 2001, 08:30 AM
 
I'll try that. Can I use POSIX threads, just out of curiousity?
"Against stupidity, the gods themselves contend in vain" (Schiller)
     
Mac Enthusiast
Join Date: Feb 2000
Location: Storrs,Connecticut, USA
Status: Offline
Reply With Quote
Jan 24, 2001, 08:40 AM
 
The rason for using that method in NSApplication to update the interface vs. just using NSThread is because it creates some locks so that your second thread isn't trying to update the interface at the same time that another thread is. If you can figure out some way to make the locks required to update the interface from a POSIX thread then there is no reason why you can't.

However, if you can't figure out how to make those locks (I have no idea how to do that, I think they are private anyway) then there is another possibility. It is possible, and also very likely, that by default, none of the methods in appkit are safe to update the interface but when you make a thread from that method in NSApp they all become thread safe in that respect and stay that way. In order to test that you could spin off a drawing thread in order to do some menial task and then use your POSIX threads to do whatever you want in your program to play with the interface. If you don't have any probelms then it's pretty safe to assume that the interface stays thread safe after the first drawing thread is spun off.
     
Admin Emeritus
Join Date: Oct 2000
Location: Boston, MA
Status: Offline
Reply With Quote
Jan 24, 2001, 09:51 AM
 
Hmmm... Apple's documentation on detachDrawingThread: is non-Existant, as far as I can tell. How do I use it? Or, if there are any example applications, that would be awsome.

Thanks.
"Against stupidity, the gods themselves contend in vain" (Schiller)
     
Mac Enthusiast
Join Date: Feb 2000
Location: Storrs,Connecticut, USA
Status: Offline
Reply With Quote
Jan 24, 2001, 11:35 AM
 
Just use it in the same way that you'd use the NSThread method to make a new thread. One thing to keep in mind, if you don't already know, the method is in NSApplication but you might have to use NSApp as the object (as is true with many things in NSApplication). I don't remember offhand; I'm not at my computer now so I don't know. If using NSApplication as the object doesn't work then use NSApp or vice versa.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 12:09 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2