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

Author Topic: [SOLVED] RenderWindow freeze  (Read 11374 times)

0 Members and 1 Guest are viewing this topic.

nihohit

  • Newbie
  • *
  • Posts: 37
    • View Profile
[SOLVED] RenderWindow freeze
« on: April 08, 2012, 03:18:52 pm »
Using SFML's RenderWindow on VS2010 freezes the window. Original explanation was a bit muddled, I'll try to make a clear explanation:
Let's say I'm debugging my application, which currently only runs an animation in a newly opened RenderWindow. (Why debugging? because running it doesn't work at the moment.) Let's call this new window App. If I'll select any other window, including the commandline window that pops up when debugging, I won't be able to select App again, let alone display it once it was covered (even partially-covered) by another window. If only partially covered, I can see that the animation continues, but the only way to see the whole window again is to minimize everything else.
The same is happening when run in Mono, but then Windows actually marks App as non-responsive.

When browsing for a solution I found this. Is upgrading to SFML 2.0 the only way to solve the problem?
« Last Edit: April 12, 2012, 03:42:27 pm by nihohit »

nihohit

  • Newbie
  • *
  • Posts: 37
    • View Profile
Re: RenderWindow freeze
« Reply #1 on: April 08, 2012, 03:34:05 pm »
small correction - I can "Start without debugging" in VS2010, and when that is done I can re-select the window, but it's still unresponsive.
So - VS debugger - can't reselect window. without debugger and Mono run & debugger - can reselect, is unresponsive.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10819
    • View Profile
    • development blog
    • Email
Re: RenderWindow freeze
« Reply #2 on: April 08, 2012, 04:41:15 pm »
A small code example would help a lot.

Also switching to SFML 2.0 wouldn't be such a bad idea specially since it seems you're not yet deeply into SFML 1.6. SFML 2.0 has quite a new API specially in the graphic section so you'd have to read again first about the changes.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

nihohit

  • Newbie
  • *
  • Posts: 37
    • View Profile
Re: RenderWindow freeze
« Reply #3 on: April 09, 2012, 08:42:45 am »
Sorry. This is enough to recreate the problem:

    class main
    {
        static int Main(string[] args)
        {
            SFML.Graphics.RenderWindow mainWindow = new SFML.Graphics.RenderWindow(
new SFML.Window.VideoMode(960, 640, 32), "main display");
            mainWindow.Display();
            Console.In.ReadLine();
            return 1;
        }

    }
« Last Edit: April 09, 2012, 10:19:52 am by Laurent »

nihohit

  • Newbie
  • *
  • Posts: 37
    • View Profile
Re: RenderWindow freeze
« Reply #4 on: April 09, 2012, 01:23:04 pm »
As for SFML 2.0, I'm not that expirienced and I think that for now I'll avoid the whole CMake process, and try to work with the given libraries of SFML 1.6 - I presume they work, and that the problems I'm facing are avoidable.

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: RenderWindow freeze
« Reply #5 on: April 09, 2012, 02:13:53 pm »
Hey there, updating to SFML 2.0 .Net is simple and you do not have to worry about using CMake. SFML 2.0 comes with precompiled CSFML 2.0 binaries. All you need to do is download the latest version from https://github.com/SFML/SFML.Net and compile it like any other .Net application.

As to the freeze, it sounds as if your not handling events. Try to handle events in SFML 2.0 and then see if the problem disappears.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

nihohit

  • Newbie
  • *
  • Posts: 37
    • View Profile
Re: RenderWindow freeze
« Reply #6 on: April 09, 2012, 08:42:09 pm »
Thanks, but I'm still flummoxed.

a. I couldn't managed to run the program with SFML 2.0. I downloaded the files, but there were no equivalent to the library files. I don't mean to go off topic here, but I'd really thank a link to a clear tutorial on installation.

b. By "handling events", what exactly do you mean? I use Window.DispatchEvents() during the screen's loop, and there are event handlers for losing & gaining focus, but they aren't activated when I switch windows.

nihohit

  • Newbie
  • *
  • Posts: 37
    • View Profile
Re: RenderWindow freeze
« Reply #7 on: April 10, 2012, 11:06:42 am »
Upgraded to SFML 2.0. While I'm now having updating problems, this problem seems to be solved. Thanks for the help!

nihohit

  • Newbie
  • *
  • Posts: 37
    • View Profile
Re: RenderWindow freeze
« Reply #8 on: April 10, 2012, 12:45:23 pm »
Correction - this works only on a single threaded program. When used with a mult-threaded program and the display isn't in the main thread, the problem persists - even after creating the event handlers in the new thread, and setActive(false);

Any idea why?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: RenderWindow freeze
« Reply #9 on: April 10, 2012, 01:00:27 pm »
Please show a complete and minimal code that reproduces your problem :)
Laurent Gomila - SFML developer

nihohit

  • Newbie
  • *
  • Posts: 37
    • View Profile
Re: RenderWindow freeze
« Reply #10 on: April 10, 2012, 03:33:45 pm »
using System.Threading;
using SFML.Graphics;
using SFML.Window;
using System;

namespace Game
{
    class main
    {
        static int Main(string[] args)
        {

            Temp display = new Temp();
            Thread graphicThread = new Thread(new ThreadStart(display.run));
            graphicThread.Start();
            graphicThread.Join();
            return 1;
        }

        public class Temp
        {
            RenderWindow _mainWindow;

            public Temp()
            {
                _mainWindow = new RenderWindow(new VideoMode(600, 600, 32), "main display");
                this._mainWindow.SetActive(false);
                this._mainWindow.GainedFocus += new EventHandler(OnGainingFocus);
                this._mainWindow.LostFocus += new EventHandler(OnLosingFocus);
            }

            public void run()
            {
                while (true)
                    _mainWindow.Display();
            }

        }

        static void OnLosingFocus(object sender, EventArgs e)
        {
            Console.Out.WriteLine("lost focus");
        }

        static void OnGainingFocus(object sender, EventArgs e)
        {
            Console.Out.WriteLine("gain focus");
        }

    }
}
 
« Last Edit: April 10, 2012, 03:58:04 pm by Laurent »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: RenderWindow freeze
« Reply #11 on: April 10, 2012, 03:59:12 pm »
There's still no call to DispatchEvents in this code.
Laurent Gomila - SFML developer

nihohit

  • Newbie
  • *
  • Posts: 37
    • View Profile
Re: RenderWindow freeze
« Reply #12 on: April 10, 2012, 05:05:23 pm »
Sorry, here's with - still doesn't work.



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

    namespace Game
    {
        class main
        {
            static int Main(string[] args)
            {

                Temp display = new Temp();
                Thread graphicThread = new Thread(new ThreadStart(display.run));
                graphicThread.Start();
                graphicThread.Join();
                return 1;
            }

            public class Temp
            {
                RenderWindow _mainWindow;

                public Temp()
                {
                    _mainWindow = new RenderWindow(new VideoMode(600, 600, 32), "main display");
                    this._mainWindow.SetActive(false);
                    this._mainWindow.GainedFocus += new EventHandler(OnGainingFocus);
                    this._mainWindow.LostFocus += new EventHandler(OnLosingFocus);
                }

                public void run()
                {
                    while (true)
                    {
                        _mainWindow.Display();
                        _mainWindow.DispatchEvents();
                    }
                }

            }

            static void OnLosingFocus(object sender, EventArgs e)
            {
                Console.Out.WriteLine("lost focus");
            }

            static void OnGainingFocus(object sender, EventArgs e)
            {
                Console.Out.WriteLine("gain focus");
            }

        }
    }
 
« Last Edit: April 10, 2012, 08:06:07 pm by Laurent »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: RenderWindow freeze
« Reply #13 on: April 10, 2012, 08:07:45 pm »
Thanks, I'll test this as soon as I can.

And next time can you please use the code tag in your posts, so that I don't have to edit all your messages?
Laurent Gomila - SFML developer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: RenderWindow freeze
« Reply #14 on: April 10, 2012, 08:11:31 pm »
Ah, in fact your problem is a typical one: events must be handled in the thread where the window was created. This is a limitation of the OS.
Laurent Gomila - SFML developer