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().
(https://cdn.discordapp.com/attachments/175298431294636032/700794917882167317/e5fe890470e00e20.png)
(https://cdn.discordapp.com/attachments/175298431294636032/700797181124149258/403e173ef04bcbea.png)
Code seems to work OK if I am not using vectors for storing Menu class.
C++ 17, SFML 2.5.1, VS 2019
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.
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:
int main()
{
std::vector<Menu> Menus;
Menus.push_back(Menu());
Menus.back().DrawMenu();
return 0;
}
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!