Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: texture.loadfromfile causes crash?  (Read 1678 times)

0 Members and 1 Guest are viewing this topic.

ThatOneGuyThatDoesStuff

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • Email
texture.loadfromfile causes crash?
« 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?

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: texture.loadfromfile causes crash?
« Reply #1 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.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything