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

Author Topic: Windows thinks my window is closing due to an error  (Read 4478 times)

0 Members and 1 Guest are viewing this topic.

Makuto

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
    • Au 79 Games
    • Email
Windows thinks my window is closing due to an error
« on: December 03, 2011, 04:47:05 am »
Hi!  In my code, for some reason when I purposely close the window, Windows gives me the "...encountered a problem and needs to close" error message following the closing of the window.  When I check if the window is opened and the check returns false, I just say break or return 1, but Windows thinks I errored up for some reason:
Code: [Select]

//Note that this is in my game loop
//This closes the window automatically if it detects the event (it works)
gm.checkToClose();
        //This uses sf::RenderWindow::IsOpened for the check
        if (gm.checkOpened()==false)
        {
            std::cout << "Window isn't opened, returning 1";
            return 1; //This does exit the program, but the command line
                          //used for debugging stays opened until Windows error
                          //shuts it down
        }

This will give me an error.  Note that I have isolated SFML, hence the other functions instead of the SFML functions.
Macoy Madson-Au 79 Games
Check out my work at http://augames.f11.us/
Most of my SFML-related code is here: https://github.com/makuto/personal/tree/master/gameDev/resources/base2.0
I try to KIS(S), do you?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Windows thinks my window is closing due to an error
« Reply #1 on: December 03, 2011, 10:06:12 am »
If Windows tells you that an error occured, then it's probably true ;)

Have you tried to run the debugger?
Laurent Gomila - SFML developer

Makuto

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
    • Au 79 Games
    • Email
Windows thinks my window is closing due to an error
« Reply #2 on: December 03, 2011, 03:52:04 pm »
I'm not sure exactly how to use the debugger, but I will learn eventually.  What could be causing the error?  A bad variable cleanup? A faulty window closing function? Would it matter that my connection to the sf::RenderWindow is through a pointer (ex: I close with App->Close() )?
Macoy Madson-Au 79 Games
Check out my work at http://augames.f11.us/
Most of my SFML-related code is here: https://github.com/makuto/personal/tree/master/gameDev/resources/base2.0
I try to KIS(S), do you?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Windows thinks my window is closing due to an error
« Reply #3 on: December 03, 2011, 04:10:29 pm »
Quote
I'm not sure exactly how to use the debugger

It's usually F5. It's enough to see where the crash happens, the type of the error and the call stack.

Quote
What could be causing the error? A bad variable cleanup? A faulty window closing function?

Yes, could be anything.

Quote
Would it matter that my connection to the sf::RenderWindow is through a pointer (ex: I close with App->Close() )?

Not directly, but there are typical errors associated to pointers. For example, it may crash if you use the window after deleting it. Or if your pointer is badly initialized.
Laurent Gomila - SFML developer

Makuto

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
    • Au 79 Games
    • Email
Windows thinks my window is closing due to an error
« Reply #4 on: December 03, 2011, 04:30:46 pm »
I'm pretty sure my pointer is alright.  Could it have something to do with not immediately quitting when sf::Event::Closed:
Code: [Select]

int checkToClose() //Basically, if it gets the event to close, close it and return 1 if closed (else 0)
    {
        App->GetEvent(Event);
        if (Event.Type==sf::Event::Closed)
        {
            App->Close();
            return 1;
        }
        else return 0;

    }

After that function returns 1 I then use return EXIT_SUCCESS to exit the program (after some cleanup).
Macoy Madson-Au 79 Games
Check out my work at http://augames.f11.us/
Most of my SFML-related code is here: https://github.com/makuto/personal/tree/master/gameDev/resources/base2.0
I try to KIS(S), do you?

Makuto

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
    • Au 79 Games
    • Email
Windows thinks my window is closing due to an error
« Reply #5 on: December 03, 2011, 04:46:57 pm »
It still crashes.  I think I can figure it out though.  Thanks for helping.
Macoy Madson-Au 79 Games
Check out my work at http://augames.f11.us/
Most of my SFML-related code is here: https://github.com/makuto/personal/tree/master/gameDev/resources/base2.0
I try to KIS(S), do you?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Windows thinks my window is closing due to an error
« Reply #6 on: December 03, 2011, 04:48:11 pm »
You should use the return value of GetEvent. If it's false, it means that no event is available, and what you do after that is undefined behaviour (the contents of the Event variable are undefined). You should also call it in a loop to be sure to process all pending events. This is explained in the tutorials.

And stop trying to guess, just press F5 and the debugger will tell you everything ;)
Laurent Gomila - SFML developer

Makuto

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
    • Au 79 Games
    • Email
Windows thinks my window is closing due to an error
« Reply #7 on: December 03, 2011, 04:59:37 pm »
Ignore the previous comment that I just edited.  In my compiler (code::blocks) F5 just toggles breakpoints.  When I hit start debugging (F8 ), the debugger opens the program, then the program closes instantly (and all the debugging toolbars and windows) and the debugging window is left with
Code: [Select]

Starting debugger:
done
Registered new type: wxString
Registered new type: STL String
Registered new type: STL Vector
Setting breakpoints
Debugger name and version: GNU gdb 5.2.1
Debugger finished with status 1
Macoy Madson-Au 79 Games
Check out my work at http://augames.f11.us/
Most of my SFML-related code is here: https://github.com/makuto/personal/tree/master/gameDev/resources/base2.0
I try to KIS(S), do you?

Makuto

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
    • Au 79 Games
    • Email
Windows thinks my window is closing due to an error
« Reply #8 on: December 04, 2011, 02:39:04 am »
Debugging aside (can't get the stupid thing to work), could not looping through all the events cause an error?  If not, it is definitely something wrong with my code, meaning I will pretty much have to re-code all of it (not all of my code, just everything to do with the App and the erroneous tile map system I previously questioned on (this isn't the main issue though, I have tried closing without displaying the maps at all)).  Thanks for helping me try and figure out how to debug though.
EDIT:  I've found it was a problem with my tile map parsing function (when I call it, the error will occur; when I omit it, the error doesn't occur), which is okay because I was planning on recoding it anyways.
Macoy Madson-Au 79 Games
Check out my work at http://augames.f11.us/
Most of my SFML-related code is here: https://github.com/makuto/personal/tree/master/gameDev/resources/base2.0
I try to KIS(S), do you?

Makuto

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
    • Au 79 Games
    • Email
Windows thinks my window is closing due to an error
« Reply #9 on: December 05, 2011, 02:56:00 pm »
Ok, I have NO idea why this function does anything to the error of the closing of the window, but it definitely does something (when I comment it out the window closes without errors):
Code: [Select]

 void parseMapFile()
    {
        std::string strBuffer="";
        std::cout << "Parsing..." << std::endl;
        int u=0;

        int buffer=0;
        bool foundNewLine=false;
        while (1)
        {
            strBuffer=mapFile[u];
            if (strBuffer=="$")
            {
                buffer=0;//Terminating caracter
                index[u]=buffer;
                break;
            }
            //This is going to be DIRTY
            if (strBuffer=="a") buffer=1;
            if (strBuffer=="b") buffer=2;
            if (strBuffer=="c") buffer=3;
            if (strBuffer=="d") buffer=4;
            if (strBuffer=="e") buffer=5;
            if (strBuffer=="f") buffer=6;
            if (strBuffer=="g") buffer=7;
            if (strBuffer=="h") buffer=8;
            if (strBuffer=="i") buffer=9;
            if (strBuffer=="j") buffer=10;
            if (strBuffer=="k") buffer=11;
            if (strBuffer=="l") buffer=12;
            if (strBuffer=="m") buffer=13;
            if (strBuffer=="n") buffer=14;
            if (strBuffer=="o") buffer=15;
            if (strBuffer=="p") buffer=16;
            if (strBuffer=="q") buffer=17;
            if (strBuffer=="r") buffer=18;
            if (strBuffer=="s") buffer=19;
            if (strBuffer=="t") buffer=20;
            if (strBuffer=="u") buffer=21;
            if (strBuffer=="v") buffer=22;
            if (strBuffer=="w") buffer=23;
            if (strBuffer=="x") buffer=24;
            if (strBuffer=="y") buffer=25;
            if (strBuffer=="z") buffer=26;
            if (buffer >=34433) buffer=1; //just in case
            index[u]=buffer;
            }
            u++;

        }
        std::cout << "Parsing done, processed "<<u<<" characters, or " << u/2 << " tiles."<< std::endl;
        strBuffer="";
        u=0;
        buffer=0;
        foundNewLine=false;
    }

Macoy Madson-Au 79 Games
Check out my work at http://augames.f11.us/
Most of my SFML-related code is here: https://github.com/makuto/personal/tree/master/gameDev/resources/base2.0
I try to KIS(S), do you?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Windows thinks my window is closing due to an error
« Reply #10 on: December 05, 2011, 03:06:56 pm »
What is the "index" array? How is it declared/resized? Is its size greater than 26?

Same questions about "mapFile".
Laurent Gomila - SFML developer

Makuto

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
    • Au 79 Games
    • Email
Windows thinks my window is closing due to an error
« Reply #11 on: December 06, 2011, 12:16:03 am »
Here are the declarations:
Code: [Select]

std::string mapFile;
int index[];

The index[] was never re sized.
Macoy Madson-Au 79 Games
Check out my work at http://augames.f11.us/
Most of my SFML-related code is here: https://github.com/makuto/personal/tree/master/gameDev/resources/base2.0
I try to KIS(S), do you?

Makuto

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
    • Au 79 Games
    • Email
Windows thinks my window is closing due to an error
« Reply #12 on: December 06, 2011, 04:19:23 am »
After declaring index[] as index[number], the error dissipated.  I learned how to use std::vector to get a dynamic array basically, and it works like a charm.  Thanks!
Macoy Madson-Au 79 Games
Check out my work at http://augames.f11.us/
Most of my SFML-related code is here: https://github.com/makuto/personal/tree/master/gameDev/resources/base2.0
I try to KIS(S), do you?

 

anything