You're creating temporary fonts, assigning them to texts and then allowing them to be destroyed. Drawing that text then attempts to use the font that no longer exists and results in an access violation.
Fonts must exist as long as they are used.
This means that it - like other (heavy) resources (like images and sound buffers) - should be loaded once (usually in advance, near the beginning) and reused. It should be stored safely and passed (by reference or pointer) around to functions that need them. They should almost never be destroyed!
Basic example:
void drawAText(sf::Font& font, sf::RenderWindow& window)
{
sf::Text text;
text.setFont(font);
text.setString("SOME TEXT");
window.draw(text);
}
int main()
{
sf::Font font;
if (!font.loadFromFile("font.ttf"))
return EXIT_FAILURE;
sf::RenderWindow window(sf::VideoMode(800u, 600u), "");
while (window.isOpen())
{
// handle events here as usual
window.clear();
drawAText(font, window);
window.display();
}
}