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

Author Topic: Access violation reading location  (Read 1744 times)

0 Members and 1 Guest are viewing this topic.

Satsu13

  • Newbie
  • *
  • Posts: 1
    • View Profile
Access violation reading location
« on: May 13, 2013, 05:35:54 am »
I am using MSVC 2010 with the latest version of SFML.  I can't tell if this is just a problem with my c++ code or if I am using the SFML library wrong, hence why I am posting it here.

Here is my code:
http://pastebin.com/5MJTqcVU

Debugging it works perfectly until the very end when main returns (line 78), where I get the following error:

Unhandled exception at 0x77b7a4de in testProject5.exe: 0xC0000005: Access violation reading location 0xfeeefef6.

A quick google search tells me that this error occurs when I have a null pointer, but I don't actually initialize any pointers in my code so I have no idea where this is coming from...

Anyways I've spent about five hours trying to figure out whats going on, so any help would be appreciated!  If you need any more info that I forgot to provide just let me know.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11037
    • View Profile
    • development blog
    • Email
Re: Access violation reading location
« Reply #1 on: May 13, 2013, 09:20:42 am »
You "mistake" is in line 31 and 32:
std::unordered_map <std::string, sf::Texture> TS::textureMap;
TS::TS(){}

You're using global variables and initialize them in the global scope, thus the order destruction of your resources and SFML resources is undefined and when crashing your part gets destroyed before SFML's part, but since your parts depend on SFML it crashes. ;)

In short: Don't use global variables, but learn how to use a better code design.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/