【问题标题】:Why is this call to GLKTextureLoader crashing?为什么对 GLKTextureLoader 的调用会崩溃?
【发布时间】:2013-04-26 12:51:42
【问题描述】:

此函数在我的 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 的调用会崩溃?

【问题讨论】:

    标签: opengl-es glkit titanium-modules


    【解决方案1】:

    我不确定为什么同步调用会崩溃,但我的函数的这个异步版本运行良好——纹理加载并在 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];
            }
        }];
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-20
      • 1970-01-01
      • 2013-01-31
      • 2014-05-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多