0

im currently making on my 2D game and i have a error that i dont understand, here is screenshot of the rror: enter image description here

here is code for main:

#include "Game.h"
#include "Player.h"

void Run(RenderWindow &window, Sprite &player, Texture &PlayerTex);

int main(RenderWindow &window, Sprite &player, Texture &PlayerTex) {

Run(window, player, PlayerTex);

return 0;
}

void InitWindow() {

RenderWindow window(VideoMode(1920, 1080), "Discord Game");

}

void Update() {



}

void Render(RenderWindow &window, Sprite &player) {

player.setScale(0.3f, 0.3f);

window.clear(Color::White);
window.draw(player);
window.display();

}

void Run(RenderWindow &window, Sprite &player, Texture &PlayerTex) {

InitWindow();

while (window.isOpen()) {

    Event sfEvent;
    while (window.pollEvent(sfEvent)) {

        if (sfEvent.type == Event::Closed)
            window.close();

    }

    Update();
    Render(window, player);
    Player P;
    P.PlayerMovement(player);

}

}

code for Player.H:

#pragma once

#include "Game.h"

class Player {

public:
    Sprite player;
    Texture PlayerTex;
    void PlayerTexture(Sprite &Player, Texture &PlayerTex);
    void PlayerMovement(Sprite &Player);

};

code for Player.cpp:

#include "Game.h"
#include "Player.h"

void Player::PlayerTexture(Sprite& player, Texture& PlayerTex) {

PlayerTex.loadFromFile("textures/Player/PlayerFront.png");
player.setTexture(PlayerTex);

}

void Player::PlayerMovement(Sprite &player) {

if (Keyboard::isKeyPressed(Keyboard::A)) {

    
    player.move(-5.f, 0.f);

}

if (Keyboard::isKeyPressed(Keyboard::D)) {

    player.move(5.f, 0.f);

}

if (Keyboard::isKeyPressed(Keyboard::W)) {

    player.move(0.f, -5.f);

}

if (Keyboard::isKeyPressed(Keyboard::S)) {

    player.move(0.f, 5.f);

}

}

and then i have Game.H just to include stuff and for the future, here is code for Game.h:

#pragma once

#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Network.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
#include <iostream>
using namespace sf;

class Game {



};

and then empty Game.cpp:

#include "Game.h"
TheJaki
  • 27
  • 1
  • 1
    You have a null pointer dereference. – drescherjm Dec 31 '20 at 22:45
  • 1
    In `InitWindow()` you create a window then throw it away. You have a different window object in `Run()` – drescherjm Dec 31 '20 at 22:47
  • 1
    `int main(RenderWindow &window, Sprite &player, Texture &PlayerTex) {` is not a valid signature for the main function. Related: [https://stackoverflow.com/questions/4207134/what-is-the-proper-declaration-of-main](https://stackoverflow.com/questions/4207134/what-is-the-proper-declaration-of-main) – drescherjm Dec 31 '20 at 22:49

0 Answers0