More specific (New keyword)

Started by
6 comments, last by Thunder_Hawk 21 years, 9 months ago
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 -- ¦þ ______________________________
______________________________________________________________________________________The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ"So. Any n00bs need some pointers? I have a std::vector<n00b*> right here..." - ZahlmanMySite | Forum FAQ | File Formats______________________________________________________________________________________
Advertisement
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 -- ¦þ
______________________________
______________________________________________________________________________________The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ"So. Any n00bs need some pointers? I have a std::vector<n00b*> right here..." - ZahlmanMySite | Forum FAQ | File Formats______________________________________________________________________________________
assuming that "text" is a null-terminated char-array (c-string), it looks fine to me...
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
Here''s a link to my full code:

Click Here
______________________________________________________________________________________The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ"So. Any n00bs need some pointers? I have a std::vector<n00b*> right here..." - ZahlmanMySite | Forum FAQ | File Formats______________________________________________________________________________________
Just had a peek on your code... what is the purpose for you to have strlen(text)*20 of floats?
"after many years of singularity, i'm still searching on the event horizon"
To create room for an array. I need 20 numbers for each letter. (2texcoords+3vertexcoords)*4vertices = 20floats/character.
______________________________________________________________________________________The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ"So. Any n00bs need some pointers? I have a std::vector<n00b*> right here..." - ZahlmanMySite | Forum FAQ | File Formats______________________________________________________________________________________
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
Chris Brodie
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 -- ¦þ
______________________________
______________________________________________________________________________________The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ"So. Any n00bs need some pointers? I have a std::vector<n00b*> right here..." - ZahlmanMySite | Forum FAQ | File Formats______________________________________________________________________________________

This topic is closed to new replies.

Advertisement