Hi,
I have a program that loads ~15 sprites from my hard drive, from predetermined paths.
for (std::string path : textures_to_load)
{
sf::Texture texture;
if (!texture.loadFromFile(path))
{
return 1;
}
//other stuff
}
This code crashes at some point during the 'for' loop.
Sometimes is successfully parses 4 textures, sometimes 12.
"other stuff" never causes a crash.
The program exits with code -1073741819.
Debugger crashes at GLContext.cpp, line 283. output:
Exception thrown: read access violation.
extensionString was nullptr.
I'm using Visual Studio 2022, compiled SFML from source (for VS2022, Debug, 64).
Ah, you're using SFML 3, there might be some undetected issue.
Just to try something, can you move the Window to the top, i.e. before you initiate any of the textures?
Also for those who don't want to download the zip:
#include <iostream>
#include <vector>
#include <map>
#include <memory>
#include <fstream>
#include <regex>
#include <SFML/Graphics.hpp>
#include "Misc.h"
#include "Entity.h"
int main(int argc, char * argv[])
{
std::vector<std::unique_ptr<Entity>> game_entities;
// game_entities.push_back(std::make_unique<Outpost>(100.f, 200.f));
// game_entities.push_back(std::make_unique<Entity>(600.f, 200.f));
// Load all of the used sprites
// We'll read from a file called Sample.txt
std::ifstream inf{ "resources/sprites_to_load.txt" };
if (!inf)
{
std::cerr << "[ERROR] sprites_to_load.txt could not be opened for reading.\n";
return 1;
}
std::map<std::string, sf::Texture> textures;
while (inf)
{
std::string texture_path;
std::getline(inf, texture_path);
std::cout << texture_path << '\n';
// lines that are empty or start with '#' are ignored
if (texture_path == "" || texture_path.front() == '#')
continue;
sf::Texture texture;
if (!texture.loadFromFile(texture_path))
{
std::cerr << "[ERROR] Failed while loading texture: " << texture_path << '\n';
return 1;
}
std::cout << texture_path << '\n';
//std::regex regexp("\\/[a - zA - Z0 - 9] * \\.png");
// flag type for determining the matching behavior (in this case on string objects)
//std::smatch m;
// regex_search that searches pattern regexp in the string mystr
//regex_search(texture_path, m, regexp);
//textures[m.end()] = texture;
}
sf::CircleShape shape(100.f);
shape.setFillColor(sf::Color::Green);
sf::ContextSettings settings;
settings.antialiasingLevel = 8;
sf::RenderWindow window(sf::VideoMode(1200, 700), "Supply chain", sf::Style::Default, settings);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
for (auto& e : game_entities)
{
window.draw(*e);
}
window.draw(shape);
window.display();
}
return 0;
}