SFML community forums

Help => Graphics => Topic started by: ThatOneGuyThatDoesStuff on July 07, 2020, 10:42:58 pm

Title: texture.loadfromfile causes crash?
Post by: ThatOneGuyThatDoesStuff on July 07, 2020, 10:42:58 pm
2 Textures, no different than all the others I have loaded, cause the program to crash immediately. They are private variables inside a class, and I loadFromFile() in the constructor, but trying to load from anywhere else, even in main{}, causes a crash.. I have done this with plenty other classes and textures, but these two in particular are just causing a crash. By changing them to global variables, they load fine.

Any idea why this might be happening?
Title: Re: texture.loadfromfile causes crash?
Post by: Hapax on July 08, 2020, 12:44:32 am
Without seeing any code, I would guess that you're passing the font around by value which makes copies. Passing by reference (or pointer) would allow any operations on it to be done directly to the actual font rather than a (temporary?) copy.

If a text is pointing to a font and that font disappears/gets destroyed then the text is now pointing to invalid memory and can cause these crashes.