1
General / Re: Im getting exception thrown "Access violation reading location"
« on: September 27, 2023, 01:47:54 am »
I haven't tried running the code, but looking over it I'd guess the issue is how you are storing fonts.
When you set the font of a Text object, it stores it as a Font pointer. You load and store the font as part of your MenuBtn class.
Pushing temporary MenuBtn objects into a vector will result in the MenuBtn moving around in memory. But that breaks the Font pointer.
You'll need to make sure the Font doesn't move around.
(Also, it's not part of the crash, but loading a copy of a font for each button is inefficient. You only need one copy of the font then tell all Text objects to use the same one)
When you set the font of a Text object, it stores it as a Font pointer. You load and store the font as part of your MenuBtn class.
Pushing temporary MenuBtn objects into a vector will result in the MenuBtn moving around in memory. But that breaks the Font pointer.
You'll need to make sure the Font doesn't move around.
(Also, it's not part of the crash, but loading a copy of a font for each button is inefficient. You only need one copy of the font then tell all Text objects to use the same one)