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

Author Topic: Not sure what this error means?  (Read 2780 times)

0 Members and 1 Guest are viewing this topic.

AndreeU17

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Not sure what this error means?
« on: June 04, 2014, 08:25:48 am »
I keep getting everytime i run my new Window, problems in loading. I run it and when the new Window pops out, it stops responding and i get an error saying that the Thread 1 is: sf::Window::isOpen() const:
Which i my perspective means that the my second While(gameWindow.isOpen()){} is running constantly without stop even though i inserted an if statement to test whether the user pressed either escape or close to close the program! I was wondering do i need to seperate events?

I just want an explanation for that error thats all! Everything else i can figure out myself, just a small vivid detail about what that error means in english!

Thanks Also i use a MAC OS X SFML, xCode 5 in case your curious!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Not sure what this error means?
« Reply #1 on: June 04, 2014, 08:57:28 am »
Please read the window tutorial carefully, there are limitations about threading and event processing, depending on the OS. Mac OS X is the worst in this regard.
Laurent Gomila - SFML developer

AndreeU17

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Re: Not sure what this error means?
« Reply #2 on: June 04, 2014, 07:18:42 pm »
oh okay thanks I will look over the window tutorial and try to figure it out if not i'll just do it in VisualStudio

AndreeU17

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Re: Not sure what this error means?
« Reply #3 on: June 04, 2014, 07:34:35 pm »
Please read the window tutorial carefully, there are limitations about threading and event processing, depending on the OS. Mac OS X is the worst in this regard.

So i read it, an apperantly Mac OS X can not handle multithreading, that isn't within the main thread. However this is what i'm working on
// Start the game loop
    while (mainWindow.isOpen())
    {
        // Process events
        sf::Event event;
        while (mainWindow.pollEvent(event))
        {
            // Close window : exit or Pressing Escape Key
            if (event.type == sf::Event::Closed || (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape))
            {
                mainWindow.close();
            }
           
            //Everything above works fine
            if(sf::Mouse::isButtonPressed(sf::Mouse::Left))//event.type == sf::Event::MouseButtonPressed) if button is pressed go ahead
            {
                if(sf::Mouse::getPosition(mainWindow).x > 100 && sf::Mouse::getPosition(mainWindow).x < 130) //If pressed button is between the text start, then run
                {
                    mainWindow.close(); //close main window
                    gameWindow.setVisible(true); //turn game window into on
                    sf::Event gameEvent;
                    while(gameWindow.isOpen()) //if game window is on, then run  ////The ERROR COMES OUT HERE
                    {
                        //Some code in here
                        // Close window : exit or Pressing Escape Key
                        if (gameEvent.type == sf::Event::Closed || (gameEvent.type == sf::Event::KeyPressed && gameEvent.key.code == sf::Keyboard::Escape))
                        {
                            gameWindow.close();
                        }
                    }
                }
            }
        }
 

I get the threaded problem in this line, while(gameWindow.isOpen())
Not sure how to make that be in the same main thread! How can i work around this? I would like to post the rest of the code but since i'm not trying to release what plans are in stored, i will only present what i believe and what the compiler issues out as error in that section !

I had a small understanding of thread (What they mean), but i never dabble in them so i have no idea how they work!

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: Not sure what this error means?
« Reply #4 on: June 04, 2014, 08:16:08 pm »
Quote
apparently Mac OS X can not handle multithreading
That's not quite true, fortunately. There're some limitations, sure, but you can still do things.

Quote
I had a small understanding of thread (What they mean), but i never dabble in them so i have no idea how they work!

Stop right there! Threads at first look relatively simple but they are NOT. Really. Do you a favor and learn what they are or you will end up losing your time and motivation.  ;)

BTW, putting an event loop inside another event loop is really bad. Using sf::Mouse::isButtonPressed or sf::Keyboard::isKeyPressed inside an event loop is also not great. The way you implemented it, your main window will simply freeze while the other is active. (EDIT: I didn't see you close the main window at some point. Your window will not freeze but that's not really a good design anyway.)
« Last Edit: June 04, 2014, 08:18:18 pm by Hiura »
SFML / OS X developer

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Not sure what this error means?
« Reply #5 on: June 04, 2014, 08:18:59 pm »
When the OS complains that your application is not responding that is usually caused by the application not processing events regularly.

About threads, I think you should read this forum thread: http://en.sfml-dev.org/forums/index.php?topic=15430.0 as well as the threads it links to.

AndreeU17

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Re: Not sure what this error means?
« Reply #6 on: June 04, 2014, 10:19:05 pm »
Quote
apparently Mac OS X can not handle multithreading
That's not quite true, fortunately. There're some limitations, sure, but you can still do things.

Quote
I had a small understanding of thread (What they mean), but i never dabble in them so i have no idea how they work!

Stop right there! Threads at first look relatively simple but they are NOT. Really. Do you a favor and learn what they are or you will end up losing your time and motivation.  ;)

BTW, putting an event loop inside another event loop is really bad. Using sf::Mouse::isButtonPressed or sf::Keyboard::isKeyPressed inside an event loop is also not great. The way you implemented it, your main window will simply freeze while the other is active. (EDIT: I didn't see you close the main window at some point. Your window will not freeze but that's not really a good design anyway.)

When you mean event loop your refering to this correct:
while(gameWindow.isOpen()) //if game window is on, then run  ////The ERROR COMES OUT HERE
                    {
                        //Some code in here
                        // Close window : exit or Pressing Escape Key
                        if (gameEvent.type == sf::Event::Closed || (gameEvent.type == sf::Event::KeyPressed && gameEvent.key.code == sf::Keyboard::Escape))
                        {
                            gameWindow.close();
                        }
                    }
 

How else can i improve this or fix it? I would really appreciate the help !

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Not sure what this error means?
« Reply #7 on: June 04, 2014, 10:21:04 pm »
Event loops are explained in the official tutorial, please read it carefully.

And avoid full quotes, it is usually enough to quote only the specific passage you refer to.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development: