Memory corruption, but only in release mode

Hello! I am currently using MS Visual Studio 2010 and started working on a project. However in debug mode everything works just fine, but as soon as i switch to Release mode i get some problems. I have made sure that it isn't any optimizer problem since i diabled full program optimization (just to be sure). The problem occured when i introduced a new feature into my program. In debug mode the program runs just fine. But when i switch to release mode the program exist instantaneously with no signs of error. I managed to narrow it down to a variable that get's changed after some two function calls.

Here is the relevant code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
while(!isQuitting)
	{
		isQuitting = invSys->shutDown();
		window.clear();

		window.draw(*player.getSprite());
		player.stepAnimation();

		handleCollision();

		Cursor::updatePos(window);

		invSys->update();

		processInputs();
		processKeys();

		window.draw(*Cursor::getSprite());
		window.display();

		obj1.updateAttrib("hp", intToString(hp));
		GameTime::restartTime();
	}


The problem occurs as soon as window.draw(*player.getSprite()); and player.stepAnimation(); are called. The variable isQuitting gets switched from false to true even though those function calls have nothing to do with it, neither do they have acces. I tried commenting one of the functions out but leaving the other, no change. Only when i comment both of them out the variable stays unchanged.

the window object is an sf::RenderWindow from the SFML 2.0 library.

the function call of player.stepAnimation(); occurs in its derived class Moveable

Here is the code for Moveable:
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "Moveable.h"

Moveable::Moveable()
{
	position.x = 0.0;
	position.y = 0.0;
	offset.x = 0.0;
	offset.y = 0.0;
	speed = 0.0;
	runSpeed = 0.0;
	uno = false;
	running = false;
	sprite = new sf::Sprite();
}

Moveable::~Moveable()
{
	delete sprite;
}

void Moveable::up()
{
	float y = speed*(GameTime::getTime().asMicroseconds()/100000.0f);
	sprite->move(0.0f, -y);
}

void Moveable::down()
{
	float y = speed*(GameTime::getTime().asMicroseconds()/100000.0f);
	sprite->move(0.0f, y);
}

void Moveable::left()
{
	float x = speed*(GameTime::getTime().asMicroseconds()/100000.0f);
	sprite->move(-x, 0.0f);
}

void Moveable::right()
{
	float x = speed*(GameTime::getTime().asMicroseconds()/100000.0f);
	sprite->move(x, 0.0f);
}

void Moveable::run(bool isRunning)
{
	running = isRunning;
}

void Moveable::setPos(sf::Vector2f pos)
{
	pos = position;
	sprite->setPosition(position+offset);
}

void Moveable::setPos(float x, float y)
{
	position.x = x;
	position.y = y;
	sprite->setPosition(position+offset);
}

void Moveable::setOffset(sf::Vector2f ofs)
{
	offset = ofs;
	sprite->setPosition(position+offset);
}

void Moveable::setOffset(float x, float y)
{
	offset.x = x;
	offset.y = y;
	sprite->setPosition(position+offset);
}

void Moveable::setSpeed(float spd)
{
	speed = spd;
}

void Moveable::setRunSpeed(float increase)
{
	runSpeed = increase;
}

sf::Sprite* Moveable::getSprite()
{
	return sprite;
}


and the header file
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
#ifndef _MOVEABLE_H_
#define _MOVEABLE_H_

#include <SFML\Graphics.hpp>
#include <iostream>
#include "big.h"


class Moveable
{
	public:
		Moveable();
		~Moveable();

		virtual void up();
		virtual void down();
		virtual void left();
		virtual void right();
		virtual void run(bool isRunning);

		virtual void setPos(sf::Vector2f pos);
		virtual void setPos(float x, float y);
		virtual void setOffset(sf::Vector2f ofs);
		virtual void setOffset(float x, float y);
		virtual void setSpeed(float spd);
		virtual void setRunSpeed(float increase);
		virtual sf::Sprite* getSprite();

	protected:
		float runSpeed;
		float speed;
		bool running;
		bool uno;
		sf::Vector2f position;
		sf::Vector2f offset;
		sf::Sprite* sprite;
};

#endif 


I think that it is some sort of memory corruption or buffer overflow, but i can't seem to figure out where. Sometimes it is easier to spot errors on someone elses code. Thanks!
`Moveable' needs a virtual destructor
Also, a copy constructor and assignment operator (¿is there a reason to use dynamic allocation with the sprite?)
I'll fix the destructor, and no, there is no need for dynamic allocation. I tried changing it to dynamic allocation to see if anything changed, and it didn't.
Topic archived. No new replies allowed.