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:
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.
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.
Many thanks in advanced! : )