ReadOnlyMemoryError in ccall


#1

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!


#2

Julia 0.6.2 on Linux:

julia> ccall((:SDL_Init, "/usr/lib64/libSDL-1.2.so.0"), Cint, (UInt32,), 0x00000020)
0

#3

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

ccall((:SDL_Init, "/usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0.4.0"), Cint, (UInt32,), 0x00000020)

I’m on Ubuntu 16.04.4 LTS.


#4

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

julia> ccall((:SDL_Init, "/usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0"), Cint, (UInt32,), 0x00000020)
ERROR: ReadOnlyMemoryError()
Stacktrace:
 [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);
   printf("%d\n",ret);
   return 0;
}

with both gcc and clang:

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

#5

also julia segfaults on quitting the session.


#6

Is this possibly still related to https://github.com/JuliaLang/julia/issues/19606 ? 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.


#7

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

julia> ENV["GALLIUM_DRIVER"]
"softpipe"

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

It is however similar to issue:


I have this pyplot issue in Ubuntu using PyQT5 backend but not on Fedora.


#8

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

export LIBGL_ALWAYS_SOFTWARE=true

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 https://github.com/JuliaLang/julia/issues/19606 , 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 https://github.com/JuliaLang/julia/pull/24890 going to fix this problem in Julia 0.7?


#9

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.


#10

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.


#11

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


#12

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.