开发者

NSThread called second time (after first didn't finish) get "EXC_BAD_ACCESS"

开发者 https://www.devze.com 2023-01-15 07:32 出处:网络
I have a cover flow and it has 3 different image sets. One of them needs to be generated and I have been trying to get it populated with a thread for larger selections of images.

I have a cover flow and it has 3 different image sets. One of them needs to be generated and I have been trying to get it populated with a thread for larger selections of images.

Here is a bit of my code:

- (void) startSongThread {
    [NSThread detachNewThreadSelector:@selector(songThreadMain) toTarget:self withObject:nil];   
}

- (void) songThreadMain {

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

    int i = 0;

    while(i < [items count] && ![[NSThread currentThread] isCancelled]) {

        NSNumber *nsInt = [NSNumber numberWithInt:i];
        if(![addedSongIndexes containsObject:nsInt]) [sel开发者_JAVA技巧f setSongImage:nsInt];
        i++;

    }

    [pool release];

}

- (void) stopSongThread {
    if(![[NSThread currentThread] isCancelled]) [[NSThread currentThread] cancel];    
}

The stopSongThread method gets called when the images change from one type to another.

If I load all the main images, switch image sets then switch back to the main set I always get EXC_BAD_ACCESS.

I tried to alloc the thread, but it only works once as well .. If i let it load and don't try to stop it, it works great.

Any help wuld be great, thanks!


This isn't a complete answer. But I've decided to switch my game plan a little on how I was using the thread.

Basically I crated a new empty class with a thread just to generate the thumbs. When I'm populating the cover flow I check to see if the thread class has built an image. This seems to work so far I will continue to tweak it until its super smooth!

Thanks

0

精彩评论

暂无评论...
验证码 换一张
取 消