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 8976999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:16:27+00:00 2026-06-15T19:16:27+00:00

OK, I’m hitting a wall here. I don’t know why my Xcode 4.5.2 is

  • 0

OK, I’m hitting a wall here.

I don’t know why my Xcode 4.5.2 is saying I am using 4.16 GB of memory before crashing:

ExampleEngine(11672,0xac70f2c0) malloc: *** mmap(size=4160753664) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug

I ran my OpenGL ES application using Instruments – Leaks & Allocations. It shows that the total amount of allocation memory I used was 1.46 MB Live Bytes.

I am trying to follow an OpenGL ES tutorial by Ian Terrel:

http://games.ianterrell.com/how-to-draw-2d-shapes-with-glkit-part-2/

I am stuck of the last part the EERegularPolygon class (all the previous shapes like Triangle, Rectangle, Elipse worked fine). My code is like this (slightly different to his because I am using Xcode 4.5.2’s auto @synthesize):

// EERegularPolygon.h file
#import "EEShape.h"

@interface EERegularPolygon : EEShape

@property (readonly) int numSides;
@property (nonatomic) float radius;

-(id)initWithNumSides:(int)numSides;

@end


// EERegularPolygon.m file
#import "EERegularPolygon.h"

#define M_TAU (2 * M_PI)

@implementation EERegularPolygon

-(id)initWithNumSides:(int)numSides
{
    self = [super init];

    if(self)
    {
        _numSides = numSides;
    }

    return self;
}

-(void)updateVertices
{    
    for(int i = 0; i < self.numSides; i++)
    {
        float theta = ((float) i) / self.numSides * M_TAU;
        self.vertices[i] = GLKVector2Make(cos(theta) * self.radius, sin(theta) * self.radius);
    }
}

-(void)setRadius:(float)radius
{
    _radius = radius;

    [self updateVertices];
}

@end


// HexagonScene.h file
#import "EEScene.h"
#import "EERegularPolygon.h"

@interface HexagonScene : EEScene
{
    EERegularPolygon *polygon;
}

@end



// HexagonScene.m file
#import "HexagonScene.h"

@implementation HexagonScene

-(id)init
{
    self = [super init];

    if(self)
    {
        polygon = [[EERegularPolygon alloc] initWithNumSides:6];
        polygon.radius = 1;
    }

    return self;
}

-(void)render
{
    [super render];

    [polygon render];
}

@end



// AppDelegate DidFinishLaunchingWithOptions: method
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    EAGLContext *context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
    [EAGLContext setCurrentContext:context];

    GLKView *view = [[GLKView alloc] initWithFrame:[[UIScreen mainScreen] bounds] context:context];
    view.delegate = self;

    GLKViewController *controller = [[GLKViewController alloc] init];
    controller.delegate = self;
    controller.view = view;

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.rootViewController = controller;
    [self.window makeKeyAndVisible];

    scene = [[HexagonScene alloc] init];
    scene.left = -3;
    scene.right = 3;
    scene.bottom = -2;
    scene.top = 2;
    scene.clearColor = GLKVector4Make(0.25, 0.25, 0.25, 1.0);


    return YES;
}

Anyone got any ideas why Xcode is reporting 4.16 GB of memory was trying to be allocated ?

I tried manually writing the get and set method for the EERegularPolygon class too but that also didn’t work.

  • 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-06-15T19:16:28+00:00Added an answer on June 15, 2026 at 7:16 pm

    OK, I have magically stumbled upon the solution after trying to debug the problem.

    First and foremost, the two changes:

    1) I forgot to override the following method:

    -(int)numVertices 
    { 
        return self.numSides 
    }
    

    2) The one single line that stopped the app from crashing and show the hexagon shape was this NSLog() line:

    -(id)initWithNumSides:(int)numSides
    {
        self = [super init];
    
        if(self)
        {
            _numSides = numSides;
    
            // ---------------------------------
            // IF THIS LINE IS COMMENTED OUT,
            // THE APP CRASHES, 
            //
            // BUT IF THE LINE IS NOT COMMENTED
            // THE APP WORKS, THE HEXAGON IS
            // RENDERED TO SCREEN AS DESIRED
            //
            // I WANT TO KNOW WHY :(
            // ---------------------------------
            NSLog(@"M_TAU = %lf", M_TAU);
        }
    
        return self;
    }
    

    There must be something I don’t understand about #define preprocessor directive not defined until it’s actually called in the above line of code.

    Can any C or Objective C guru please explain ?

    I’ll dig Google too to see if I can get an understanding why a #define fails to work until a NSLog is called in my above code.

    Unless it’s a bug with the compiler or Xcode, otherwise it seems absurd.

    EDIT

    OK, further discovery, it’s not that the #define was broken and that I needed to call the M_TAU constant like so in the init:

    NSLog(@"M_TAU = %lf", M_TAU);
    

    It seems I need to have a line of NSLog inside my init function for some odd reason, anything.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I know there's a lot of other questions out there that deal with this
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.

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.