Public Group

# jumping array values

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

## Recommended Posts

I'm accually quite new to c++ and I know I jumped inte the world of 3dprogramming too early but I'm doing quite well I think. :) This is a class for making graphical specialeffects (particleeffects) like fire, explosions and so on.
typedef struct
{
bool show;        //Show the particle?
float fade;       //the alpha value of the part
float pos[2];     //The position of the part  [0]=x, [1]=y, [2]=z
float speed[2];   //The speed of the part
float gravity[2]; //The gravity of the part
}Particles;

class SpecialFX
{
public:
Particles * Part; //Declaring a number of parts (set in the constructor)
float Pos[2];     //Position of the effect
float color[2];   //Color of the effect
int FX;           //Type of effect. Fire=0, Explosion=1 etc.
int numparts;     //Number of particles used in this effect

SpecialFX(float x, float y, float z, int type, int numpart); //Constructor
~SpecialFX();     //Destructor (frees the memory)
bool Render();    //Function called every loop to render all particles and call the animation func
void Execute();   //Restart animation

private:
GLuint oTexture;  //Saves the particletexture

bool Animate();   //Animates the effect
void SpawnPart(int i); //respawns a dead particle
};


The problems with this is that sometimes the values of, for instance, color[0] gets the same value as Pos[0]. Then I can't change the value of color[0] during runtime. This happends to all of the arrays in this class (including those in the struct). It usally fixes if I change the order in which i set the values, but then another variable gets a currupt value. I'm not that good at memoryhandling and I guess that this is what it's about. Thankful for every comment! (even if it's about something else in the way this class is written)

##### Share on other sites
Your problem is the way you are declaring your arrays. You need to specify the number of elements in the array. For example:

float pos[2]; //The position of the part [0]=x, [1]=y, [2]=z

should be:

float pos[3]; //The position of the part [0]=x, [1]=y, [2]=z

All of your arrays appear to have this problem.

##### Share on other sites
Thank you very much!

Haha okey this was really one of the most simple things I've ever had a problem with... I've had this problem for very long in various programs I've programmed, don't know how I could have missed this :)

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 28
• 16
• 10
• 10
• 11
• ### Forum Statistics

• Total Topics
634111
• Total Posts
3015573
×