Opengl es 为什么对GLKTextureLoader的调用会崩溃?

Opengl es 为什么对GLKTextureLoader的调用会崩溃?,opengl-es,glkit,titanium-modules,Opengl Es,Glkit,Titanium Modules,此函数位于我的GLKViewController中,在创建EAGLContext并将其设置为Current之后以及在加载视图之前调用: -(GLint)prepareTextureWithImage:(UIImage *)image andName:(NSString *)name { NSLog(@"[INFO] image has CGImage %@", image.CGImage); NSLog(@"[INFO] image has size %f, %f", image

此函数位于我的GLKViewController中,在创建EAGLContext并将其设置为Current之后以及在加载视图之前调用:

-(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;
    }
}
这是从钛模块的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
[INFO]使用viewcontroller
[信息]图像具有CGImage
[信息]图像大小为64.000000,64.000000
但这是崩溃前的最后一次输出


为什么对GLKTextureLoader的调用会崩溃?

我不确定同步调用为什么会崩溃,但我的函数的这个异步版本工作得很好——纹理加载并在glview中正确显示

-(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;

    GLKTextureLoader *textureloader = [[GLKTextureLoader alloc] initWithSharegroup:self.context.sharegroup];
    GLKTextureInfo *myTexture;
    [textureloader textureWithCGImage:image.CGImage options:nil queue:nil completionHandler:^(GLKTextureInfo *textureInfo, NSError *error) {

        if(error) {
            NSLog(@"[ERROR] Error loading texture from image: %@",error);
        }
        else {
            NSLog(@"[INFO] GlkitViewController prepared texture %@", textureInfo);
            [textures setObject:textureInfo forKey:name];
        }
    }];
}