SFML community forums

Help => General => Topic started by: EldarFara on April 18, 2020, 01:41:20 am

Title: (Solved) Read access violation with unknown reason
Post by: EldarFara on April 18, 2020, 01:41:20 am
Hello! I am getting read access violation while running game code, here is a minimal example:
https://pastebin.com/cEqKDaGk
It is designed to render some sprites to the RenderTexture and then render it to the window.
Exception occures on any line of Menu::DrawMenu().
(click to show/hide)
Code seems to work OK if I am not using vectors for storing Menu class.
C++ 17, SFML 2.5.1, VS 2019
Title: Re: Read access violation with unknown reason
Post by: Laurent on April 18, 2020, 09:52:23 am
Quote
Menus.push_back(&Menu());
You're storing the address of a temporary object. It is destroyed immediately so the address points to garbage after this line.
Title: Re: Read access violation with unknown reason
Post by: EldarFara on April 18, 2020, 12:33:36 pm
Thanks for your answer. I changed vector of object pointers to vector of objects (changed RenderTexture to RenderTexture* to make copy assignment possible) and now main() looks like this:
(click to show/hide)

This time, I get read access violation "this was 0x30" on the line with drawing to the window.

EDIT: I simplified code so much (to show a minimal example) that I deleted part with creating window, thats why I got read access violation. Problem is solved now. Cheers!