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

Author Topic: Unhandled exception at 0x77AB22C2 (ntdll.dll)  (Read 7324 times)

0 Members and 1 Guest are viewing this topic.

Pein95

  • Newbie
  • *
  • Posts: 4
    • View Profile
Unhandled exception at 0x77AB22C2 (ntdll.dll)
« on: August 30, 2013, 07:22:20 pm »
//Game.h
#pragma once
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>

class Game
{
public:
        static void Start();

private:
        static bool IsExiting();
        static void GameLoop();

        enum GameState {Uninitialized, ShowingSplash, Paused,
                ShowingMenu, Playing, Exiting};

        static GameState _gameState;
        static sf::RenderWindow _mainWindow;
};
 

#include "Game.h"


Game::GameState Game::_gameState = Uninitialized;
sf::RenderWindow Game::_mainWindow;


void Game::Start()
{
        if (_gameState != Uninitialized)
                return;

        _mainWindow.create(sf::VideoMode(1024, 768,32), "Pang!");
        _gameState = Game::Playing;

        while (!IsExiting())
        {
                GameLoop();
        }

        _mainWindow.close();
}


bool Game::IsExiting()
{
        if (_gameState == Game::Exiting)
                return true;
        else
                return false;
}

void Game::GameLoop()
{
        sf::Event currentEvent;
        while(_mainWindow.pollEvent(currentEvent))
        {
                switch (_gameState)
                {
                case Game::Playing:
                        {
                                _mainWindow.clear(sf::Color(255,0,0));
                                _mainWindow.display();

                                if(currentEvent.type == sf::Event::Closed)
                                {
                                        _gameState = Game::Exiting;
                                }
                                break;
                        }
                       
                       

                }
        }
}


 

I have error in this line: sf::RenderWindow Game::_mainWindow;.
How I can fix it?
Sorry for my English) it is not my native English)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10801
    • View Profile
    • development blog
    • Email
Re: Unhandled exception at 0x77AB22C2 (ntdll.dll)
« Reply #1 on: August 30, 2013, 07:34:18 pm »
Don't use static (= global) variables, especially not for SFML objects like sf::RenderWindow.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Pein95

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Unhandled exception at 0x77AB22C2 (ntdll.dll)
« Reply #2 on: August 30, 2013, 07:39:05 pm »
Thanks)

cmbrgames

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Unhandled exception at 0x77AB22C2 (ntdll.dll)
« Reply #3 on: August 30, 2013, 09:45:30 pm »
I've got the same error when I try to run my project compiled in Debug. In Release it works fine. I'm using Visual Studio 2012.

Don't use static (= global) variables, especially not for SFML objects like sf::RenderWindow.

So is this code below wrong when using SFML? I use this to share textures between different types of entities in my game and to load them only once at the start of the game for each type of entity.

Code: [Select]
class Monster : public Thing
{
private:
    static std::vector<sf::Texture> textures;
public:
    static bool loadTextures();
}
« Last Edit: August 30, 2013, 09:55:02 pm by cmbrgames »

Jove

  • Full Member
  • ***
  • Posts: 114
    • View Profile
    • http://www.jestofevekites.com/
Re: Unhandled exception at 0x77AB22C2 (ntdll.dll)
« Reply #4 on: August 31, 2013, 01:03:53 am »
Pein95, out of interest are you using SFML 2.1?
{much better code}

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10801
    • View Profile
    • development blog
    • Email
Re: Unhandled exception at 0x77AB22C2 (ntdll.dll)
« Reply #5 on: August 31, 2013, 01:24:43 am »
So is this code below wrong when using SFML? I use this to share textures between different types of entities in my game and to load them only once at the start of the game for each type of entity.

class Monster : public Thing
{
private:
    static std::vector<sf::Texture> textures;
public:
    static bool loadTextures();
}
 
Short answer: Yes

Longer answer: There are two factors:
The issue specifically with SFML is, that SFML itself initializes stuff globally on its own and since the order of destruction in the global scope is undefined, one will run into crashes when the random order doesn't line up as imagined. So one has to make sure, that everything gets instantiated and destroyed in a local scope.

The other factor is a discussion on code design and this has comes always with some controversy. For me and many other people with orientation for modern design, global variables, which include static class member, are in most cases a bad design.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Unhandled exception at 0x77AB22C2 (ntdll.dll)
« Reply #6 on: August 31, 2013, 01:34:45 am »
A cleaner design would be a separate class that has the responsibility of managing the textures. This can be a simple wrapper around std::vector<sf::Texture>, or something more elaborate like the ResourceHolder with a std::map we used in the book.

The advantages are clearly-defined lifetimes (you know when the resources are constructed and destroyed), separate responsibilities (Monster needn't care about correct loading, it can simply request a texture) and reusability (you can use the texture loading functionality for other classes than Monster).
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

cmbrgames

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Unhandled exception at 0x77AB22C2 (ntdll.dll)
« Reply #7 on: September 01, 2013, 03:55:48 pm »
Thanks. I'll try to remove the static stuff from my game and see if it works in Debug. The ResourceHolder using std::map is a good idea, because at the moment I have to worry about loading them in correct order and using index numbers.

[edit]
Removing static stuff fixed it and now it works in Debug mode too. Also it seemed to fix another problem with slowly rising memory usage. My game would initially use up 40MB and rise even up to 150MB for some reason, now it seems to keep the usage steady around ~37MB.
« Last Edit: September 02, 2013, 09:00:17 pm by cmbrgames »

 

anything