Vertex Array Error

Hi guys! :slight_smile:
Let’s see if anyone can help me with this. I am stuck! :frowning:

I am implementing Vertex and Color Arrays for my point sprite particle System. The problem lies in the glDrawArrays call (I discovered after a lot of debugging) and it returns:

“Unhandled exception in ogl_particle_system.exe:
0xC0000005: Access Violation”

However the problem only occurs if the number of particles used is big. For 30000 particles it returns the error (for 3000 particles it works fine).

I would like to fix this so that I can use big number of particles, but I don’t know what’s wrong.

My calls are:

GLsizei i=0;
	while( pParticle )
			m_PVertexArray[i].r=pParticle->m_vColor.x; //Red
			m_PVertexArray[i].g=pParticle->m_vColor.y; //Green
			m_PVertexArray[i].b=pParticle->m_vColor.z; //Blue
			m_PVertexArray[i].a=pParticle->m_Alpha;   //Alpha

			m_PVertexArray[i].z=pParticle->m_vCurPos.z ;

			pParticle = pParticle->m_pNext;

	// enable and specify pointers to vertex arrays

	glVertexPointer(	3,   //3 components per vertex (x,y,z)
	glColorPointer(		4,   //4 components per vertex (r,g,b,a)
						&m_PVertexArray[0].r);  //Pointer to the first color

	  [b]  glDrawArrays(GL_POINTS, 0 //Starting at 0
							, i+1); //Rendering i+1 points [/b]

	glDisableClientState(GL_VERTEX_ARRAY);  // disable vertex arrays

My point vertex structure is:

  struct PointVertex
	GLfloat x,y,z;
	GLfloat r,g,b,a;

My Point/Vertex Array is correctly defined at the init of the program:

	m_PVertexArray = new PointVertex[m_dwMaxParticles];  

Where m_dwMaxParticles is the specified maximum. In the example above is 50000.

What’s going on!? Does glDrawArrays have a maximum limit for the size of the Count parameter!!! :confused:

Thanks so much in advance!!!


There is only a theoretical limit for glDrawArray on 32bit systems, it’s the range of GLuint 2^32-1 which makes your system memory run out before you reach that.

There is one bug and a some unsafe things in your code:
1.) After your while loop “i” is already the count of vertices, glDrawArrays with i+1 is wrong. When you have specified m_dwMaxParticles that might crash the way you’ve seen.
2.) The while loop should be while( pParticle && i < m_dwMaxParticles) to avoid crashes in case you have more particles than the array can hold.
3.) If the structure is x,y,z,r,g,b,a I would initialize it in that order for optimial cache performance.
4.) glVertexPointer address should be written safer the way you did it for colors: glVertexPointer(3, GL_FLOAT, sizeof(PointVertex), &m_PVertexArray[0].x);
5.) Check if you really need to toggle the vertex array enable state all the time. Most of the times you will need the vertex array anyway if there is more drawing going on with arrays.
Also verify that no other array is enabled.

If that doesn’t help you might have found a driver bug. Check which OpenGL implementation you use with glGetString(). If it’s not Microsoft try updating your graphics driver.

Oh no… :frowning:
I fixed all the errors you found… but still nothing. Same error persists.

Ok this is weird. I catched the maximum permitted value I can use before it crashes. It works well with 16623. With that number +1, it crashes!
The crash occurs on the same line glDrawArrays.

I am using NVidea 's GeForce XFX5500 2.01 Driver… (Just updated last week).

This is weird…
Any genius out there that can crack this puzzle?!

Thanks everyone!

In all honesty, I think you should give up programming.
If you’re not going to give up, go to the beginners forum.

Originally posted by knackered:
In all honesty, I think you should give up programming.
If you’re not going to give up, go to the beginners forum.

Ok, maybe I thought that this was an advanced question and turned not being advanced, but why so much flaming is necessary?!

Man, for me programming is a hobby and I am no proffesional (like you mentioned you are), but how the heck should I know with certainty if my question belongs to the Begginers or Advanced forum!? There are no parameters to determine that. When I think that the topic I am asking is not Begginers then I post it in the Advanced. I can also be mistaken. And I don’t mind if someone answers me “Hey, you know, that question should go to the Begginers’ forum since it’s actually not advanced.”. That’s ok, I don’t mind reciving that answer, and I would reply just fine: “Sorry, I didn’t know, I will make sure I don’t ask questions of that topic on the advanced forum”.

However I don’t think that your agressive reply is appropiate to this forum.

Please don’t answer back. I don’t want this to be a flaming post. Thanks.

It is not advised to put more elements than that limitation.

Okay, even if it seems not so an advanced topic, don’t read what some might write: they just live in their megalomaniacal vanity beach but never went to swim in the ocean. They would have liked to be moderators but failed, so they must put their anger on everyone seeming inferior to them.

jide, I keep meaning to ask. It says you registered in this forum in July 2001, yet you continually ask quite basic questions about OpenGL - why is this? Is it like Memento, where you started off knowing everything but as time passes you’ve forgotten more and more?
Or were you in some kind of motorway accident, where some projectile took a chunk of your brain away, like what happened to poor old Gordon Kay?

If you think I should give up programming, I think that you should definitely give up this forum, as your answers are completely inappropiate.

Moreover, I suggest that you join an anger management programa, or invest in some psychological advice to understand which are the causes of your innapropiate and irrespectful attitude.

Wishing the best for you,

to the community: sorry.

to knackered:

And after ? What’s the problem ?

No it’s more like Fight Club :smiley: And I can see you toke 3 hours to find an ‘appropriate’ answer to my post as you were online almost the same time I posted my last post.

You’re always the same knackered, so it has been written you will never change, slave of some kind of a desperate destiny: GL isn’t a goal for my life: may the quantum neuronal transmissions make you understand this point. But you might need some milk to try to understand this point.

I don’t want to do the same as before. Here is not the place. So I won’t turn around anymore.

EDIT: between, you have not understood Memento. Try to see it again and again so you might understand what really is his problem.

EDIT 2: Well, is it really the good place to guess what’s happening to people ? And what if I have had an accident ? Would that point makes you happy ? Feel better ? What if I ask you if someone made a trauma to you when you was a child ?
Come on. If you read all the posts carefully (and I’m pretty sure you do), then don’t reply if they don’t interrest or hurt you and make and endearing to your girl friend (if you have one — and I don’t wanna know if you have one !!!).

No knackered (does it mean a past thing ??) you really disappoint me, no smart thoughts, no humanity, no evolution, no changes, no feelings (but bad ones), well nothing what…

I told some months ago I will ignore you. I must admit now this was the thing I HAD TO DO.

My computer’s always on, and I use firefox tabbed browsing pathologically, so as far as you’re concerned I’m eternally reading your posts, jide.
It must be something about the translation, but your diagnosis of my ‘condition’ is always beautiful, jide. It almost makes me wish I were French…almost.
Rodrix, the code you posted is litered with basic programming mistakes, therefore it’s safe to assume you’re a beginner. If you’re not a beginner, then it’s a reasonable suggestion that you give up programming, as you’re going to drive any people you work with insane debugging your crazy stuff. No anger, just logic.

Oh sh** a fanatic…

Ok jide, just read your reply. I’m sorry for winding you up, really don’t take me so seriously. I’m trying, really trying to be funny in a thread that I believe has no other value…at your expense, admittedly - but nevertheless, humour is my motive, not malice.

Humor ?? Is that really of humor ??? Try to put yourself at the place of the one who wrote the post instead of telling so absurd and ineptitude things. You really need a mentor that makes you understand the real values of life knackered and I wonder if I would accept to be this one.

Not everybody is a “PRESIDENT OF A COMPANY AS YOU ARE” knackered. I already told you years ago that times are changing. We’re no more in the euphoria of the year 2000 you know.
But what I know is that I won’t like to be at your place now, I would prefer selling fruits in the week-end market instead…

And please, as for the other post, don’t push me, please, please, please.

Originally posted by knackered:
… really don’t take me so seriously.
… humour is my motive, not malice.

Why are there so many people around who think they can excuse their arrogant behavior and offending talk by feinting humor?
It’s a cheap trick only these people think will work to excuse their brainless comments after they realise they’ve been acting a jerk!

def, it’s just humour you don’t understand. I take issue with your assertion that my comments were brainless, they were funny and rooted in truth.

Nobody seems to understand your socalled “humour”.

What does that make you:
Genius? Misunderstood? Lunatic? Dumb? Scatterbrained?

Take your pick…

comon u cant say that to knackered hes our mascot
whilst his comments are internded as homour (which is as plain as day to me that they are), if u feel not then its either cause u have either
A/ different mentality
B/ different culture
whilst they are intended as humour, admitted sometimes theyre not funny but seeing above ‘pened to poor old Gordon Kay’ me - who?? search search, canadian actor no, hmmm 5 minutes later, hes the fella from 'ello 'ello, **** truly the low point of english humour ( even crap like it aint half hot mum, open all hours, r u being served, i rate higher ) knackered i must say im disapointed

i feel sorry for poor old relic.

you speak for everyone now, def?
what does that make you?
say something funny, def - so I can understand what makes you laugh. No ‘buffy the vampire’ references though, I don’t watch it so they’d be lost on me.

As far as jide is concerned, if you actually read this thread from the beginning you’ll see jide initiated this exchange of insults. This is the only reason I took the michael out of him. I will happily do the same to you def if you persist in attacking me.

yes zed, sorry about the gordon kay reference, it was misjudged. It’s the fact that gordon was the star of so many of england’s most appauling comedy exports that made his accident in the '87 storm so funny.
But if you’re not a british person over, say, 25 then it would mean nothing to you.
Thank you for defending me, you’re a man of good taste.
Now, it’s a rare sunny day in england today, so I’m going to shut down my computer and go out to play.