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

  • Home
  • SEARCH
  • 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 8208429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:21:55+00:00 2026-06-07T09:21:55+00:00

I want to make my vertex array dynamic. So that values would be added

  • 0

I want to make my vertex array dynamic. So that values would be added after every mouse event. When user drags his mouse I register mouse location coordinates. Coordinates is named ‘loc’. And when user drags his mouse the ‘loc’ value is updated. So I want that when ‘loc’ is updated, coordinates would be added to vertex array. Still I can only do that when ‘loc’ is updated it rebuilds vertex array, so my vertex array always has only one coordinates (current ‘loc’ value).

My vertex array values are stored in GLfloat:

GLfloat vertexes[] = { loc.x, loc.y };

‘loc’ is registered in - (void) mouseDragged:(NSEvent *)event by:

loc = [self convertPoint: [event locationInWindow] fromView:self];

Vertex array is drawn in - (void) drawMyShape by:

glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_FLOAT, 0, vertexes);
glPointSize(30);
glDrawArrays(GL_POINTS, 0, vertexCount);
glFlush();
glDisableClientState(GL_VERTEX_ARRAY);

- (void) drawMyShape is called after registering mouse events and adding them to GLfloat in - (void) mouseDragged:(NSEvent *)event by:

[self drawMyShape]

Current code:

in .h file:

NSMutableArray *vertices;
@property (nonatomic, retain) NSMutableArray *vertices;

in the beginning of .m file

@dynamic vertices;

in .m file in - (id)initWithCoder:(NSCoder *)coder

vertices = [[NSMutableArray alloc] init];

in .m file in - (void) mouseDragged:(NSEvent *)event

loc = [self convertPoint: [event locationInWindow] fromView:self];
NSValue *locationValue = [NSValue valueWithPoint:loc];
[vertices addObject:locationValue];`
[self addValuesToArray];

in .m file in - (void) addValuesToArray

int count = [vertices count] * 2; 
NSLog(@"count: %d", count); 
int currIndex = 0; 
GLfloat GLVertices[] = {*(GLfloat *)malloc(count * sizeof(GLfloat))}; 
for (NSValue *locationValue in vertices) { 
  NSValue *locationValue = [vertices objectAtIndex:currIndex++]; 
  CGPoint curLoc = locationValue.pointValue; 
  GLVertices[currIndex++] = curLoc.x; 
  GLVertices[currIndex++] = curLoc.y; 
} 

And it crashes on

NSValue *locationValue = [vertices objectAtIndex:i];

After crash in Log i see (removed some parts of log because they are not important I think):

sum: 2
*** -[__NSArrayM objectAtIndex:]: index 2 beyond bounds [0 .. 1]
sum: 3
*** -[__NSArrayM objectAtIndex:]: index 3 beyond bounds [0 .. 2]
sum: 4
*** -[__NSArrayM objectAtIndex:]: index 4 beyond bounds [0 .. 3]
sum: 5
*** -[__NSArrayM objectAtIndex:]: index 5 beyond bounds [0 .. 4]
sum: 6
(lldb) 
  • 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-07T09:21:57+00:00Added an answer on June 7, 2026 at 9:21 am

    Use NSMutableArray to store your location objects dynamically.

    Init the array at initialization phase :

    NSMutableArray *vertices = [[NSMutableArray alloc] init];
    

    Add vertices on mouse event :

    loc = [self convertPoint: [event locationInWindow] fromView:self];
    [vertices addObject:loc]; // Assuming loc can be added as an object to the array
    

    Convert to GLFloat array before drawing :

    int count = [vertices count] * 2; // * 2 for the two coordinates of a loc object
    GLFloat *glVertices = (GLFloat *)malloc(count * sizeof(GLFloat));
    int currIndex = 0;
    for (YourLocObject *loc in vertices) {
        glVertices[currIndex++] = loc.x;
        glVertices[currIndex++] = loc.y;        
    }
    

    Now you can use the glVertices array when drawing.

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

Sidebar

Related Questions

I want make interactive application where user launches it and can do various task
I want make a xslt transformation to xsl-fo but I´m not really sure that
I want to accomplish a GLSL Shader, that can texture and color my vertex
I want make an iphone app that has a UITableView that displays different texts
I want make sure that one thing about the transaction lock of GAE. In
I want make datetimepicker in my project. Using jquery how it is possible? I
I want make a bash script which returns the position of an element from
Let's say I want make some of my sources publicly available via my blog
I am new android app developer i want make app for tablets and phone
I have style sheet with a class name changebackgroundcolor i want make change in

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.