Description
I've had numerous performance issues when getting SFML's Clipboard every frame (especially on Windows (10 FPS), on Linux it wasn't as bad (70 FPS), which may be hardware related) and I mostly worked around that by caching the Clipboard on my side upon window focus. Which lead me to the following issue.
A very bad hiccup occurs when getting SFML.Window.Clipboard.Contents
while the contents are not text (image pixels for example). On my Linux machine, the app freezes for about 1 or 2 seconds.
From what I saw in the binding implementation - SFML assumes the clipboard contents are always text and does the parsing all the time. Perhaps there may be an OS-dependent way to check whether the clipboard contents are text before parsing the data and skip doing so if non-textual data is present.
Minimal example:
- Make sure to copy image pixels from some image editor software beforehand
- Screenshot may also work
using SFML.Graphics;
using SFML.System;
using SFML.Window;
namespace MinimalExampleClipboardIssue;
public class Program
{
public static void Main()
{
var window = new RenderWindow(new(1280, 720), "Clipboard Hiccup Issue");
var rect = new RectangleShape(new Vector2f(200, 200));
window.GainedFocus += (_, _) => _ = Clipboard.Contents;
while (window.IsOpen)
{
rect.Position = window.MapPixelToCoords(Mouse.GetPosition(window));
window.DispatchEvents();
window.Clear();
window.Draw(rect);
window.Display();
}
}
}