I am trying to print text to a specific spot on my window through a function within a separate class from main. This function basically updates the string in the text and then the text is later drawn in the main loop. However, every time I try running, it gives me a white screen and exits with code -1073741819. This is what the code looks like: THIS IS IN MAIN:
sf::Font txt_font;
txt_font.loadFromFile("F:\\C++VS\\Rigid_Ball_Physics\\Rigid_Ball_Physics\\arial.ttf");
if (!txt_font.loadFromFile("F:\\C++VS\\Rigid_Ball_Physics\\Rigid_Ball_Physics\\arial.ttf"))
throw("FAILED TO LOAD FONT");
ball.update_ball_vectors();
overlay.UPDATE(txt_font);
THIS IS THE SEPARATE FUNCTION
void INFO_DISPLAY::render_info_text(sf::Font font)
{
object_info_label.setFont(font);
object_info_label.setPosition(sf::Vector2f(0, 0));
object_info_label.setFillColor(sf::Color::Black);
}
void INFO_DISPLAY::update_info_display(
int selected_object,
float ball_radius,
sf::Vector2f ball_position,
sf::Vector2f ball_velocity)
{
object_info_label.setString(
"SELECTED OBJECT: " + std::to_string(selected_object) + "\n" +
"RADIUS: " + std::to_string(ball_radius) + "\n" +
"POSITION_X: " + std::to_string(ball_position.x) + "\n" +
"POSITION_Y: " + std::to_string(ball_position.y) + "\n" +
"VELOCITY_X: " + std::to_string(ball_velocity.x) + "\n" +
"VELOCITY_Y: " + std::to_string(ball_velocity.y) + "\n"
);
}
MAIN_OVERLAY::MAIN_OVERLAY(sf::Font font)
{
ID.set_info_display_position(0.0f, 0.0f);
ID.render_info_text(font);<--------------|THIS HERE
UI.set_user_interface_position(main_window_width - (UI.user_interface_width - 2), main_window_height - UI.user_interface_height);
}
I looked for others with similar issues, but the only one I could find had an answer about the font not being created in main.cpp, and so I did not exist outside of the separate class and Text was referring to no font. I fixed this in mine (or so I think) and the same problem persists.