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

Author Topic: Unhandled exception on window creation  (Read 2450 times)

0 Members and 1 Guest are viewing this topic.

ansh93

  • Newbie
  • *
  • Posts: 10
    • View Profile
Unhandled exception on window creation
« on: November 02, 2012, 09:06:52 pm »
#include <SFML\Graphics.hpp>
#include <SFML\System.hpp>
#include <SFML\Window.hpp>
#include <iostream>

using namespace std;

int main()
{
        int x=0,y=0;

        sf::VideoMode myMode(640,480,32);
        sf::RenderWindow myWindow(myMode,"board test");

        sf::Texture myTexture;
        if(!myTexture.loadFromFile("C:\\Users\\Voldy\\Documents\\Blue Tile.png"))
        {
                cout << " Could not load image" << endl ;
                return 0;
        }
        sf::Sprite mySprite(myTexture);
        sf::Event event;

        while (myWindow.isOpen())
        {
                while (myWindow.pollEvent(event))
                {
                        if(event.type == sf::Event::Closed || event.key.code == sf::Keyboard::Escape)
                        {
                                myWindow.close();
                        }
                        sf::IntRect myRect(x,y,32,32);
                        mySprite.setTextureRect(myRect);
                        myWindow.clear();
                        myWindow.draw(mySprite);
                        myWindow.display();
                }
        }


}

This is the code i am trying to run everything works fine
but when I try to run it i get an error saying "Unhandled exception at 0x75a6f7cc in board render tes.exe: 0xC0000005: Access violation reading location 0x65742064.".
previously i was able to run the projects of sfml
no such error occurred.
now also i use the old projects and just write the code in them and works perfectly fine but if i make any new project i get this error.
please help me to solve this error

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Unhandled exception on window creation
« Reply #1 on: November 02, 2012, 09:17:21 pm »
event.key.code == sf::Keyboard::Escape
Try removing that first. Did you step through code with debugger to see where exactly it crashes?
Back to C++ gamedev with SFML in May 2023

ansh93

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Unhandled exception on window creation
« Reply #2 on: November 03, 2012, 07:29:31 am »
yah i already saw the debugger
it crashes at the line for window creation

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Unhandled exception on window creation
« Reply #3 on: November 03, 2012, 12:53:52 pm »
Are you sure you're not using .dlls and .libs compiled with other version of your compiler?
Back to C++ gamedev with SFML in May 2023

cooldog99

  • Jr. Member
  • **
  • Posts: 95
    • View Profile
    • Perilous Game Studios
Re: Unhandled exception on window creation
« Reply #4 on: November 03, 2012, 01:00:06 pm »
This is the code i am trying to run everything works fine
but when I try to run it i get an error saying "Unhandled exception at 0x75a6f7cc in board render tes.exe: 0xC0000005: Access violation reading location 0x65742064.".
previously i was able to run the projects of sfml
no such error occurred.
now also i use the old projects and just write the code in them and works perfectly fine but if i make any new project i get this error.
please help me to solve this error


As far as creating at creation of window, i'm not 100% sure.
but there is ONE problem with your code.

You have these lines:

            sf::IntRect myRect(x,y,32,32);
            mySprite.setTextureRect(myRect);
            myWindow.clear();
            myWindow.draw(mySprite);
            myWindow.display();
 

inside the second while loop, when it should be under :)

so it'll be this:
#include <SFML\Graphics.hpp>
#include <SFML\System.hpp>
#include <SFML\Window.hpp>
#include <iostream>

using namespace std;

int main()
{
        int x=0,y=0;

        sf::VideoMode myMode(640,480,32);
        sf::RenderWindow myWindow(myMode,"board test");

        sf::Texture myTexture;
        if(!myTexture.loadFromFile("C:\\Users\\Voldy\\Documents\\Blue Tile.png"))
        {
                cout << " Could not load image" << endl ;
                return 0;
        }
        sf::Sprite mySprite(myTexture);
        sf::Event event;

        while (myWindow.isOpen())
        {
                while (myWindow.pollEvent(event))
                {
                        if(event.type == sf::Event::Closed || event.key.code == sf::Keyboard::Escape)
                        {
                                myWindow.close();
                        }

                }
                        sf::IntRect myRect(x,y,32,32);
                        mySprite.setTextureRect(myRect);
                        myWindow.clear();
                        myWindow.draw(mySprite);
                        myWindow.display();
        }


}


As FRex said, make sure your linker and includes are correct.

Maybe rebuild SFML lib, and remove all old SFML (if any)
« Last Edit: November 03, 2012, 01:02:53 pm by cooldog99 »