I’ve written a program for my research that does robotics simulations. It causes video corruption, and I’m not sure why that might be.
The video corruption itself only affects my external monitor, never my laptop’s built-in monitor. It consists of horizontal bars of distortion that arise non-deterministically after some minutes. More bars appear as minutes pass and the program keeps running. They go away when I turn the monitor off and on again.
I know almost nothing about how video memory works. In fact, in my naivety, I kind of thought it would be impossible for a non-privileged user program to corrupt the video. So I’m not sure what components I should even be thinking about. Below are some details. It’s not strictly necessary that I fix this, so I can’t follow too deep a rabbit hole, but I would appreciate any tips on how to begin thinking about what sort of animal this is.
Program: C++, compiled with GCC 11.2.1. Uses SDL2 (2.0.14) to display bitmaps in a window every few seconds. Also uses the Eigen library (3.3.9) for matrix math. The corruption only seems to happen (though I’m not certain yet) when both libraries are being actively used. Valgrind shows no memory errors anywhere. It shows some memory leaks in the SDL2 internals, which googling suggests may be normal.
OS: Fedora 34 Workstation with GNOME 40, using Nouveau and Wayland. (But the problem goes back at least to Fedora 32.)
Hardware: Dell P2720D monitor connected by DisplayPort to a Dell 7779 laptop with Intel HD Graphics 620 and NVIDIA GeForce 940MX.
You will need to learn about memory usage with your program. It apparently is accessing memory that affects the video, either writing to video itself or interfering with video memory.
I would guess that since it is displaying bitmaps the problem may be it is not releasing the memory properly, thus causing corruption as video memory fills. Memory leaks are a killer in any long running application.
Thanks. I’ll ask the SDL people for advice. But I’ve been reading a bit about video memory, and it’s confusing… I get the impression that most modern Linux distributions don’t give unprivileged userspace processes direct access to video memory, instead reserving that access for drivers. So even with memory leaks, it seems like my program shouldn’t be able to corrupt the screen outside its own window. I’m having trouble finding out if things are different in Fedora, though.
Sorry, I should have said “unprotected access,” not “direct access.” When I write a CUDA program, I can directly access the memory that cudaMalloc points me to, but I wouldn’t expect cudaMalloc to give me the same memory that the video display is using. I don’t know of a way to use what cudaMalloc gives me to corrupt the video display any more than I know how to use segfaults to crash other processes than my own.