WriteableBitmap: doesn't display anything on Linux (and I don't know about other platforms)
See original GitHub issueDescribe the bug
WriteableBitmap doesn’t display anything on Linux. The same code does display an image on Windows. No platform-specific code is used.
To Reproduce Steps to reproduce the behavior:
- Clone this repo: https://github.com/OpenRakis/Spice86
- Grab a supported DOS game, like Dune or Prince of Persia
- Run it with the following command line
Spice86 -e /path/to/executable
- See a black image.
Expected behavior
The same image should display on every supported platform.
Screenshots
✓ Windows:

❌ WSL2 (Ubuntu 20.04) and Xubuntu 20.04 (or any other desktop Linux distro):

Same result on a desktop PC with a nvidia GPU, and a laptop with a nvidia GPU.
? - Other platforms
I don’t have a Mac for example.
Desktop (please complete the following information):
- OS: [Ubuntu 20.04]
- Version [0.10.13]
Additional context
Here is the code that updates the image, and at the end invalidates the visual on the UI thread (VideoBufferViewModel, view is VideoBufferView.xaml with the associated code-behind file) :
public unsafe void Draw(byte[] memory, Rgb[] palette) {
if (_disposedValue || UIUpdateMethod is null || Bitmap is null) {
return;
}
int size = Width * Height;
long endAddress = Address + size;
if (_appClosing == false) {
using ILockedFramebuffer buf = Bitmap.Lock();
uint* dst = (uint*)buf.Address;
switch (buf.Format) {
case PixelFormat.Rgba8888:
for (long i = Address; i < endAddress; i++) {
byte colorIndex = memory[i];
Rgb pixel = palette[colorIndex];
uint rgba = pixel.ToRgba();
dst[i - Address] = rgba;
}
break;
case PixelFormat.Bgra8888:
for (long i = Address; i < endAddress; i++) {
byte colorIndex = memory[i];
Rgb pixel = palette[colorIndex];
uint argb = pixel.ToArgb();
dst[i - Address] = argb;
}
break;
default:
throw new NotImplementedException($"{buf.Format}");
}
Dispatcher.UIThread.Post(() => UIUpdateMethod?.Invoke(), DispatcherPriority.MaxValue);
}
}
Both on Linux and Windows, the case being run is always PixelFormat.Bgra8888.
Using another pixel format (pixel.ToRgba, or pixel.ToBgra) only breaks the Windows use case.
Using random values does display something, so bindings and invalidation are OK.
Issue Analytics
- State:
- Created a year ago
- Comments:7 (3 by maintainers)

Top Related StackOverflow Question
Corrected on my end.
Previously I was able to reproduce this issue with WSL2 and the proprietary nvidia driver.
The issue doesn’t manifest itself anymore with this new code:
it also still works on Windows and on Linux with the nouveau driver for nvidia hardware.
https://github.com/OpenRakis/Spice86/pull/85
Issue closed. Thank you !