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

Author Topic: [SOLVED] Access Violation in RenderWindow as global, with Visual Studio 2017  (Read 2588 times)

0 Members and 1 Guest are viewing this topic.

rogeriodec

  • Newbie
  • *
  • Posts: 42
    • View Profile
I'm working on a project with Code:Blocks and I decided to migrate to Visual Studio 2017.
Everythig was ok with this project on CB, but now on VS I get a runtime error "Access Violation" on some SFML Classes. They are outside "main".

For example, in any project, just put "Renderwindow" line outside main and you will get the "Access Violation" runtime error:

sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
int main()
Error:
Code: [Select]
Unhandled exception at 0x00007FF8DF70B709 (ntdll.dll) in teste.exe: 0xC0000005: Access violation writing location 0x0000000000000008. occurred
But I need these classes as Global, and as I said, it was ok on CB, so, how can I solve this?
« Last Edit: May 30, 2018, 04:31:42 pm by rogeriodec »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10821
    • View Profile
    • development blog
    • Email
Don't use SFML resources including the SFML window as globals. SFML doesn't support this and it's bad design anyways.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

rogeriodec

  • Newbie
  • *
  • Posts: 42
    • View Profile
Since I am still a beginner in C++, I am gradually discovering the most common practices in this language, and after reading several opinions, I have realized that global variables are contraindicated in more than 90% of cases because it is dangerous and difficult to control.
I am refactoring my code and I have managed to resolve this error.
Thank you again.

 

anything