此函数在我的 GLKViewController 中,在创建 EAGLContext 并设置当前且视图加载之前调用:
-(GLint)prepareTextureWithImage:(UIImage *)image andName:(NSString *)name
{
NSLog(@"[INFO] image has CGImage %@", image.CGImage);
NSLog(@"[INFO] image has size %f, %f", image.size.width, image.size.height);
NSDictionary * options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES],
GLKTextureLoaderOriginBottomLeft,
nil];
NSError *error;
GLKTextureInfo *texture = [GLKTextureLoader textureWithCGImage:image.CGImage options:options error:&error];
if (error) {
NSLog(@"[ERROR] Error loading texture from image: %@",error);
return -1;
}
else {
NSLog(@"[INFO] GlkitViewController prepared texture %@", texture);
[textures setObject:texture forKey:name];
return texture.name;
}
}
这是从 Titanium 模块的 TiViewProxy 调用的,如下所示:
-(void)prepareTexture:(id)args
{
ENSURE_UI_THREAD_1_ARG(args);
ENSURE_SINGLE_ARG(args,NSDictionary);
NSString *name = [TiUtils stringValue:[args objectForKey:@"name"]];
TiBlob *blob = [args objectForKey:@"image"];
UIImage *image = [blob image];
[image retain];
GlkitOverlayView *overlayView = (GlkitOverlayView *)view;
GLKitViewController *vc = (GLKitViewController *)overlayView.viewController;
NSLog(@"[INFO] using viewcontroller %@", vc);
[vc prepareTextureWithImage:image andName:name];
}
我在控制台中得到了适当的输出:
[INFO] using viewcontroller <GLKitViewController: 0xd5b68a0>
[INFO] image has CGImage <CGImage 0xd5c6d40>
[INFO] image has size 64.000000, 64.000000
但这是崩溃前的最后一个输出。
为什么对 GLKTextureLoader 的调用会崩溃?