Here is a minimalist C# console app to recreate the problem:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SFML.Graphics;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
using (var rw = new RenderWindow(new SFML.Window.VideoMode(800, 600), "Test"))
{
Shape sh = Shape.Rectangle(new FloatRect(8,8,32,32), Color.Green);
RenderImage buffer = null;
while (rw.IsOpened())
{
rw.DispatchEvents();
buffer = CreateBuffer(rw, buffer);
buffer.Clear();
buffer.Draw(sh);
buffer.Display();
rw.Clear();
var s = new Sprite(buffer.Image);
rw.Draw(s);
rw.Display();
}
}
}
static RenderImage CreateBuffer(RenderWindow rw, RenderImage existingBuffer)
{
if (existingBuffer == null || existingBuffer.Width != rw.Width || existingBuffer.Height != rw.Height)
{
if (existingBuffer != null)
existingBuffer.Dispose();
return new RenderImage(rw.Width, rw.Height);
}
return existingBuffer;
}
}
}
I have been having this issue for a while, but always assumed it was my fault up until now. RenderImage doesn't seem to want to dispose properly. In my game, I use a few RenderImages to draw to, then combine them all to the screen. If the RenderWindow changes in size, the RenderImages are disposed then created again with the new size. But when disposing them, that is when the problems seem to arise.
If you take out the Dispose in the program above, it also seems to make it work just fine.