So I am trying to write a Resource loader and manager (Yes I know of Thor, this is just a "learning" project.) and I have started experimenting with unions, not something I use very often. I created a class (as seen in code below) called resource which has a union that contains a texture/font. The texture loads correctly; however the font throws an access violation
Exception thrown at 0x00C5DBE0 in Project.exe: 0xC0000005: Access violation reading location 0x00000004.
The following is my complete and minimal example.
#include <SFML/Graphics.hpp>
class Resource
{
public:
union
{
sf::Texture t;
sf::Font f;
};
Resource()
{ }
~Resource()
{ }
};
int main()
{
Resource font;
Resource tex;
if (!tex.t.loadFromFile("player.png")) {} //! Works great!
//doError
if (!font.f.loadFromFile("blocks.ttf")) {} //! Throws access violation.
//doError
return 0;
}