Archived

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

Thunder_Hawk

More specific (New keyword)

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 -- ¦þ
______________________________

Share this post


Link to post
Share on other sites