GLKit を使用して IPhone OpengGL アプリを開発しており、次のコードを使用してテクスチャを作成しています。
NSRange dotRange = [textureFileName rangeOfString:@"." options:NSCaseInsensitiveSearch];
if (dotRange.location == NSNotFound){
NSLog(@"OpenGLDRawMaterial:createTextureFromFileName, incorrect file name given in inputs");
return nil;
}
GLKTextureInfo *newTexture;
NSError *error = nil; // stores the error message if we mess up
NSString *bundlepath = [[NSBundle mainBundle] pathForResource:[textureFileName substringToIndex:dotRange.location]
ofType:[textureFileName substringFromIndex:(dotRange.location+1)]];
newTexture = [GLKTextureLoader textureWithContentsOfFile:bundlepath options:[NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:GLKTextureLoaderOriginBottomLeft] error:&error];
メインスレッドで動作する限り、コードは非常にうまく機能します。ワーカースレッドで機能させようとするたびに、次のメッセージが表示されます。
"2013-03-04 02:09:01.528 Puppeteer[7063:1503] イメージからのテクスチャの読み込み中にエラーが発生しました: エラー Domain=GLKTextureLoaderErrorDomain Code=17 "操作を完了できませんでした。(GLKTextureLoaderErrorDomain エラー 17)" UserInfo=0x1c5977e0 "
グランドセントラルディスパッチキューに使用しているコードは次のとおりです。
dispatch_queue_t backgroundQueue = dispatch_queue_create("loadPlayViewBackgroundTexture", 0);
dispatch_async(backgroundQueue, ^{
[self createTexturesForPlayView]; // method calling texture creation
dispatch_async(dispatch_get_main_queue(), ^{
});
});
dispatch_release(backgroundQueue);
この問題を解決し、テクスチャをバックグラウンドでロードする方法についての洞察やアイデアがあれば、私は非常に感謝しています:) Cheers, Stéphane