SFML community forums

Bindings - other languages => DotNet => Topic started by: Yuraj on May 01, 2013, 02:54:52 pm

Title: Thread bug ?
Post by: Yuraj on May 01, 2013, 02:54:52 pm
Hello,
there is probably bug in SFML (or only .net binding?), it can't draw things which were loaded in thread before (like text, textures etc.). I debugged this and It reach app.Draw(text); (it's loaded fully) but It can't draw it on screen.

using SFML.Graphics;
using SFML.Window;
using System;
using System.Threading;

namespace SFMLThreads
{
    class Program
    {
        static void Main(string[] args)
        {
            RenderWindow app = new RenderWindow(new VideoMode(800,600), "SFML Threads Test");
            app.SetFramerateLimit(60);
            app.Closed += (s,e) => app.Close();

            //Create and start thread
            Text text = null;
            new Thread(() =>
                {
                    text = new Text("test", new Font("C:\\Windows\\Fonts\\Verdana.ttf"), 25);
                }).Start();

            while (app.IsOpen())
            {
                app.DispatchEvents();

                app.Clear();
                if (text != null)
                {
                    app.Draw(text);
                }
                app.Display();
            }
        }
    }
}
Title: Re: Thread bug ?
Post by: Laurent on May 01, 2013, 02:57:24 pm
Please read http://www.sfml-dev.org/tutorials/2.0/graphics-draw.php ('Drawing from threads' section).
Title: Re: Thread bug ?
Post by: Yuraj on May 01, 2013, 03:00:25 pm
Ehm, thanks  :) I thought It was only C++ (threads) related tutorial.
Title: Re: Thread bug ?
Post by: Yuraj on May 01, 2013, 03:16:26 pm
By the way, is it better to add all Draw logic into thread?
Title: Re: Thread bug ?
Post by: Laurent on May 01, 2013, 03:20:36 pm
There's no absolute "best solution". It depends on what you do. But use threads only if you need to, don't forget that they have overhead and add complexity to your code.