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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - Mysquff

Pages: [1]
1
I was trying to create a simple game and got stuck at the beginning. The app builds correctly and when launched throws exception with a message:
Quote
Exception thrown at 0x775F9F83 (ntdll.dll) in pong.exe: 0xC0000005: Access violation writing location 0x00000004.
Visual Studio Debugger points me at the line 6 in Window.cpp file ("This is the next statement to execute when this thread returns from the current function").

Apart from that I get IntelliSense errors only:
Quote
no instance of constructor "sf::ContextSettings::ContextSettings" matches the argument list pong Window.hpp 89
Quote
no instance of constructor "sf::ContextSettings::ContextSettings" matches the argument list pong Window.hpp 106
Quote
no instance of constructor "sf::ContextSettings::ContextSettings" matches the argument list pong Window.hpp 133
Quote
no instance of constructor "sf::ContextSettings::ContextSettings" matches the argument list pong Window.hpp 151
I searched for solution here and at StackExchange and I discovered it's not advisable to declare sf::Window as global. I don't do this, but it seems simply declaring it outside a function causes problems. Still I'd really like to have this object as Window static class member when the project grows bigger.

I remember a year ago on some earlier version on SFML I was able to declare it in such way without any problems.

Problem occurs in debug mode only. Program executes just fine in Release mode.

Could you help me? I don't really know what I am doing wrong. Here are all project files at the moment.

main.cpp

#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <SFML/Network.hpp>
#include "App.h"
#include "Window.h"

int main()
{
    App::run();


    return 0;
}

App.h
class App
{
private:
    static void     loop();

public:
    static void     run();
};

App.cpp
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <SFML/Network.hpp>
#include "Window.h"
#include "App.h"

void App::run()
{
    Window::initialize();

    loop();
}

void App::loop()
{
    while (Window::window.isOpen())
    {
        sf::Event event;
        while (Window::window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                Window::window.close();
        }
    }
}

Window.h
class Window
{

public:
    static void initialize();
    static sf::Window window;
};

Window.cpp
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <SFML/Network.hpp>
#include "Window.h"

sf::Window Window::window; // <--- This is the next statement to execute when this thread returns from the current function

void Window::initialize()
{
    window.create(sf::VideoMode::getDesktopMode(), "Pong");
}

Pages: [1]