ios - Can't figure out what this objective c Bad Access is -



ios - Can't figure out what this objective c Bad Access is -

i copied code straight out of book , don't know problem is. getting exc bad access runtime error on lastly line glteximage2d called. think it's coming pixeldata pointer. don't know problem is. if geniuses out there help i'd appreciate it. using xcode 6.

#import "texturehelper.h" @implementation texturehelper -(void) createtexturefromimage: (nsstring *) picname{ uiimage *pic = [uiimage imagenamed:picname]; int scalefactor = 1; float iosversion = [[[uidevice currentdevice] systemversion] floatvalue]; if(iosversion >= 4.0){ if(pic.scale >= 2){ scalefactor = pic.scale; } } if(pic){ //set texture dimentions width = pic.size.width * scalefactor; height = pic.size.height * scalefactor; /* if ((width & (width-1)) !=0 || (height & height-1)) != 0 || width> 2048 || height > 2048) { nslog(@"error:%@ width and/or height not powerfulness of 2 or > 2048!", picname); } */ glubyte *pixeldata = [self generatepixeldatafromimage:pic]; [self generatetexture:pixeldata]; int memory = width*height*4; nslog(@"%@, size:%i kb, id:%i", picname, memory/1024, textureid); free(pixeldata); }else{ nslog(@"error:%@ not found, texture not created.",picname); } } -(glubyte *) generatepixeldatafromimage: (uiimage *) pic{ glubyte *pixeldata = (glubyte *) calloc(width * height *4, sizeof(glubyte)); cgcolorspaceref imagecs = cgimagegetcolorspace(pic.cgimage); cgbitmapinfo bitmapinfo = (cgbitmapinfo) kcgimagealphapremultipliedlast; cgcontextref gc = cgbitmapcontextcreate(pixeldata, width, height, 8, width*4, imagecs, bitmapinfo); cgcontextdrawimage(gc, cgrectmake(0, 0, width, height), pic.cgimage); cgcontextrelease(gc); homecoming pixeldata; } -(void) generatetexture: (glubyte * ) pixeldata{ //create gl texture glgentextures(1, &textureid); glbindtexture(gl_texture_2d, textureid); gltexparameteri(gl_texture_2d, gl_texture_min_filter, gl_linear); gltexparameteri(gl_texture_2d, gl_texture_mag_filter, gl_linear_mipmap_linear); gltexparameteri(gl_texture_2d, gl_texture_wrap_s, gl_clamp_to_edge); gltexparameteri(gl_texture_2d, gl_texture_wrap_t, gl_clamp_to_edge); glteximage2d(gl_texture_2d, 0, gl_rgba, width, height, 0, gl_rgba, gl_unsigned_byte, &pixeldata); } @end

i fixed because stupidly included & symbol in pixeldata.

ios objective-c opengl-es

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -