Multithreading NSThread第二次调用(在第一次未完成后)get;EXC“不良访问”;
我有一个封面流程,它有3个不同的图像集。其中一个需要生成,我一直在尝试让它填充一个线程,用于更大的图像选择 下面是我的一些代码:Multithreading NSThread第二次调用(在第一次未完成后)get;EXC“不良访问”;,multithreading,xcode,exc-bad-access,Multithreading,Xcode,Exc Bad Access,我有一个封面流程,它有3个不同的图像集。其中一个需要生成,我一直在尝试让它填充一个线程,用于更大的图像选择 下面是我的一些代码: - (void) startSongThread { [NSThread detachNewThreadSelector:@selector(songThreadMain) toTarget:self withObject:nil]; } - (void) songThreadMain { NSAutoreleasePool *pool =
- (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]) [self setSongImage:nsInt];
i++;
}
[pool release];
}
- (void) stopSongThread {
if(![[NSThread currentThread] isCancelled]) [[NSThread currentThread] cancel];
}
-(空)启动松线程{
[NSThread detachNewThreadSelector:@selector(songThreadMain)toTarget:self with Object:nil];
}
-(无效)主管道{
NSAutoreleasePool*池=[[NSAutoreleasePool alloc]init];
int i=0;
而(i<[items count]&&![[NSThread currentThread]已取消]){
NSNumber*nsInt=[NSNumber numberwhithint:i];
如果(![addedSongIndexes containsObject:nsInt])[self-setSongImage:nsInt];
i++;
}
[池释放];
}
-(无效)止动螺纹{
如果(![[NSThread currentThread]被取消][[NSThread currentThread]取消];
}
当图像从一种类型更改为另一种类型时,将调用stopSongThread方法
如果我加载所有主图像,切换图像集,然后切换回主图像集,我总是可以访问EXC_BAD_
我试着分配线程,但它也只能工作一次。。如果我让它加载,而不试图阻止它,它工作得很好
任何帮助都会很好,谢谢 这不是一个完整的答案。但是我决定改变一下我的游戏计划,我是如何使用线程的 基本上,我用一个线程创建了一个新的空类来生成thumbs。当我填充cover流时,我会检查thread类是否构建了一个映像。这似乎工作到目前为止,我会继续调整它,直到它超级顺利
谢谢您在哪一行收到错误访问?每次都不同,这取决于我切换并尝试停止线程的时间。嗯,仍然有问题。当我需要执行以下代码行时,它似乎失败:[thisPage.layer renderInContext:ctx];