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

Author Topic: Threaded window disappears, still thinks its open?  (Read 3437 times)

0 Members and 1 Guest are viewing this topic.

m00npirate

  • Newbie
  • *
  • Posts: 18
    • View Profile
Threaded window disappears, still thinks its open?
« on: December 12, 2011, 03:33:22 am »
I am trying to use a SFML window on a separate thread from the main thread (which hosts a GTK window). Whenever I try this, the window immediately disappears. It still runs DispatchEvents, Display, Clear, and IsOpen() returns true. Am I doing something wrong?

Here is a minimal example:

Code: [Select]
   
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using SFML.Graphics;
using SFML.Window;

namespace MessageView
{
    class EntryPoint
    {
        static RenderWindow window = new RenderWindow(new VideoMode(400, 400), "test");
        static Thread thread = new Thread(run);
        static bool running = true;
        static void run()
        {
            while (running)
            {
                window.DispatchEvents();
                window.Clear();
                window.Display();
            }
        }
        static void Main(string[] args)
        {
           
            //thread.Start(); //window will immediately disappear
            //run(); //runs fine

        }
    }
}

m00npirate

  • Newbie
  • *
  • Posts: 18
    • View Profile
Threaded window disappears, still thinks its open?
« Reply #1 on: December 13, 2011, 06:19:38 am »
Aha! I was browsing around and saw this post in another thread

Quote

SetActive is only about drawing. A window needs to be active when you want to draw stuff. So:
- you must call SetActive(false) before launching the rendering thread
- that's all, SetActive(true) is called automatically by Clear/Draw/Display


This fixed it =]

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Threaded window disappears, still thinks its open?
« Reply #2 on: December 13, 2011, 07:29:59 am »
Really? This made the window disapear?? Not calling SetActive(false) can trigger OpenGL errors, and the inner area of the window may contain garbage, but the window itself shouldn't completely disapear...
Laurent Gomila - SFML developer

m00npirate

  • Newbie
  • *
  • Posts: 18
    • View Profile
Threaded window disappears, still thinks its open?
« Reply #3 on: December 13, 2011, 04:03:28 pm »
Even stranger. If I SetActive(false) in my minimal example, the window still disappears. If I do it together with my Gtk window, it works... I will investigate further in a bit.

Chris12

  • Newbie
  • *
  • Posts: 20
    • View Profile
Threaded window disappears, still thinks its open?
« Reply #4 on: March 02, 2012, 03:29:42 pm »
The problem is that the process terminates maybe because the Main function returns...

Code: [Select]

 static void Main(string[] args)
        {
           
            thread.Start(); //window will immediately disappear
            //run(); //runs fine

while(true)
{
// Sleep or do anything else here to prevent the process from exiting.
Thread.Sleep(100);

}

        }



Try this!