SFML community forums

Bindings - other languages => DotNet => Topic started by: m00npirate on December 12, 2011, 03:33:22 am

Title: Threaded window disappears, still thinks its open?
Post by: m00npirate 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

        }
    }
}
Title: Threaded window disappears, still thinks its open?
Post by: m00npirate 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 =]
Title: Threaded window disappears, still thinks its open?
Post by: Laurent 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...
Title: Threaded window disappears, still thinks its open?
Post by: m00npirate 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.
Title: Threaded window disappears, still thinks its open?
Post by: Chris12 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!