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

Author Topic: [Solved] SFML Game.exe has stopped working.  (Read 8734 times)

0 Members and 1 Guest are viewing this topic.

33pwnt33

  • Newbie
  • *
  • Posts: 7
    • View Profile
[Solved] SFML Game.exe has stopped working.
« on: April 27, 2013, 10:22:07 pm »
I don't think there is anything wrong with my code, because when I compile in visual studio express 2012 (release mode) there are no errors.  Though when I try too open the application it says: "SFML Game.exe has stopped working".

Here is my code:
#include <SFML\Graphics.hpp>
#include <Windows.h>
#include <iostream>

//Variables
bool appon,collision;
int PlayerX,PlayerY,speed;

sf::RenderWindow wind(sf::VideoMode(800, 600), "PwntGame");
sf::CircleShape Player(20.f);
sf::RectangleShape Object1(sf::Vector2f(100, 100));
sf::RectangleShape Object2(sf::Vector2f(100, 100));

int main()
{
        using namespace std;
        appon = true;
        speed = 25;

        PlayerX = 380;
        PlayerY = 280;

        collision = true;

        //Initialize Objects
        Object1.setFillColor(sf::Color::Blue);
        Object1.setPosition(100, 100);

        Object2.setFillColor(sf::Color::Blue);
        Object2.setPosition(300, 100);
       
        while(appon)
        {
                Sleep(speed);

                //If Escape Key down
                if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)){
                        wind.close();
                        Sleep(1000);
                        system("cls");
                        cout<<endl<<"Shutting down"<<endl;
                        Sleep(500);
                        appon = false;
                }

                //If Slash key down
                if(sf::Keyboard::isKeyPressed(sf::Keyboard::Slash)){
                        cout<<"0010101110101010101";
                        cout<<"1010001010111010111";
                        cout<<"1010101011101010010";
                }

                //Collision
                if(collision){
                if(PlayerY == 200 && PlayerX>60 && PlayerX<200){PlayerY = PlayerY = 201;cout<<"SHIFT + C to toggle collision"<<endl;}
                if(PlayerY == 60 && PlayerX>60 && PlayerX<200){PlayerY = PlayerY = 59;cout<<"SHIFT + C to toggle collision"<<endl;}
                if(PlayerX == 60 && PlayerY>60 && PlayerY<200){PlayerX = PlayerX = 59;cout<<"SHIFT + C to toggle collision"<<endl;}
                if(PlayerX == 200 && PlayerY>60 && PlayerY<200){PlayerX = PlayerX = 201;cout<<"SHIFT + C to toggle collision"<<endl;}

                if(PlayerY == 200 && PlayerX>260 && PlayerX<400){PlayerY = PlayerY = 201;cout<<"SHIFT + C to toggle collision"<<endl;}
                if(PlayerY == 60 && PlayerX>260 && PlayerX<400){PlayerY = PlayerY = 59;cout<<"SHIFT + C to toggle collision"<<endl;}
                if(PlayerX == 400 && PlayerY>60 && PlayerY<200){PlayerX = PlayerX = 401;cout<<"SHIFT + C to toggle collision"<<endl;}
                if(PlayerX == 260 && PlayerY>60 && PlayerY<200){PlayerX = PlayerX = 259;cout<<"SHIFT + C to toggle collision"<<endl;}

                if(PlayerX<1){PlayerX = 1;cout<<"You Are Not Permited in This Area"<<endl;}
                if(PlayerY<1){PlayerY = 1;cout<<"You Are Not Permited in This Area"<<endl;}
                if(PlayerX>759){PlayerX = 759;cout<<"You Are Not Permited in This Area"<<endl;}
                if(PlayerY>559){PlayerY = 559;cout<<"You Are Not Permited in This Area"<<endl;}
                }

                //Keydowns
                if(sf::Keyboard::isKeyPressed(sf::Keyboard::A)){PlayerX = PlayerX-1;}
                if(sf::Keyboard::isKeyPressed(sf::Keyboard::S)){PlayerY = PlayerY+1;}
                if(sf::Keyboard::isKeyPressed(sf::Keyboard::D)){PlayerX = PlayerX+1;}
                if(sf::Keyboard::isKeyPressed(sf::Keyboard::W)){PlayerY = PlayerY-1;}
                if(sf::Keyboard::isKeyPressed(sf::Keyboard::O)){speed = speed-1;}
                if(sf::Keyboard::isKeyPressed(sf::Keyboard::P)){speed = speed+1;}
                if(sf::Keyboard::isKeyPressed(sf::Keyboard::LShift) && sf::Keyboard::isKeyPressed(sf::Keyboard::C) || sf::Keyboard::isKeyPressed(sf::Keyboard::RShift) && sf::Keyboard::isKeyPressed(sf::Keyboard::C)){
                        Sleep(500);
                        if(collision){
                                collision = false;
                        }
                        else{
                                collision = true;
                        }
                }

                if(speed>50){speed = 47;}
                if(speed<5){speed = 8;}

                //Player stuff

                Player.setPosition(PlayerX, PlayerY);
                Player.setFillColor(sf::Color::Red);

                //Draw Everything
                wind.clear();
                wind.draw(Player);
                wind.draw(Object1);
                wind.draw(Object2);
                wind.display();
        }
    return 0;
}
« Last Edit: April 30, 2013, 04:33:03 am by 33pwnt33 »

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: SFML Game.exe has stopped working.
« Reply #1 on: April 27, 2013, 10:34:37 pm »
sf::RenderWindow wind(sf::VideoMode(800, 600), "PwntGame");
Don't do that in global scope, that breaks SFML.
And as a side note, SFML has own sf::sleep, so don't include Windows and don't use \ in include paths because that will become a pain if you ever go out of Windows to something like Linux and it's little effort to just use /, it's actually easier.
Back to C++ gamedev with SFML in May 2023

33pwnt33

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: SFML Game.exe has stopped working.
« Reply #2 on: April 27, 2013, 10:42:24 pm »
Thanks for the response but the program still crashes when I open it.  The program works in debug mode but I want to compile it in release mode.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: SFML Game.exe has stopped working.
« Reply #3 on: April 27, 2013, 10:58:40 pm »
Thanks for the response but the program still crashes when I open it.
Well what did you change in between?

Besides, you should know the difference between compiler error, linker error and runtime error. The first one occurs when you get an error at compilation and is mainly due to wrong syntax. The second one happens when the linker fails to link the compiled objects, this is most likely a wrong project setup or incompatible library. The third one is the hardest of them all, since you don't directly get an error message and it happens when running the application and it crashes. In the last case you can utilize your debugger to find out what goes wrong. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: SFML Game.exe has stopped working.
« Reply #4 on: April 27, 2013, 11:04:20 pm »
Then maybe you're linking to debug libraries which should only be used in debug.
Back to C++ gamedev with SFML in May 2023

33pwnt33

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: SFML Game.exe has stopped working.
« Reply #5 on: April 30, 2013, 04:32:25 am »
Sorry guys, I solved the problem on my own.  I had pasted the code in visual studio 2010 instead of 2012 and compiled in debug.  After that I tried release (which didn't work).  But I noticed what had happened wasthat everything I linked in debug was not linked in release.

victorlevasseur

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: [Solved] SFML Game.exe has stopped working.
« Reply #6 on: April 30, 2013, 07:02:21 am »
Hello,

You have to link debug libraries with debug configuration and release libraries with release configuration.

 

anything