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

Author Topic: Multiple Windows Overlapping Issue  (Read 6092 times)

0 Members and 1 Guest are viewing this topic.

Reborn121

  • Newbie
  • *
  • Posts: 16
    • View Profile
Multiple Windows Overlapping Issue
« on: December 06, 2014, 08:55:34 pm »
So, I have two windows, they both work, they issue is when I tried to interact with the second window while it is above the first window, as soon as I move the first window away, then click back to the seconds window I can interact with it without any problems. My code is below.

        //Declare both RenderWindows
        sf::RenderWindow F1Menu;
        sf::RenderWindow MainWin;

        //Create the Main Window
        MainWin.create(sf::VideoMode(800, 600), "SFML 2D");

        sf::View MainView(sf::FloatRect(0, 0, 1600, 1200));
        MainView.setViewport(sf::FloatRect(0, 0, 1, 1));

        MainWin.setView(MainView);
   
    //Loop while either window is open.
    while (MainWin.isOpen() || F1Menu.isOpen())
    {
        sf::Event Event;
                //Main Window got an event
                if (MainWin.pollEvent(Event))
                {
                        switch (Event.type)
                        {
                                case sf::Event::Closed:
                                        MainWin.close();
                                break;

                                case sf::Event::Resized:
                                        MainView.reset(sf::FloatRect(0.f, 0.f, MainWin.getSize().x, MainWin.getSize().y));
                                        MainWin.setView(MainView);
                                break;

                                case sf::Event::KeyPressed:
                                        if (Event.key.code == sf::Keyboard::F1)
                                                //Create the second window when F1 is pressed.
                                                F1Menu.create(sf::VideoMode(200, 500), "SFML 2D - F1 Menu");
                                        else if (Event.key.code == sf::Keyboard::Escape)
                                                MainWin.close();
                                break;
                        }
        }

                //Second Window got an event.
                if (F1Menu.pollEvent(Event))
                {
                        switch (Event.type)
                        {
                                case sf::Event::Closed:
                                        F1Menu.close();
                                break;
                        }
                }

                //The Main window is the top window
                if (MainWin.isOpen())
                {
                        MainWin.clear();
                        MainWin.display();
                }

                //Second Window is top window.
                if (F1Menu.isOpen())
                {
                        F1Menu.clear();
                        F1Menu.display();
                }
    }
 

EDIT::::

Here is the link to a stack overflow question http://stackoverflow.com/questions/27350714/managing-multiple-renderwindows-in-sfml/27351325?noredirect=1#comment43156853_27351325 I posted, it has a couple of important discussions, like what we have tried.

The most important part in there is when I discover that if I move the executable to another computer it works as expected.

Here are some specs on what I am compiling on, where the problem persists, I believe it may be a bug between the OS/Compiler and SFML:

- Windows XP 32-bit (Yes I know it is no longer supported, I have another computer, I use for everyday use.)
- Visual C++ 2010 32-bit
- 3GB Ram

Program Does work on the following system:

- MAC OSX 10.9.5 64-bit
- 4GB Ram
- I have not used XCode to compile, I used the same executable, but ran it under wine.

Should I try to update my Drivers? Can I on WinXP?

EDIT 2::::

After further investigation, it Does Not work on the Mac, but I can move the window. It seems they cannot poll events at the same time.
« Last Edit: December 08, 2014, 04:46:09 pm by Reborn121 »

Reborn121

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: Multiple Windows Overlapping Issue
« Reply #1 on: December 08, 2014, 02:16:25 am »
Bump, still need to know how to fix this.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
AW: Multiple Windows Overlapping Issue
« Reply #2 on: December 08, 2014, 07:07:09 am »
Look at the tutorial again. You should use while loops for polling the events, not just if-statements.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Reborn121

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: Multiple Windows Overlapping Issue
« Reply #3 on: December 08, 2014, 02:25:35 pm »
I have already tried that. Here is the link to a stack overflow question http://stackoverflow.com/questions/27350714/managing-multiple-renderwindows-in-sfml/27351325?noredirect=1#comment43156853_27351325 I posted, it has a couple of important discussions, like what we have tried.

The most important part in there is when I discover that if I move the executable to another computer it works as expected.

Here are some specs on what I am compiling on, where the problem persists, I believe it may be a bug between the OS/Compiler and SFML:

- Windows XP 32-bit (Yes I know it is no longer supported, I have another computer, I use for everyday use.)
- Visual C++ 2010 32-bit
- 3GB Ram

Program Does work on the following system:

- MAC OSX 10.9.5 64-bit
- 4GB Ram
- I have not used XCode to compile, I used the same executable, but ran it under wine.

Should I try to update my drivers? Can I on WinXP?
« Last Edit: December 08, 2014, 02:32:35 pm by Reborn121 »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Multiple Windows Overlapping Issue
« Reply #4 on: December 08, 2014, 10:36:57 pm »
Honestly, I don't understand what the issue is exactly. What does "interact" mean and how do you know that it's "not interacting"?

Also, did you know that this forum as well as StackOverflow have nice editing functions, where you like could update the code? ;)

I've modified your code and it all works fine:

#include <SFML/Graphics.hpp>

#include <iostream>

int main()
{
    //Declare both RenderWindows
    sf::RenderWindow F1Menu;
        sf::RenderWindow MainWin;

    //Create the Main Window
    MainWin.create(sf::VideoMode(800, 600), "SFML 2D");

    sf::View MainView(sf::FloatRect(0, 0, 1600, 1200));
    MainView.setViewport(sf::FloatRect(0, 0, 1, 1));

    MainWin.setView(MainView);

    //Loop while either window is open.
    while (MainWin.isOpen() || F1Menu.isOpen())
    {
        sf::Event Event;
                //Main Window got an event
        while (MainWin.pollEvent(Event))
        {
            switch (Event.type)
            {
                case sf::Event::Closed:
                    MainWin.close();
                break;

                case sf::Event::Resized:
                    MainView.reset(sf::FloatRect(0.f, 0.f, MainWin.getSize().x, MainWin.getSize().y));
                    MainWin.setView(MainView);
                break;

                case sf::Event::KeyPressed:
                    if (Event.key.code == sf::Keyboard::F1)
                                                //Create the second window when F1 is pressed.
                        F1Menu.create(sf::VideoMode(200, 500), "SFML 2D - F1 Menu");
                    else if (Event.key.code == sf::Keyboard::Escape)
                        MainWin.close();
                break;

                case sf::Event::MouseButtonPressed:
                    std::cout << "Main" << std::endl;
                break;
            }
        }

        //Second Window got an event.
        while (F1Menu.pollEvent(Event))
        {
            switch (Event.type)
            {
                case sf::Event::Closed:
                    F1Menu.close();
                break;
                case sf::Event::MouseButtonPressed:
                    std::cout << "F1" << std::endl;
                break;
            }
        }

                //The Main window is the top window
        if (MainWin.isOpen())
        {
            MainWin.clear();
            MainWin.display();
        }

                //Second Window is top window.
        if (F1Menu.isOpen())
        {
            F1Menu.clear();
            F1Menu.display();
        }
    }
}
 

Make sure to build SFML from source, so you won't encounter any issues which were already fixed long time ago.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Reborn121

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: Multiple Windows Overlapping Issue
« Reply #5 on: December 08, 2014, 11:59:52 pm »
Okay, I have been using the stable version, I just built the source version; however, I can't seem to the static libs. example: "sfml-graphis-s.lib". I am used to using the pre-built version, what do I do with the provided items? I would prefer to not use the dynamic version.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
AW: Multiple Windows Overlapping Issue
« Reply #6 on: December 09, 2014, 12:08:42 am »
Read the tutorial on how to build SFML with CMake, you'll see the option for not building shared libs there.
Also keep the following link in mind when linking SFML statically: https://github.com/SFML/SFML/wiki/FAQ#wiki-build-link-static
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Reborn121

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: Multiple Windows Overlapping Issue
« Reply #7 on: December 09, 2014, 12:14:15 am »
Okay, thank you for the link, I figured it out just after asking the question, sorry for wasting your time. About the GitHub link, what is the important part there? Just how to link it?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
AW: Multiple Windows Overlapping Issue
« Reply #8 on: December 09, 2014, 12:15:34 am »
If you link SFML statically, you need to add all its dependencies.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Multiple Windows Overlapping Issue
« Reply #9 on: December 09, 2014, 12:15:58 am »
I know I'm not answering your question, but I'm curious; what's wrong with using the dynamically linked version?
I see many people wanting to use a statically linked SFML and I honestly wonder why?  Sure, you have to distribute fewer files (but so what; when they are inside a .dpg, .rpm or .msi - who cares?). Ok, the linker may do smarter things with static libs compared to dynamic libs - at the very least the dynamic linker won't have to resolve symbols - but so what? we are not using 286 machines these days.
Seriously, what's the big deal? Is it that you think people won't be able to extract your sprites or music if it is all statically linked? (if so, you're wrong). Is it that it gives you fewer files to distribute? (If so, you should really set up your build environment to build your distributables properly so that it's not an issue, what's the difference between 10 and 100 files anyway?). Is it that you think you'll gain performance? (Yes, dynamic libs perform worse than static libs, but in the age of multi-gigaherz CPUs you'll never notice).
Why?

Reborn121

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: Multiple Windows Overlapping Issue
« Reply #10 on: December 09, 2014, 12:19:19 am »
Not much of a huge deal to me, just a preference, I speak for myself when I say it's just for the distributing fewer files. That's my only reason, if someone was to tell me it was safer/better or anything I would have a problem using dynamic.

Also, with the extracting sprites, do you mean the images? I don't see how that would stop people for taking your images? Do some people really believe that? Security is not really a concern for me, I am debating open-source or not.
« Last Edit: December 09, 2014, 12:28:25 am by Reborn121 »

Reborn121

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: AW: Multiple Windows Overlapping Issue
« Reply #11 on: December 09, 2014, 12:25:43 am »
If you link SFML statically, you need to add all its dependencies.

Okay... was this the same in the "latest stable version"?

EDIT::
Nevermind, it's different, I'm just linking dynamically.
« Last Edit: December 09, 2014, 12:34:48 am by Reborn121 »

Reborn121

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: Multiple Windows Overlapping Issue
« Reply #12 on: December 09, 2014, 01:12:38 am »
Alright sorry to post again, this topic is beyond off-topic. I linked dynamically, took out the SFML_STATIC macro all that good stuff, but now I'm getting a runtime error. The vector header is throwing it. This is what the log spits out:

Code: [Select]
This may be due to a corruption of the heap, which indicates a bug in SFML2D.exe or any of the DLLs it has loaded.

This may also be due to the user pressing F12 while SFML2D.exe has focus.

The output window may have more diagnostic information.
The program '[3324] SFML2D.exe: Native' has exited with code 0 (0x0).

So I am assuming I did something wrong, the only thing I can think of is that I didn't use the Exports Library Files from the build. I linked the Object Files, and Included the DLLs in my executable location like normal, but what do I with the Exports Library Files?

Like I said, I'm used to using the stable build, and usually static, so this is all new to me.

EDIT::
Never mind, sorry again wasting time. It's something in one of my classes, don't know why the updated SFML has anything to do with it though...

On a topic related to the actual question, this fixed the original problem, thanks eXpl0it3r!
« Last Edit: December 09, 2014, 01:35:21 am by Reborn121 »

 

anything