Advertisement Jump to content
Sign in to follow this  

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.

If you intended to correct an error in the post then please contact us.

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

class SpecialFX
    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
    GLuint oTexture;  //Saves the particletexture
    bool Animate();   //Animates the effect
    void SpawnPart(int i); //respawns a dead particle
    void LoadTexture(); //Loads the texture

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

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

Link to post
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 :)

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!