ReadOnlyMemoryError in ccall

I’m trying to make my SDL bindings work on Linux but I’m getting this error that I don’t understand:

julia> ccall((:SDL_Init, SDL2.libSDL2), Cint, (UInt32,), SDL2.INIT_VIDEO)
ERROR: ReadOnlyMemoryError()

The function signature is:

int SDL_Init(Uint32 flags)

And SDL2.libSDL2 points to the correct (as far as I can tell) library installed with apt-get. The same code works on Windows and macOS.

What does this ReadOnlyMemoryError means exactly and is there a way to fix this ? Thanks!

Julia 0.6.2 on Linux:

julia> ccall((:SDL_Init, "/usr/lib64/"), Cint, (UInt32,), 0x00000020)

Does it work with SDL2 (libsdl2-2.0-0) as well ?

ccall((:SDL_Init, "/usr/lib/x86_64-linux-gnu/"), Cint, (UInt32,), 0x00000020)

I’m on Ubuntu 16.04.4 LTS.

I can confirm this problem with SDL2 on Ubuntu 18.04 LTS:

julia> ccall((:SDL_Init, "/usr/lib/x86_64-linux-gnu/"), Cint, (UInt32,), 0x00000020)
ERROR: ReadOnlyMemoryError()
 [1] anonymous at ./<missing>:?

But the following C code works fine:

#include <SDL2/SDL.h>
#include <stdio.h>
int main( int argc, char *argv[])
   int ret = SDL_Init(0x00000020u);
   return 0;

with both gcc and clang:

$ gcc test.c  -lSDL2 -o test
$ ./test 

also julia segfaults on quitting the session.

Is this possibly still related to ? If you are using the Gallium-based driver, you can test if this is the problem by setting the environment variable GALLIUM_DRIVER="softpipe" before starting Julia.

I am using r600 gallium, but setting GALLIUM_DRIVER=“softpipe” before starting Julia does not help:


julia> ccall((:SDL_Init, "/usr/lib/x86_64-linux-gnu/"), Cint, (UInt32,), 0x00000020)
ERROR: ReadOnlyMemoryError()
 [1] anonymous at ./<missing>:?

It is however similar to issue:
I have this pyplot issue in Ubuntu using PyQT5 backend but not on Fedora.

I have realised that to enable softpipe, you also need to:


in addition to:

export GALLIUM_DRIVER=“softpipe”

but even then I get the same error.

This is an annoying bug and I would like to figure a way around it (especially for being able to plot with julia with all backends).
If this is an Ubuntu bug, I will report it to Ubuntu, but first I need to understand it better.

How can I debug this?

If this is a LLVM version conflict problem, I don’t really see a way around it except for renaming all LLVM symbols in either julia or mesa.

In , it says “The Mesa projects strongly recommends against linking their drivers dynamically for this reason”. Can we have the source of this statement?

On my system mesa is using LLVM6

$ glxinfo |grep -i llvm
    Device: AMD JUNIPER (DRM 2.50.0 / 4.15.0-23-generic, LLVM 6.0.0) (0x68ba)
OpenGL renderer string: AMD JUNIPER (DRM 2.50.0 / 4.15.0-23-generic, LLVM 6.0.0)

LLVM6 shared lib is installed and if I try to remove the package with apt it tries to deinstall most of the system packages including mesa, so it looks like mesa is linking LLVM dynamically however I could not find any explicit LLVM dependencies in the mesa shared lib:

$ ldd /usr/lib/x86_64-linux-gnu/*mesa* |grep -i LLVM

Is going to fix this problem in Julia 0.7?

1 Like

If it really is the LLVM version conflict bug, then compiling Julia from source with the system compilers and LLVM should solve it, although using the system LLVM may introduce other problems. At least it will help to determine if this is the root cause or not.

I had the same issue with hdf5 recently. The issue ReadOnlyMemory exception happed non-deterministically though always in the same function. I could solve this by switch to the serial version of libhdf5 instead of the openmp version. As for @jonathanBieler this does not seem to have anything to do with the gallium issue.

I have tested that this error does not happen in Julia 0.7!

1 Like

Also I was in julia 0.6.2 and I just migrated to 0.6.3. The problem is also fixed on 0.6.3.