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

Author Topic: Cannot get window from its handle  (Read 3630 times)

0 Members and 1 Guest are viewing this topic.

EntityinArray

  • Newbie
  • *
  • Posts: 4
    • View Profile
Cannot get window from its handle
« 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;
}
 

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
Re: Cannot get window from its handle
« Reply #1 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

EntityinArray

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Cannot get window from its handle
« Reply #2 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?
« Last Edit: June 07, 2018, 04:41:50 pm by eXpl0it3r »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
Re: Cannot get window from its handle
« Reply #3 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?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

EntityinArray

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Cannot get window from its handle
« Reply #4 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

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
Re: Cannot get window from its handle
« Reply #5 on: June 07, 2018, 04:57:22 pm »
And by "block everything" what exactly are you thinking of with everything?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

EntityinArray

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Cannot get window from its handle
« Reply #6 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.

Rosme

  • Full Member
  • ***
  • Posts: 169
  • Proud member of the shoe club
    • View Profile
    • Code-Concept
Re: Cannot get window from its handle
« Reply #7 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.
GitHub
Code Concept
Twitter
Rosme on IRC/Discord