Archived

This topic is now archived and is closed to further replies.

More specific (New keyword)

This topic is 5996 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Can someone tell me if these statements are valid inside a function.

float *array = 0;
array = new float[strlen(text)*20];
...
delete [] array;

If anyone knows I''d be thankful. _____________________________ And the Phoenix shall rise from the ashes... --Thunder_Hawk -- ¦þ ______________________________

Share on other sites
I''ve been debuging a function for about 3hours now and I''m getting to the point where I believe that these statements have to be what''s messing it up.

_____________________________

And the Phoenix shall rise from the ashes...

--Thunder_Hawk -- ¦þ
______________________________

Share on other sites
assuming that "text" is a null-terminated char-array (c-string), it looks fine to me...

Share on other sites
Here''s a link to my full code:

Share on other sites
Just had a peek on your code... what is the purpose for you to have strlen(text)*20 of floats?

Share on other sites
To create room for an array. I need 20 numbers for each letter. (2texcoords+3vertexcoords)*4vertices = 20floats/character.

Share on other sites
These kind of hard to track down errors don''t hapen as often when you use well defined data. If you use a class\struct in place of what your currently using you can still cast you data to a void* to say pass in to opengl later.

Without doing something like that it''s easy to write code that unintentionally over run the array.

I''d use a std::vector with a struct for the data members. Then there in no new \ delete and no chance that you''ve messed up the accessor code for finding the correct data member as the struct stores the offsets for you.

Chris Brodie
http:\\fourth.flipcode.com

Share on other sites
Aha! Somehow when I read your post gimp it just clicked! I shouldn''t be multiplying by 20 in drawelements. After all, there are only strlen(text) number of elements to draw. I think it was just the thought of overrunning arrays. I had thought that couldn''t be happening because I got it to work with a manual glBegin/glEnd and the vector forms of the functions. Then, I thought that maybe somehow I was telling OpenGL to overrun the array and voila (is that spelled right?). I don''t see how a struct or class would help me here, I would still need a method like this. Never mind, if I had put this in a structure the *20 part might have been handled automatically and I would have avoided my confusion. Oh well, thanks alot

_____________________________

And the Phoenix shall rise from the ashes...

--Thunder_Hawk -- ¦þ
______________________________

1. 1
2. 2
Rutin
19
3. 3
4. 4
khawk
14
5. 5

• 13
• 26
• 10
• 11
• 44
• Forum Statistics

• Total Topics
633743
• Total Posts
3013643
×