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 > NSMovie not thread-safe?

NSMovie not thread-safe?
Thread Tools
Mac Elite
Join Date: Feb 2001
Location: adrift in a sea of decadent luxury and meaningless sex
Status: Offline
Reply With Quote
Oct 6, 2002, 12:47 PM
 
ok, I have a method that opens a bunch of movie files, and I want it in it's own thread. It basically does this

- (void) openMovieAtPath:(NSURL *)path
{
NSMovie *aMovie;
aMovie = [[NSMovie alloc] initWithURL:path byReference:NO];
//more here
}

And when I just call this method (on MPEG movies) it works fine. But if I give it it's own thread like this (just to make sure I'm not doing it wrong)

[NSThread detachNewThreadSelector:@selector(openMovieAtPath: ) toTarget:self withObject:path];

MPEG movies are initialized to 0x0 (nil). Other movies still work (mov, avi, mp4, jpg, txt, etc)

The function also has an
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[pool release];
and a simple NSLock, if that's important.

Does anyone know what's the deal here?

edit: damn you, smilies!
blackmail is such an ugly word. I prefer extortion. the X makes it sound cool
     
Professional Poster
Join Date: Apr 2001
Location: Long Beach, CA
Status: Offline
Reply With Quote
Oct 6, 2002, 11:02 PM
 
The problem may be that you are trying to access the movie before the movie has finished opening.

Why would you want something this simple in its own thread? You will need to wait for the file to finish being open anyway before you can even begin to access it from another thread. Why not just keep it in the main thread?

ACSA 10.4/10.3, ACTC 10.3, ACHDS 10.3
     
Mac Elite
Join Date: Feb 2001
Location: adrift in a sea of decadent luxury and meaningless sex
Status: Offline
Reply With Quote
Oct 7, 2002, 02:41 AM
 
well, I don't think that's the problem. The symptom I see is in the debugger, when directly after the movie is opened, the aMovie variable is set to nil (also the movie doesn't open).

The reason I want it threaded is because after I open the movie I extract a lot of data from it and do some computations, and if I open a folder of 50 movies, it takes a while even on my dual gig machine, and I want to have a cancel button so if you accidentally click on a folder with 10,000 text files, you don't have to force quit the app or wait 10 minutes while it opens them all as movies. Is there any way to get a click from the user if I'm working in the main thread? I didn't think there was....

anyway, it's weird that the problem is only with mpegs and not other kinds of movies or non-movies. Anyone know why, or have a way for me to receive a cancel event from the gui while the main thread is opening mpegs? I'm wary of multiple threads, so I would rather not open the mpeg in the main thread and then spawn a new thread for each mpeg to do the processing. I want to keep it as one main thread (with cancel button) and one "opening files" thread.

thanks
blackmail is such an ugly word. I prefer extortion. the X makes it sound cool
     
Junior Member
Join Date: Oct 2001
Status: Offline
Reply With Quote
Oct 7, 2002, 02:27 PM
 
You could put the cancel button in it's own thread.

type R 503
I be that insane n***a from the psycho ward.
     
Mac Elite
Join Date: Feb 2001
Location: adrift in a sea of decadent luxury and meaningless sex
Status: Offline
Reply With Quote
Oct 7, 2002, 07:34 PM
 
how do you do that?
blackmail is such an ugly word. I prefer extortion. the X makes it sound cool
     
Junior Member
Join Date: Oct 2001
Status: Offline
Reply With Quote
Oct 8, 2002, 05:20 PM
 
In your openMovieAtPath: method you need to put:


NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

// execute our code here

[pool release];

This creates a stack for objects in your thread.

type R 503
I be that insane n***a from the psycho ward.
     
Mac Elite
Join Date: Feb 2001
Location: adrift in a sea of decadent luxury and meaningless sex
Status: Offline
Reply With Quote
Oct 8, 2002, 07:29 PM
 
yes, I already had the autorelease pool (it's mentioned at the bottom of my first post)

can anyone tell me how to receive button clicks from a new thread? I didn't think that was possible
blackmail is such an ugly word. I prefer extortion. the X makes it sound cool
     
Junior Member
Join Date: Oct 2001
Status: Offline
Reply With Quote
Oct 8, 2002, 07:55 PM
 
Sorry I missed the end of your message. I think I got it. When a thread is created it runs. Since you are passing in path at the creation it tries to load the uninitialized path. This would result in movie being set to nil. You need to specify a path or handle if path is nil in your openmovie function.


type R 503
I be that insane n***a from the psycho ward.
     
Mac Elite
Join Date: Feb 2001
Location: adrift in a sea of decadent luxury and meaningless sex
Status: Offline
Reply With Quote
Oct 8, 2002, 11:48 PM
 
That's a good one, but I don't think that's it. First of all, all media files work except for mpeg. Secondly, the path isn't uninitialized when the thread is created; the thread is created with a valid path string in the variable "path" of the detachNewThread method (the last argument "withObject"), and when I watch the new thread in the debugger, I can see the correct path for the mpeg as it's trying to open the NSMovie with it. So I'm pretty sure the path is not the source of the problem
blackmail is such an ugly word. I prefer extortion. the X makes it sound cool
     
   
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 01:53 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