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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:44:18+00:00 2026-06-15T23:44:18+00:00

I hope I’m not repeating an existing question but I’m having some issues retaining

  • 0

I hope I’m not repeating an existing question but I’m having some issues retaining a data array in a Objective-C with OpenGL ES. Here’s the deal:

I have this class with the following property:

@property GLfloat* data;

this class has a method that finishes with:

-(void)loadObj {
     (...)
     GLfloat glData[n];
     (...) //populate glData array
     self.data = glData;
     NSLog(@"%i", self.data[1]) 
 }

Back on my main, I create an instance of said class and proceed to call the loadObj function.

loader = [[ObjLoader alloc] init];
[loader loadObj];
data = loader.data;
NSLog(@"%i", data[1]) 

Unfortunately it’s data array has lost it’s information for some reason

On the first print the values are all there, the way they’re intended. On the second though, almost none of the data is retained.

Is there any way I can keep this from happening? I’d like to point out that using NSMutable arrays is out of the question, because I need the data type to be GLfloat

Thanks in advance

  • 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-15T23:44:18+00:00Added an answer on June 15, 2026 at 11:44 pm

    Since a GLfloat is a C typedef that has nothing to do with Objective-C you can’t retain it by using any Objective-C feature.

    The problem in your example is that GLfloat glData[n] is an array with automatic allocation onto the stack. When the function in which you declared it returns to the caller, the data pointed is no longer valid.

    What you should do it managing the memory by yourself:

    -(void)loadObj {
         (...)
         GLfloat *glData = calloc(n, sizeof(GLfloat));
         (...) //populate glData array
         self.data = glData;
     }
    

    In this way you are allocating the array in the heap and it won’t become invalid when function exits. Mind that this memory is not managed by Objective-C so you are responsible of releasing it when needed, eg

    -(void)dealloc {
      free(self.data);
      [super dealloc];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hope this question is not stupid since I am an amateur web designer. I
Hope you're having a good Friday and stuff... okay, so here's my question: All
Hope it's not against rules to post more than 1 question per page. I
Hope you can help me with this problem. I am having issues with the
Hope this is not a stupid question. For Regression testing, I wrote a small
Hope my question does not pose as too wide. So I try to frame
Hope someone can advise. Having issues trying to remove a row once a link
Hope that someone can share their experience with some of the latest emerging backbone.js
Hope you all are fine and rocking your code editors. My question is how
hope someone can answer this. Here is some sample code. namespace std { #ifdef

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.