从 viewDidLoad 加载纹理效果很好。但是,如果我尝试从GLKViewController
更新中加载它们,我会收到错误消息。我这样做是因为我想在不改变视图的情况下交换新的背景纹理。
这在上次升级之前有效。也许我在时机上很幸运。我怀疑它失败是因为某个线程很忙还是什么?
这是完整的错误。
Domain=GLKTextureLoaderErrorDomain Code=8 "操作无法完成。(GLKTextureLoaderErrorDomain error 8.)" UserInfo=0x10b5b510 {GLKTextureLoaderGLErrorKey=1282, GLKTextureLoaderErrorKey=OpenGL 错误}
所以问题是,我可以安全地从GLKViewController
更新函数中加载纹理吗?还是我需要重新考虑我的方法并重新加载整个视图或其他什么?
这是我的功能:
-(void) LoadTexture:(NSString *)texture textureInfo:(GLKTextureInfo**)textureInfo
{
NSString *path = [[NSBundle mainBundle] pathForResource:texture ofType:@"png"];
NSError *error = nil;
(*textureInfo) = [GLKTextureLoader textureWithContentsOfFile:path options:nil error:&error];
NSLog(@"path %@", path);
if(!(*textureInfo))
{
NSLog(@"Failed to load texture %@ %@", texture, error);
}
else
{
NSLog(@"LOADED Texture %@ !!! YAY!!! ", texture);
}
}
谢谢,
大卫