Sign in to follow this  
BENOJ

Whatis your typical Vertex Range?

Recommended Posts

BENOJ    128
Hi, Im currently coding a game engine and i've come to Object code.. Anyway becase Devcpp can't handle unlimited arrays ( The Memory runs into eachother (with big arrays) and causes the exe to crash ) i have had to set a Vertex Limit for each object. Im Not rrly sure what i should set the limit to be.... What would you say is the suggested Maximum Vertex Number? Its Really annoying That i have to set a limit, because this means the objects are runnign inneficiently because it uses the memory space no matter what :( anyone know how to get around this in Devcpp then that would be even better !! oh and finaly does anyone know any (or where to see these )algorthms to load in common 3D files like .x etc... (into opengl) im not really sure as to the structure of these files. My Code is working,but i have to define the Vertex.. and a game engine where you can't laod in a 3d file would be a bit boring :P Thanks, BEN

Share this post


Link to post
Share on other sites
Kaze    948
so how big are these arrays that crash devc++?
if the elements are more than a 10 bytes you may want to create a array of pointers to elements.
Im not entirely sure what your asking in the rest of your question, mabey if you could provide some more detail.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
basicaly i have a class for vertex's
each vertex contains x,y,z co-ordinates

the object class coinaints vertec so ist a bit like

class OBject
{
public:
vertex[];
};

when i do that itusualy crashes if i load with vertex > than say 20. However if i do :


class OBject
{
public:
vertex[0xFFF];
};

then i can have ip to 0xFFF vertex and it wont crash.. but as you can see its inneficient, because the ememory is wasted really....


and i meant like opening the file and knowing where the different stuff is stored like Vertex data in each file etc... so i can load this into OpenGl with glvertex() etc..
-BEN

Share this post


Link to post
Share on other sites
Kaze    948
in c++ arrays arnt automatically created unless you specify a starting size or resized, if you write to a uninitialized array you just writing to a random point in memory
this dosent seem to be correct c++ syntax so its still hard to understand, i also dont understand why your using hex in it

// a 20 element array
int a[20];

//a uninitialized array
int b[];
//same
int *b;

//this write to a random point in memeory and will crash your app
b[5]=45;

//so does this
a[25]=5555;

//this is fine
a[14]=4;

//this is how you do it
//create 60 element array
b= new int[60];
//now this is ok
b[59]=56;

//hex gets treated as a normal number
//4095 long array
int d[0xFFF];

Share this post


Link to post
Share on other sites
BENOJ    128
I used hex because writing 0xFFFF was easier than writing 65535 lol.
Yeah i know thats why i have used a massive array meaning thatonly 65535 vertexs can be lioaded. What i meant is, i was alking to my teacher about this and he sed theres a godo way to egtaround it, but he couldnt remember how to do it. He sed it was like destroyign and recreating the array each time or something liek that . Not Much help really :P.

-BEN

Share this post


Link to post
Share on other sites
bobofjoe    322
He was probably talking about dynamically creating arrays, which is what Kaze was demostrating in the last portion of his code.

Basically, you get a pointer to whatever datatype you want:

int arraySize = 1000;
int * someArray = NULL;



Then you set it to a block of memory using the new operator
someArray = new int[arraySize];



Now you can use the variable someArray just like you would any array, but you didn't have to hard code in the size.
Destroying the array is as simple as calling delete on the pointer.

delete someArray;





EDIT:: How do you use the quote tags? =/

Share this post


Link to post
Share on other sites
BENOJ    128
thanks.

Hmmm hwo would i use that with the classes though??
say i have these classes

class Vertex
{
public:
float x,y,z;
}

class OB
{
public:
Vertex Vertex[0xFF]
}

because the way he said it worked, is that when the end of the array si reached it destroys the array and recreates it with +1 size.

Thanks,
BEN

ps Don't Know :p

Share this post


Link to post
Share on other sites
BENOJ    128
yeah its a bit of a bitch, im not too btohered really im sure ill find a solution to the problem eventually but for now i just want to know what si the typuical range of vertex in models... but no one has answered that 1 yet :P although i would be happy to knwo how to do the destrucion and restruction of arrays though :P but mainly i justwanna know what a goo maximum value is

Share this post


Link to post
Share on other sites
Kaze    948
Quote:
Original post by BENOJ
yeah its a bit of a bitch, im not too btohered really im sure ill find a solution to the problem eventually but for now i just want to know what si the typuical range of vertex in models... but no one has answered that 1 yet :P although i would be happy to knwo how to do the destrucion and restruction of arrays though :P but mainly i justwanna know what a goo maximum value is

just a hint, spell check and proof reading might give you more relevant replies

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Quote:
Original post by Anonymous Poster
basicaly i have a class for vertex's
each vertex contains x,y,z co-ordinates

the object class coinaints vertec so ist a bit like

class OBject
{
public:
vertex[];
};

when i do that itusualy crashes if i load with vertex > than say 20. However if i do :


class OBject
{
public:
vertex[0xFFF];
};

then i can have ip to 0xFFF vertex and it wont crash.. but as you can see its inneficient, because the ememory is wasted really....


and i meant like opening the file and knowing where the different stuff is stored like Vertex data in each file etc... so i can load this into OpenGl with glvertex() etc..
-BEN


class OBject
{
public:
vertex[];
};

This is legal syntax in C++ but it isn't what you want. Only use this for when you map data from a file to a block of data.

What you want is

class Object // Let's get rid of the capital B too
{
public:
Vector* vertex;
Object(int numVertices) { vertex = new Vector[numVertices]; }
~Object() { delete[] vertex; }
};

Note you also didn't declare the type of vertex in your example so I made up a Vector type.

The first (wrong) case doesn't allocate any space for the vertices so when you access 20 or so into it you hit protected memory (I'm guessing) causing an access violation crash.

Plus, learn to spell if you are a native English speaker, it's just laziness.

Share this post


Link to post
Share on other sites
Quote:
Original post by bobofjoe
He was probably talking about dynamically creating arrays, which is what Kaze was demostrating in the last portion of his code.

Basically, you get a pointer to whatever datatype you want:
*** Source Snippet Removed ***
Then you set it to a block of memory using the new operator
someArray = new int[arraySize];
Now you can use the variable someArray just like you would any array, but you didn't have to hard code in the size.
Destroying the array is as simple as calling delete on the pointer.
delete someArray;



EDIT:: How do you use the quote tags? =/


Destroying the array is as simple as calling delete on the pointer.

Erm... you allocated with new[] but didn't use delete[] afterwards. So that's an undefined behaviour bug so it's not quite as simple as you suggested. Don't give advice if it is wrong folks.

PS previous anon poster was me also, didn't sign in.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this