我已經自動引用計數和殭屍啓用...常數,隨機和莫名的(對我來說,反正)EXC BAD目標C中的應用程序訪問
我不斷收到代碼EXC錯誤訪問到不同的點,最的時間沒有進一步的信息來自殭屍。
目標是在屏幕上繪製一個矩形,其中包含從圖像加載的紋理。它確實有效!但通常它被破壞了(圖像和矢量),然後我經常得到不良的訪問警告。
我有這種結構...
應用程序委託類聲明:
GWBackgroundScene* background;
EAGLContext *context;
GLKView *view;
GLKViewController *controller;
UIWindow *window;
,然後窗被製作成一個屬性和合成。
DID的完成啓動與選項:
context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
[EAGLContext setCurrentContext:context];
view = [[GLKView alloc] initWithFrame:[[UIScreen mainScreen] bounds] context:context];
view.delegate = self;
controller = [[GLKViewController alloc] init];
[controller shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationPortrait];
controller.delegate = self;
controller.view = view;
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = controller;
[self.window makeKeyAndVisible];
background = [[GWBackgroundScene alloc] initWithImage:[UIImage imageNamed:@"DSC_0059.jpg"]];
的AppDelegate中充當一個OpenGL委託和OpenGL呼叫被叫的類,然後調用[背景呈現]「呈現」功能;
我GWBackgroundScene類:
@interface GWBackgroundScene : NSObject
{
GLKTextureInfo *texture;
NSMutableData* vertexData;
NSMutableData* textureCoordinateData;
}
@property(readonly) GLKVector2 *vertices;
@property(readonly) GLKVector2 *textureCoordinates;
-(void) render;
-(id) initWithImage: (UIImage*)image;
初始化有:
self = [super init];
if(self != nil)
{
texture = [GLKTextureLoader textureWithCGImage:image.CGImage options:[NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:GLKTextureLoaderOriginBottomLeft] error:&error];
vertexData = [NSMutableData dataWithLength:4];
textureCoordinateData = [NSMutableData dataWithLength:4];
self.vertices[0] = GLKVector2Make(-2.0,3.0);
...
self.textureCoordinates[0] = GLKVector2Make(0,0);
...
}
return self;
,有這兩個函數來處理矢量和紋理信息
- (GLKVector2 *)vertices {
return [vertexData mutableBytes];
}
- (GLKVector2 *)textureCoordinates {
return [textureCoordinateData mutableBytes];
}
,然後渲染功能(OpenGL通過它的委託(應用程序委託)調用它:
質地:
GLKBaseEffect *effect = [[GLKBaseEffect alloc] init]; effect.texture2d0.envMode = GLKTextureEnvModeReplace; effect.texture2d0.target = GLKTextureTarget2D; effect.texture2d0.name = texture.name;
self.vertices:
glVertexAttribPointer(GLKVertexAttribPosition, 2, GL_FLOAT, GL_FALSE, 0, self.vertices);
self.textureCordinates
glVertexAttribPointer(GLKVertexAttribTexCoord0, 2, GL_FLOAT, GL_FALSE, 0, self.textureCoordinates);
什麼是我在做什麼顯而易見的內存問題?
非常感謝
你的回溯是什麼意思? –
@CarlNorum - 你通常不會用EXC_BAD_ACCESS獲得回溯。 –
@Hot Licks,你應該可以在*任何*時間回溯,所以我很確定你可以。 –