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

Author Topic: Failed to activate the window's context.  (Read 12956 times)

0 Members and 2 Guests are viewing this topic.

N1ghtly

  • Jr. Member
  • **
  • Posts: 96
    • View Profile
Failed to activate the window's context.
« on: August 24, 2011, 01:26:40 pm »
I searched around already and it seems it always has got something to do with OpenGL. Well I'm not using openGL. It's the first time I try running different threads ^.^

Here's my code:

Code: [Select]
void Game::tick()
{
    ball.tick();

    //get mouse coord
    float x = Window.GetInput().GetMouseX();
    panel.tick(x);
    updateText();

    if(killedBricks == levels[currentLvl].amountOfBricks) //level over
    {
        currentLvl++;
        ball.reset();
        return;
    }

    if(prepare)
    {
        prepare = false;
        ball.pause();
        sf::Thread thread(&Game::prepare_function, &*this);
        thread.Launch();
    }
}

void Game::prepare_function()
{
    sf::Clock clock;
    int i = 0;
    sf::Font myfont;
    myfont.LoadFromFile("GOUDYSTO.TTF");
    sf::Text text("", myfont, 30);
    text.SetPosition(300, 300);
    while(i < 3)
    {
        int i = clock.GetElapsedTime();
        if(i < 1)
        text.SetString("3");
        else if (i < 2)
        text.SetString("2");
        else
        text.SetString("1");
        Window.Draw(text);
    }
    ball.start();
}


The purpose is (it's a breakout game btw) that if the ball goes out of screen (thus -1 live) we wait first 3 seconds before releasing the next ball.
I was also thinking of having a separate thread for audio and one for drawing.

help?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Failed to activate the window's context.
« Reply #1 on: August 24, 2011, 01:40:45 pm »
Basically, a window must be deactivated (SetActive(false)) in the thread where it is active, before being used in another thread.

But you don't need a thread at all for what you do. Your thread spends most of its time doing nothing, and worst, the main thread is waiting until the other thread is finished (you could call prepare_function directly, it would have the exact same effect). So it's absolutely useless ;)

A thread for audio is not necessary, sounds are already played in a separate thread so that the main thread is never blocked.

A thread for drawing... I'd say it's useless too, unless you have already thought about it and have really good arguments for it.

Threading is not magical, it must be used carefully and it involves a lot of new concepts and problems.
Laurent Gomila - SFML developer

N1ghtly

  • Jr. Member
  • **
  • Posts: 96
    • View Profile
Failed to activate the window's context.
« Reply #2 on: August 24, 2011, 02:17:16 pm »
Wow, thanks for the quick reply Laurent!
I thought, that if I'd call prepare_function directly, it wouldn't keep on drawing?
For example, my paddle won't move anymore, and the numbers will stay on the screen and painted over (ugly)?

EDIT:
If I call it directly it crashes :(

djm_jm

  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: Failed to activate the window's context.
« Reply #3 on: January 17, 2017, 04:42:42 pm »
Good afternoon everybody. I installed SFML on windows and it happens same error here. I use the codeblocks IDE 16.01 with GCC 4.9.2 TDM (SJLJ) - 32-bit. Nothing program that uses SFML windows is drawned and is showed the same message this topic.

How I can fix this?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
Re: Failed to activate the window's context.
« Reply #4 on: January 17, 2017, 05:24:12 pm »
This thread is over 5 years old, as such the problem won't be the same at all. Please create your own thread.

Also there are other similar and newer topics on this error message, make sure to read them.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/