Here is my code:
#include <iostream>
#include "SFML/Graphics.hpp"
#include "SFML/Graphics/Font.hpp"
#include "SFML/Graphics/Text.hpp"
#include <string>
sf::Text generateTitle()
{
std::string filename = "files\\font.ttf";
sf::Font titleFont;
titleFont.loadFromFile(filename);
sf::Text titleText;
titleText.setFont(titleFont);
titleText.setString("WELCOME TO MINESWEEPER!");
titleText.setCharacterSize(24);
titleText.setFillColor(sf::Color::White);
titleText.setStyle(sf::Text::Bold | sf::Text::Underlined);
return titleText;
}
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window", sf::Style::Close);
std::cout << "Made it";
window.clear(sf::Color::Blue);
std::cout << "Made it";
sf::Text titleText = generateTitle();
std::cout << "Made it";
window.draw(titleText);
window.display();
}
Every time the code runs, it crashes on the window.draw call, and says: Exception thrown at 0x00007FFE069A3579 (sfml-graphics-d-2.dll) in Minesweepermf.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF. I am fairly certain that my SFML is included properly in the project, and I know that the file there (sfml-graphics-d-2.dll) is included with the exe. Does anyone know what might be going wrong here? First time posting a question btw, sorry if I formatted anything weirdly.
I tried completely re-linking all SFML modules, opening a new project from scratch, re downloading all files, restarting pc. Nothing has produced any other result besides the one I keep getting. I am using SFML 2.6.0 with Visual Studio 2022.
It turns out it was because I was using a separate function to generate the text. Another user in another thread had pointed out that SFML passes around font references, and due to the way mine was set up, SFML likely didn't know which font to use when the .draw call was issued.