This function is in my GLKViewController, called after a EAGLContext has been created and setCurrent and before the view has loaded:
-(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;
}
}
This is being called from a Titanium module's TiViewProxy like this:
-(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];
}
I'm getting the appropriate output in the console:
[INFO] using viewcontroller <GLKitViewController: 0xd5b68a0>
[INFO] image has CGImage <CGImage 0xd5c6d40>
[INFO] image has size 64.000000, 64.000000
But that is the last output before a crash.
Why is this call to GLKTextureLoader crashing?
I'm not sure why the synchronous call was crashing, but this async version of my function is working nicely -- textures loading and showing correctly in the 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];
}
}];
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.