Autor Beitrag
Kasko
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 126
Erhaltene Danke: 1

Win 10
C# C++ (VS 2017/19), (Java, PHP)
BeitragVerfasst: Fr 14.09.18 01:37 
Main.cpp:
ausblenden C++-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
#include <iostream>
#include "Definitions.h"

#include "Game.h"

int main() {
  AFKGames::Game(SCREEN_WIDTH, SCREEN_HEIGHT, "Flappy Bird");
  return EXIT_SUCCESS;
}


Game.h:
ausblenden C++-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
#include <string>

#include <SFML/Graphics.hpp>

#include "AssetManager.h"
#include "InputManager.h"
#include "StateMachine.h"

namespace AFKGames {
  struct GameData {
    StateMachine machine;
    sf::RenderWindow window;
    AssetManager assets;
    InputManager input;
  };

  typedef std::shared_ptr<GameData> GameDataRef;

  class Game {
  public:
    Game(int width, int height, std::string title);

  private:
    const float deltaTime = 1.0f / 60;
    sf::Clock _clock;

    GameDataRef _data = std::make_shared<GameData>();
    void Run();
  };
}


Game.cpp:
ausblenden C++-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
#include "Game.h"
#include "SplashState.h"

namespace AFKGames {
  Game::Game(int width, int height, std::string title) {
    _data->window.create(sf::VideoMode(width, height), title, sf::Style::Default); // <----------------- Hier tritt der Fehler auf
    _data->machine.AddState(StateRef(new SplashState(this->_data)));
    this->Run();
  }

  void Game::Run() {
    // MainLoop
  }
}


Fehlermeldung: Ausnahme ausgelöst bei 0x5095FBC6 (sfml-system-d-2.dll) in Flappy Bird.exe: 0xC0000005: Zugriffsverletzung beim Lesen an Position 0xCCCCCCD8.

Irgendwelche Ideen?

LG Kasko
Kasko Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 126
Erhaltene Danke: 1

Win 10
C# C++ (VS 2017/19), (Java, PHP)
BeitragVerfasst: So 16.09.18 21:39 
Andere Foren können mir auch nicht helfen
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4764
Erhaltene Danke: 1052

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Mo 17.09.18 08:55 
Was sagt denn der Debugger? Sind die Variablen (z.B. _data und dessen Inhalt) alle korrekt initialisiert?

PS: Und Crossposts bitte hier angeben!
Kasko Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 126
Erhaltene Danke: 1

Win 10
C# C++ (VS 2017/19), (Java, PHP)
BeitragVerfasst: Mo 17.09.18 14:55 
siehe Anhang -> Screen

es scheint als würde alles korrekt initialisiert werden. Wenn ich mit F11 debugge werden die Konstruktoren ausgeführt und danach tritt der Fehler auf.

Post in anderem Forum: stackoverflow.com/qu...d-2-dll?noredirect=1
Einloggen, um Attachments anzusehen!
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4764
Erhaltene Danke: 1052

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Mo 17.09.18 16:15 
Wie lautet denn der Stacktrace bei der Exception? Also passiert dies innerhalb des create-Aufrufs oder erst bei der Zuweisung?

Du könntest auch mal versuchen direkt den Konstruktor zu verwenden anstatt die create()-Funktion:
ausblenden C+*
1:
2:
3:
4:
5:
Game::Game(int width, int height, std::string title) :
    _data->window(sf::VideoMode(width, height), title, sf::Style::Default)
{
  // ...
}
(bin mir aber gerade unsicher, ob dies syntaktisch so zulässig ist...)

Funktioniert der Code denn, wenn du direkt sf::RenderWindow window als Member der Klasse Game deklarierst (also ohne den shared_ptr)?