SFML community forums
Bindings - other languages => DotNet => Topic started 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:
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
}
}
}
-
Aha! I was browsing around and saw this post in another thread
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 =]
-
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...
-
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.
-
The problem is that the process terminates maybe because the Main function returns...
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!