GLKTextureLoader textureWithContentsOfFile: fails

2019-09-05 04:17发布

I am using GLKTextureLoader to load image textures into a sprite.

When I run the following code and load two sprites...

NSString *pathToImage = [NSString stringWithFormat:@"%@/defaultProject/images/%@", [Util applicationDocumentsDirectory], fileName];
NSLog(@"path: %@", pathToImage);
self.textureInfo = [GLKTextureLoader textureWithContentsOfFile:pathToImage options:options error:&error];
if (self.textureInfo == nil) 
{
    NSLog(@"Error loading file: %@", [error localizedDescription]);
    return;
}

... it fails for the first image but not for the second.

The error is:

Error loading file: The operation couldn’t be completed. (GLKTextureLoaderErrorDomain error 12.).

Does anyone know what this error means? I haven't found any information on code 12.

Thanks in advance!

1条回答
唯我独甜
2楼-- · 2019-09-05 04:31

Error code 12 means GLKTextureLoaderErrorDataPreprocessingFailure as per (Apple Docs)

I think cause of error is a file corruption. Try to re-save your corrupted image.

查看更多
登录 后发表回答