Unhandled exception at 0x53e83d80 in TestGame.exe: 0xC0000005: Access violation reading
location 0xfeeefef6.
My C++ program throws an unhandled exception when I close my SFML window (causing the main class to return 0;
The code causing this is an std::ostringstream object, if I dont use it the problem doesnt occur..
void Orbs::UpdateText()
{
oss.str("");
oss << air_orbs.number;
air_orbs.text.setString(oss.str());
oss.str("");
oss.flush();
}
The class header:
#pragma once
#include <SFML/Graphics.hpp>
#include "FieldConst.h"
#include <sstream>
int const ORB_CHAR_SIZE = 20;
float const ORB_SCALE_SIZE = 0.25f;
struct Orb
{
sf::Texture texture;
sf::Sprite sprite;
int number;
sf::Text text;
void Add(){
number++;
}
void Remove(){
number--;
}
};
class Orbs
{
public:
Orbs();
~Orbs();
void Render(sf::RenderWindow &target);
void UpdateText();
private:
Orb air_orbs, darkness_orbs, death_orbs, earth_orbs, electricity_orbs,
fire_orbs, life_orbs, light_orbs, machine_orbs, metal_orbs, time_orbs, water_orbs;
std::ostringstream oss;
};
Player::Player()
{
Player::name = "Player1";
Player::deck = new Deck();
Player::voidZone = new Deck();
Player::hand = new Hand();
Player::orbs = new Orbs();
}
. #pragma once
#include "IncludeCards.h"
#include "Orbs.h"
class Player
{
public:
Player();
~Player();
std::string GetName();
Deck* GetDeck();
Hand* GetHand();
Deck* GetVoidZone();
Orbs* GetOrbs();
void DrawFromDeck();
void DiscardToVoid(Card *cardToDiscard);
//void UseCard ability/invoke/spell
private:
std::string name;
Deck *deck;
Hand *hand;
Deck *voidZone;
Orbs *orbs;
};
What can I do to fix it? Thanks in advance