Variables losing values

Hello everybody, i have got a little problem. It's not the first time that happens and usually i've achieved to pass it, but without understanding its origin. What it happens is that my variables ( not pointers ) are losing their values, like if they were going out of scope, but i'm inside the same class and they are not pointers. This happens whenever i call any kind of function ( even std::cout ) with that variable involved .
OK actually i have got two classes :
-> DirectionalEmitterMode that is a struct containing a lot of variables (just one pointers )
-> DirectionalEmitter that requires a directionalEmitterMode as constructor parameter.
Here's the code for the constructor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
spark::DirectionalEmitter::DirectionalEmitter(sf::RenderWindow& Window,DirectionalEmitterMode& EmitterMode)
{

	m_ParticleMode		= EmitterMode;
	m_pWindow			= &Window;
	m_BurstTick			= 0;
	m_WndWidth			= m_pWindow->getSize().x;
	m_WndHeight			= m_pWindow->getSize().y;

	// seeding the random number generator
	srand(time(NULL));


}

so far so simple... here's the DirectionalEmitterMode definition so you can have an idea about its properties :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60

	struct DirectionalEmitterMode
	{

		DirectionalEmitterMode(){};
		// Creating a constructor for ease of use
		DirectionalEmitterMode( Vector2D& Position,
							    Vector2D& Heading = Vector2D(1,0),
							    Vector2D& Acceleration = Vector2D(0,0),
								Vector2D& Force = Vector2D(0,0),
							    Vector2D& Speed = Vector2D(100,100),
								Vector2D& MaxSpeed = Vector2D(100,100),
								unsigned int NOfParticle = 100,
								double Radius = 0,
							    double Angle = 360,
								double Randomness = 20,
								double LifeTime = 200,
							    double Energy = 50,
								double BurstRate = 0.01,
							    bool Reuse = true,
								bool FadeOut = false);

		void					SetTexture(sf::Texture&);
		void					SetConvexShape(sf::ConvexShape&);
		void					SetCircleShape(sf::CircleShape&);
		void					SetPixelArray(sf::Color,sf::Color);
		/** PARTICLE PROPERTIES **/
		Vector2D				m_Position;
		Vector2D				m_Heading;
		Vector2D				m_Acceleration;
		Vector2D				m_Force;
		Vector2D				m_Speed;
		Vector2D				m_MaxSpeed;
		double					m_Angle;
		double					m_Randomness;
		double					m_Radius;
		double					m_LifeTime;
		double					m_Energy;

		/** EMITTER PROPERTIES **/
		bool					m_Reuse;
		double					m_BurstRate;
		sf::Texture*			m_pTexture;
		sf::ConvexShape			m_ConvexShape;
		sf::CircleShape			m_CircleShape;
		unsigned int			m_NOfParticles;
		sf::BlendMode			m_BlendMode;
		bool					m_FadeOut;
		sf::Color				m_AlphaColor;
		unsigned int			m_AlphaValue;
		sf::Color				m_StartColor;
		sf::Color				m_EndColor;
		unsigned int			m_ParticleType;

		/** WINDOW PROPERTIES **/
		unsigned int			m_WndWidth;
		unsigned int			m_WndHeight;

	};

Going step-by-step with the debugger i noticed that when i use the m_ParticleMode in another method it just has CX0030 ERROR as value. thank for your time and please excuse my english
Last edited on
If you want a value not to lose his value just put it as <static> for example.

static int value;
etc.....
Here's the code for the constructor

First thing I notice is you are not using the member init list for the constructor, which means your object are first being default constructed, then copy assigned. Therefore, disregarding all compiler optimizations, you don't have a copy constructor or copy assignment operator for your struct and it is doing a shallow copy. This is probably the root of the cause.
Topic archived. No new replies allowed.