У меня включен автоматический подсчет ссылок и зомби ...
Я продолжаю получать EXC BAD ACCESS к различным точкам кода, большую часть времени без дополнительной информации, поступающей от зомби.
Цель - нарисовать прямоугольник на экране с текстурой, загруженной из изображения. Это действительно работает! Но часто он поврежден (изображение и векторы), а затем часто я просто получаю предупреждение о плохом доступе.
У меня такая структура ...
Объявление класса делегата приложения:
GWBackgroundScene* background;
EAGLContext *context;
GLKView *view;
GLKViewController *controller;
UIWindow *window;
, а затем окно превращается в свойство и синтезируется.
Окончание запуска с параметрами:
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 вызывает функцию с именем render в классе, которая затем вызывает [background render];
Мой класс 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);
Каковы очевидные проблемы с памятью с тем, что я делаю?
Большое спасибо