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

Author Topic: Access violation with sf::Texture, only in Debug  (Read 1632 times)

0 Members and 1 Guest are viewing this topic.

kennyrkun

  • Newbie
  • *
  • Posts: 9
  • a pretty mediocre programmer
    • View Profile
    • mehsowb
Access violation with sf::Texture, only in Debug
« on: January 19, 2018, 04:07:54 am »
Creating a simple server-client demo, and the Client will not run when compiled in Debug mode via Visual Studio.

The offending code:
#include <SFML/Graphics.hpp>

sf::Texture tex;

int main()
{
}
 

Run in a debugger, the program crashes immediately a points to the declaration of tex as the culprit.
 
Quote from: Visual Studio
Exception thrown at 0x77E90E72 (ntdll.dll) in Client.exe: 0xC0000005: Access violation writing location 0x00000004.

This only happens when compiled in debug mode. If I remove the declaration of tex, it compiles and runs with no issues, so I don't believe I have any linker mismatches, but just in case, here's the call stack Visual Studio reports:



I have no idea what's causing this so called access violation. It's only now that it's causing this issue, where yesterday, and a month ago, all was well. The accompanying server project has a few variables in the global scope of main.cpp and it compiles and runs in both debug and release with no issues.

save me.
it's probably terrible.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Access violation with sf::Texture, only in Debug
« Reply #1 on: January 19, 2018, 06:37:25 am »
It's generally a good idea to avoid declaring SFML resource classes at global scope, as they sometimes need to make calls that rely on other globals (like here) that may not be initialized yet.

Regarding this specific one, I may be wrong but I think it might be "fixed" in the latest sources.
Laurent Gomila - SFML developer

netrunner

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: Access violation with sf::Texture, only in Debug
« Reply #2 on: December 18, 2019, 08:43:34 am »
Creating a simple server-client demo, and the Client will not run when compiled in Debug mode via Visual Studio.

The offending code:
#include <SFML/Graphics.hpp>

sf::Texture tex;

int main()
{
}
 

Run in a debugger, the program crashes immediately a points to the declaration of tex as the culprit.
 
Quote from: Visual Studio
Exception thrown at 0x77E90E72 (ntdll.dll) in Client.exe: 0xC0000005: Access violation writing location 0x00000004.

This only happens when compiled in debug mode. If I remove the declaration of tex, it compiles and runs with no issues, so I don't believe I have any linker mismatches, but just in case, here's the call stack Visual Studio reports:



I have no idea what's causing this so called access violation. It's only now that it's causing this issue, where yesterday, and a month ago, all was well. The accompanying server project has a few variables in the global scope of main.cpp and it compiles and runs in both debug and release with no issues.

save me.

Hey, Kenny!

I'm having this issue too, and I'm not having a particularly easy time fixing it. It's been a few months since you've posted this thread (sorry for the necro), would you happen to remember what the problem was/how you went about fixing it?

Thanks in advance.

 

anything