SFML community forums

Help => Window => Topic started by: EntityinArray on June 07, 2018, 04:18:18 pm

Title: Cannot get window from its handle
Post by: EntityinArray on June 07, 2018, 04:18:18 pm
When i try to get existing window by handle, application crashes returning code -1073740771 (0xC000041D)

#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <math.h>
#include <gui.h>

void shutdown(){
    exit(0);
}

void render(sf::WindowHandle windowhandle){

    printf("Starting render thread for window %u...",(unsigned int)windowhandle);

    sf::RenderWindow window(windowhandle); //crash

    /*
    while(window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event)){
            if (event.type == sf::Event::Closed)
                shutdown();
        }

        ...

        window.display();

    }
    */


}

int main(){

    sf::RenderWindow window(sf::VideoMode(800,600),"cool thinge",sf::Style::Close);
    window.setVerticalSyncEnabled(true);

    sf::Thread thrender(&render,window.getSystemHandle());
    thrender.launch();

    return 0;
}
 
Title: Re: Cannot get window from its handle
Post by: eXpl0it3r on June 07, 2018, 04:31:30 pm
This is not a supported use-case of window handles. The reason that one can create a window based on an existing handle is, so you can have some other code handle the creation of the window, while SFML just "attaches" to that window.

What you're trying to do is have an existing render window get the handle and create another render window on top. That doesn't work.

Also, you should use a debugger to get better information like a call stack on application crashes.
Title: Re: Cannot get window from its handle
Post by: EntityinArray on June 07, 2018, 04:34:29 pm
Thanks!

May i ask how do i get the window from it's handle to manipulate it from another separate thread?
Title: Re: Cannot get window from its handle
Post by: eXpl0it3r on June 07, 2018, 04:42:15 pm
The question is rather, why would you want to do that?
Or, what exactly are you trying to achieve here?
Title: Re: Cannot get window from its handle
Post by: EntityinArray on June 07, 2018, 04:43:11 pm
I want to render a game from a separate thread because rendering from main will block everything else
Title: Re: Cannot get window from its handle
Post by: eXpl0it3r on June 07, 2018, 04:57:22 pm
And by "block everything" what exactly are you thinking of with everything?
Title: Re: Cannot get window from its handle
Post by: EntityinArray on June 07, 2018, 05:00:19 pm
Maybe physics and networking between client and server, i'm not sure yet. I'm very new to C, i was programming on Lua and JavaScript before.
Title: Re: Cannot get window from its handle
Post by: Rosme on June 08, 2018, 03:42:19 pm
You should learn more about C++ (and not C) with a good book before going into SFML. The tutorials also explain(briefly how to have everything in a single loop and not blocking everything through a game loop. You don't want to do multithreading for this. Even less when you clearly lack some knowledge of the language.