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

Author Topic: Two Windows  (Read 3679 times)

0 Members and 1 Guest are viewing this topic.

Wander

  • Full Member
  • ***
  • Posts: 170
    • View Profile
    • Email
Two Windows
« on: September 05, 2010, 08:19:40 am »
I've been trying for the past 2 hours to get my program to use two windows at the same time, but I can't succeed. Can someone help me out here? I've tried using threads. I think I'm just using them wrong.
-Wander

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Two Windows
« Reply #1 on: September 05, 2010, 10:16:18 am »
Can you show us what you tried?
Laurent Gomila - SFML developer

Wander

  • Full Member
  • ***
  • Posts: 170
    • View Profile
    • Email
Two Windows
« Reply #2 on: September 05, 2010, 07:25:29 pm »
I actually just figured it out, but I have a question. Here is the code for my thread:

Code: [Select]
void extraWindow(void *UserData)
{
    sf::Window App2(sf::VideoMode::GetMode(1), "Laz's Interactive Map :: The Wrath... :: PvP Created");
    while (App2.IsOpened())
    {
        std::cout << "hi";
        sf::Event ThreadEvent;
        while (App2.GetEvent(ThreadEvent))
        {
            // Close window : exit
            if (ThreadEvent.Type == sf::Event::Closed)
            {
                App2.Close();
            }

            // Press escape : exit
            if ((ThreadEvent.Type == sf::Event::KeyPressed) && (ThreadEvent.Key.Code == sf::Key::Escape))
                App2.Close();
        }
    }
}


As you can see it creates a window and then waits for an event to close the window. When the window is closed, does the thread keep running? If so, is that bad? If so, is there a way to shut it down from inside the thread?
-Wander

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Two Windows
« Reply #3 on: September 05, 2010, 07:30:50 pm »
The thread ends when the function is terminated, which happens when the window is closed, so... yes, the thread should end when you close the window.
Laurent Gomila - SFML developer

Wander

  • Full Member
  • ***
  • Posts: 170
    • View Profile
    • Email
Two Windows
« Reply #4 on: September 05, 2010, 07:31:37 pm »
Okay thank you. :)
-Wander

Wander

  • Full Member
  • ***
  • Posts: 170
    • View Profile
    • Email
Two Windows
« Reply #5 on: September 05, 2010, 08:18:35 pm »
Okay! Weird thing just happened. I hit the F2 button to start the thread and then I used the 'esc' event I had to close the window with. The secondary window closed and my main window came back up and then went unresponsive....

Know of any causes of that?
-Wander

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Two Windows
« Reply #6 on: September 05, 2010, 08:31:18 pm »
What's the code of your main thread?
Laurent Gomila - SFML developer

Wander

  • Full Member
  • ***
  • Posts: 170
    • View Profile
    • Email
Two Windows
« Reply #7 on: September 05, 2010, 08:33:06 pm »
It's that super long this that you told me to compress in our other posting thread. Would you like me to post the whole thing? I'm not really sure how to compress it since I don't know what the problem is.
-Wander

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Two Windows
« Reply #8 on: September 05, 2010, 08:38:21 pm »
Maybe you can just keep the part that's relevant? If you're not sure what to keep, remove parts of code little by little, and stop when the problem disappears ;)
Laurent Gomila - SFML developer

Wander

  • Full Member
  • ***
  • Posts: 170
    • View Profile
    • Email
Two Windows
« Reply #9 on: September 05, 2010, 08:43:40 pm »
It doesn't crash every time. So I don't know what part of code could possible mess up one time and then not mess up the next.
-Wander

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Two Windows
« Reply #10 on: September 05, 2010, 08:53:02 pm »
Yes, with a big code the problem is often harder to identify. If you can reduce it to the minimum (and I'm not saying it's easy, sometimes it requires a full day of work), you'll be able to find out what's going on more easily.
Laurent Gomila - SFML developer