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

Author Topic: Input affecting image loading?  (Read 3235 times)

0 Members and 2 Guests are viewing this topic.

Austech

  • Newbie
  • *
  • Posts: 23
    • View Profile
Input affecting image loading?
« on: March 12, 2011, 07:30:21 am »
Here's something that I accidentally stumbled upon in SFML.net. I'm not sure if it has the same affect on other languages like C++. Though, I would assume the same outcome will occur since the .net is a binding.

Anyway, I have no idea why this happens:


Apparently the window's input function has some sort of affect on an image loading.

Here's some code:

Code: [Select]

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SFML.Graphics;
using SFML.Window;
using System.Threading;

namespace Nature
{
    class Program
    {
        static public Random random;
        static public RenderWindow window;
        static public DateTime firsttick;

        static void Main(string[] args)
        {
            firsttick = DateTime.Now;
           
            random = new Random();
           
            ContextSettings antial = new ContextSettings();
           
            antial.AntialiasingLevel = 16;
           
            window = new RenderWindow(new VideoMode(800, 600), "Nature",Styles.Close, antial);
           
            window.SetFramerateLimit(60);
           
            window.Closed += new EventHandler(SFMLCloseEvent);

            if (window.Input.IsKeyDown(KeyCode.A))
            {
                //Somehow, this messes up image loading?
            }
            Image img = new Image("Res/Sprites/BurriedSprite.png");
           
            img.Smooth = false;
            Sprite spr = new Sprite(img);
            spr.Width = 100;
            spr.Height = 100;
            spr.Position = new Vector2(100, 100);

            while (window.IsOpened())
            {
                window.DispatchEvents();
                window.SetActive();
                window.Clear(new Color(100,200,100));



                window.Draw(spr);

                window.Display();
            }
        }

        static void SFMLCloseEvent(object obj, EventArgs arg)
        {
            window.Close();
        }

        public static TimeSpan ElapsedTime()
        {
            return DateTime.Now - firsttick;
        }
    }
}



Here's the outcome:



Pretty odd. But what made me believe that this is due to the input, here's the same affect with this code. All that's changed is that the input detection is commented out.

Code: [Select]


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SFML.Graphics;
using SFML.Window;
using System.Threading;

namespace Nature
{
    class Program
    {
        static public Random random;
        static public RenderWindow window;
        static public DateTime firsttick;

        static void Main(string[] args)
        {
            firsttick = DateTime.Now;
           
            random = new Random();
           
            ContextSettings antial = new ContextSettings();
           
            antial.AntialiasingLevel = 16;
           
            window = new RenderWindow(new VideoMode(800, 600), "Nature",Styles.Close, antial);
           
            window.SetFramerateLimit(60);
           
            window.Closed += new EventHandler(SFMLCloseEvent);

            /*if (window.Input.IsKeyDown(KeyCode.A))
            {
                //This is commented out, so it doesn't affect the image loading now?
            }*/
            Image img = new Image("Res/Sprites/BurriedSprite.png");
           
            img.Smooth = false;
            Sprite spr = new Sprite(img);
            spr.Width = 100;
            spr.Height = 100;
            spr.Position = new Vector2(100, 100);

            while (window.IsOpened())
            {
                window.DispatchEvents();
                window.SetActive();
                window.Clear(new Color(100,200,100));



                window.Draw(spr);

                window.Display();
            }
        }

        static void SFMLCloseEvent(object obj, EventArgs arg)
        {
            window.Close();
        }

        public static TimeSpan ElapsedTime()
        {
            return DateTime.Now - firsttick;
        }
    }
}


And the result:


Now, obviously you shouldn't load resources after a input. It's usually loaded at the start of the program. But me accidentally loading resources when needed caused me to get this.

And while I can just load the resources at the beginning, have everything working fine. I'd still like to know what causes this. :P

Many thanks in advanced! : )

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Input affecting image loading?
« Reply #1 on: March 12, 2011, 01:04:12 pm »
That reminds me an old bug that I had with the PostFx sample. As far as I remember, it only happened in the .Net binding, and I couldn't solve it (I didn't even find out what the hell was going on).
Laurent Gomila - SFML developer

Austech

  • Newbie
  • *
  • Posts: 23
    • View Profile
Input affecting image loading?
« Reply #2 on: March 12, 2011, 11:34:42 pm »
Quote from: "Laurent"
That reminds me an old bug that I had with the PostFx sample. As far as I remember, it only happened in the .Net binding, and I couldn't solve it (I didn't even find out what the hell was going on).


Okay, it's no problem though. Resources need to be loaded in the beginning anyway : )

Thanks for clearing that up. I was stumped for hours. : P