Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6873045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:00:28+00:00 2026-05-27T04:00:28+00:00

I have Automatic Reference Counting and Zombies enabled… I keep getting EXC BAD ACCESS

  • 0

I have Automatic Reference Counting and Zombies enabled…

I keep getting EXC BAD ACCESS to different points in the code, most of the time with no further information coming from zombies.

The objective is to draw a rectangle to the screen with a texture on it that is loaded from an image. It does actually work! But often it is corrupted (the image and the vectors) and then often I just get the exc bad access warning.

I have this sort of structure…

App Delegate Class Declaration:

GWBackgroundScene* background;
EAGLContext *context;
GLKView *view;
GLKViewController *controller;
UIWindow *window;

and then window is made into a property and synthesized.

The did Finish Launching With Options:

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"]];

The AppDelegate acts as an OpenGL delegate and OpenGL calls a function called ‘render’ in the class which then calls [background render];

My GWBackgroundScene class:

@interface GWBackgroundScene : NSObject
{
    GLKTextureInfo *texture;
    NSMutableData* vertexData;
    NSMutableData* textureCoordinateData;
}  
@property(readonly) GLKVector2 *vertices;
@property(readonly) GLKVector2 *textureCoordinates;
-(void) render;
-(id) initWithImage: (UIImage*)image;

Initialises with:

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;

and has these two functions for dealing with the vector and texture information

- (GLKVector2 *)vertices {
  return [vertexData mutableBytes];
}
- (GLKVector2 *)textureCoordinates {
return [textureCoordinateData mutableBytes];
}

and then the render function (which is called by OpenGL via its delegate (the App delegate) uses:

  1. texture:

    GLKBaseEffect *effect = [[GLKBaseEffect alloc] init];
    effect.texture2d0.envMode = GLKTextureEnvModeReplace;
    effect.texture2d0.target = GLKTextureTarget2D;
    effect.texture2d0.name = texture.name; 
    
  2. self.vertices:

    glVertexAttribPointer(GLKVertexAttribPosition, 2, GL_FLOAT, GL_FALSE, 0, self.vertices);
    
  3. self.textureCordinates

    glVertexAttribPointer(GLKVertexAttribTexCoord0, 2, GL_FLOAT, GL_FALSE, 0, self.textureCoordinates);
    

What are the obvious memory issues with what im doing?

Thanks very much

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:00:29+00:00Added an answer on May 27, 2026 at 4:00 am

    You create an NSMutableData object with size 4 bytes, but the data type GLKVector2 is larger than 1 byte. If you’re expecting to store a few objects in there you should do

    vertexData = [NSMutableData dataWithLength:4 * sizeof(GLKVector2)];
    

    And similarly for textureCoordinateData.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a few questions about ARC (automatic reference counting): CFURLRef url = (__bridge
I ported some old code over to Objective-C ARC (Automatic Reference Counting) and it
I have a class that uses automatic reference counting. Within the class, I have
I have an objective-C program and I am using ARC (Automatic Reference Counting), it
Note: the below is using iOS with Automatic Reference Counting (ARC) enabled. I think
Automatic Reference Counting releases Objective-C objects that have been allocated. What about primitive variables
I have recently converted my project to use ARC (Automatic Reference Counting). It doesn't
I am new to Automatic Reference Counting with LLVM and Objective-C, and have a
I am getting this error that I can't figure out. error: Automatic Reference Counting
Thanks to this question/answer Automatic Reference Counting: Error with fast enumeration I resolved a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.