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

Author Topic: RenderWindow .setActive() prints error  (Read 2800 times)

0 Members and 1 Guest are viewing this topic.

Macecraft

  • Guest
RenderWindow .setActive() prints error
« on: May 28, 2018, 12:24:46 am »
Hello,

Was just writing a small test of rendering with VertexBuffers, but using rendering from a separate thread. It's an environment that mirrors a larger project that I intend to upgrade to SFML 2.5.0. But whilst working on this test I found that just having called the .setActive() function on the RenderWindow class returns me an error saying:

An internal OpenGL call failed in RenderTextureImplFBO.cpp(192).
Expression:
   GLEXT_glBindFramebuffer(GLEXT_GL_FRAMEBUFFER, 0)
Error description:
   GL_INVALID_OPERATION
   The specified operation is not allowed in the current state.
 

A minimal code example that reproduces the same effect:
#include <iostream>
#include <SFML\Graphics.hpp>

using namespace std;
using namespace sf;

int main(void)
{
        RenderWindow rWindow(VideoMode(640, 480), "Hello", Style::Close);
        rWindow.setFramerateLimit(60);
        rWindow.setActive(false);
        rWindow.setActive(true);

        while (rWindow.isOpen())
        {
                Event evnt;
                while (rWindow.pollEvent(evnt))
                {
                        if (evnt.type == Event::Closed)
                        {
                                rWindow.close();
                        }
                }
        }

        return 0;
}
 

The function .setActive() does return true, indicating there was no error. But I was just wondering the error in console was significant?

I'm currently developing with Visual Studio 2017, with the 32-bit release of 2.5.0 for VS2017. I'm working on a Windows 10 x64 machine.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: RenderWindow .setActive() prints error
« Reply #1 on: May 28, 2018, 12:39:43 am »
Can you give this PR a go? :)

https://github.com/SFML/SFML/pull/1442
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Macecraft

  • Guest
Re: RenderWindow .setActive() prints error
« Reply #2 on: May 28, 2018, 08:59:31 pm »
That fixes the print to the console  :)

Macecraft

  • Guest
Re: RenderWindow .setActive() prints error
« Reply #3 on: May 28, 2018, 11:05:17 pm »
That fixes the print to the console  :)

Was kind of wrong there!

Now once you run the rendering on another thread, when the window is closed it spits out:

Failed to activate OpenGL context: The requested resource is in use.

 

Minimal code example:

#include <future>

#include <iostream>
#include <SFML\Graphics.hpp>

using namespace std;
using namespace sf;

void draw(RenderWindow* rWindow)
{
        rWindow->setActive(true);
        while (rWindow->isOpen())
        {
                rWindow->clear(Color::Green);
                rWindow->display();
        }
}


int main(void)
{
        RenderWindow rWindow(VideoMode(640, 480), "Hello", Style::Close);
        rWindow.setFramerateLimit(60);
        rWindow.setActive(false);
        thread rthread(&draw, &rWindow);
        while (rWindow.isOpen())
        {
                Event evnt;
                while (rWindow.pollEvent(evnt))
                {
                        if (evnt.type == Event::Closed)
                        {
                                rWindow.close();
                        }
                }
        }
        rthread.join();
        system("pause"); //To ensure I could see the message.

        return 0;
}
 

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: RenderWindow .setActive() prints error
« Reply #4 on: May 29, 2018, 07:35:52 pm »
If you activate a context in another thread, it's also your responsibility to deactivate it.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/