Hey,
im farely new to SFML and im having trouble when loadiong Textures. Im getting an Assertion Failed.
here's the message;
Assertion failed!
Program: D:\Workspace\C++\Game-Dev\Hexagon Game Engine\bin\Debug\Hexagon Game Engine.exe
File: D:\Programming\C++\Releases\_Sources\SFML\src\SFML\Window\GlContext.cpp, Line 416
Expression: sharedContext != NULL
Heres the class where I call the load texture:
#include "SpriteLoader.hpp"
#include <iostream>
using namespace std;
using namespace Hexagon;
string SpriteLoader::ResourceLocation;
// Constructor for Spriteloader class
SpriteLoader::SpriteLoader(string ResourceLocation) {
InitSpriteLoader(ResourceLocation);
}
// Deconstructor for Spriteloader class
SpriteLoader::~SpriteLoader() {}
// Initialization Method
void SpriteLoader::InitSpriteLoader(string ResourceLocation) {
cout << "HE: SpriteLoader: Initializing..." << endl;
SpriteLoader::ResourceLocation = ResourceLocation;
}
// Method for loading/creating a Sprite
void SpriteLoader::LoadSprite(string name) {
sf::Texture texture = LoadTexture(name);
}
// Method for loading Textures
sf::Texture SpriteLoader::LoadTexture(string name) {
sf::Texture texture;
if(!texture.loadFromFile(GetResourceLocation()+"/"+name)) {
cout << "[ERROR]HE: SpriteLoader: Texture failed to load! (" << name << ")" << endl;
}
}
// Method for getting "ResourceLocation"
string SpriteLoader::GetResourceLocation() {
return SpriteLoader::ResourceLocation;
}
(LoadSprite calls LoadTexture, which really loads the texture)
And heres the class for my Window Creation and where I call the LoadSprite Function:
#include "HexagonEngine.hpp"
#include <iostream>
using namespace Hexagon;
using namespace std;
SpriteLoader* Engine::spriteLoader;
Engine::Engine(int WIDTH, int HEIGHT, char* TITLE) {
Engine::initHexagonEngine(WIDTH, HEIGHT, TITLE);
}
Engine::~Engine() {}
void Engine::initHexagonEngine(int WIDTH, int HEIGHT, char* TITLE) {
cout << "HE: Initializing" << endl;
spriteLoader = new SpriteLoader("src/HexagonEngine/defaultRes");
spriteLoader->LoadSprite("MissingTexture.png");
cout << "HE: Creating new sf::Window" << endl;
Engine::hexWindow.create(sf::VideoMode(WIDTH, HEIGHT), TITLE); // Create new sf::RenderWindow
cout << "HE: Initializing finished." << endl;
}
// Method Runs GameLoop
void Engine::Start() {
cout << "HE: Starting GameLoop" << endl;
// Gameloop
while(hexWindow.isOpen()) {
sf::Event event;
while(hexWindow.pollEvent(event)) { // Run this loop aslong as there are window events
if (event.type == sf::Event::Closed) { // Execute any requested events
hexWindow.close();
}
}
Update();
FixedUpdate();
Render();
}
}
void Engine::Update() {}
void Engine::FixedUpdate() {}
// Render Function is called every go through of the gameloop
void Engine::Render() {
hexWindow.clear(sf::Color::Magenta);
hexWindow.display();
}
It fails at window creation, but as soon as I remove the LoadSprite call it doesnt fail anymore and the other way arround