Segfault using glfw with tensorflow

Discussion in 'Visualization' started by Markus Staeuble, Oct 25, 2018.

  1. Hey,

    We are developing an application, which performs some tensorflow operations and we would like to visualize the results with mujoco. We built up a visualizer according to the simulate.cpp example with the help of the glfw lib. However, glfw and tensorflow seem to use incompatible protobuf versions in some of their backends. And the program results in a segfault. A minimal code example causing the error is:

    #include <tensorflow/core/framework/tensor.h>
    #include <glfw3.h>
    int main() {
    tensorflow::Tensor a;
    glfwInit(); // segfault occurs in this method
    return 0;
    }

    Gdb backtrace reads:
    #0 0x00007fffeaeb9516 in google:: protobuf::internal::Mutex::Lock() () from /usr/lib/x86_64-linux-gnu/libprotobuf-lite.so.9
    #1 0x00007fffeaeb9833 in google:: protobuf::internal::OnShutdown(void (*)()) () from /usr/lib/x86_64-linux-gnu/libprotobuf-lite.so.9
    #2 0x00007ffff7de76ba in call_init (l=<optimized out>, argc=argc@entry=1, argv=argv@entry=0x7fffffffd778, env=env@entry=0x7fffffffd788) at dl-init.c:72
    #3 0x00007ffff7de77cb in call_init (env=0x7fffffffd788, argv=0x7fffffffd778, argc=1, l=<optimized out>) at dl-init.c:30
    #4 _dl_init (main_map=main_map@entry=0xc3dc00, argc=1, argv=0x7fffffffd778, env=0x7fffffffd788) at dl-init.c:120
    #5 0x00007ffff7dec8e2 in dl_open_worker (a=a@entry=0x7fffffffd380) at dl-open.c:575
    #6 0x00007ffff7de7564 in _dl_catch_error (objname=objname@entry=0x7fffffffd370, errstring=errstring@entry=0x7fffffffd378,
    mallocedp=mallocedp@entry=0x7fffffffd36f, operate=operate@entry=0x7ffff7dec4d0 <dl_open_worker>, args=args@entry=0x7fffffffd380) at dl-error.c:187
    #7 0x00007ffff7debda9 in _dl_open (file=0x7ffff273b23d "libEGL.so.1", mode=-2147483647, caller_dlopen=0x7ffff27365fa <_glfwInitEGL+74>, nsid=-2,
    argc=<optimized out>, argv=<optimized out>, env=0x7fffffffd788) at dl-open.c:660
    #8 0x00007ffff1bacf09 in dlopen_doit (a=a@entry=0x7fffffffd5b0) at dlopen.c:66
    #9 0x00007ffff7de7564 in _dl_catch_error (objname=0xc26bb0, errstring=0xc26bb8, mallocedp=0xc26ba8, operate=0x7ffff1baceb0 <dlopen_doit>,
    args=0x7fffffffd5b0) at dl-error.c:187
    #10 0x00007ffff1bad571 in _dlerror_run (operate=operate@entry=0x7ffff1baceb0 <dlopen_doit>, args=args@entry=0x7fffffffd5b0) at dlerror.c:163
    #11 0x00007ffff1bacfa1 in __dlopen (file=<optimized out>, mode=<optimized out>) at dlopen.c:87
    #12 0x00007ffff27365fa in _glfwInitEGL () from /libglfw.so.3
    #13 0x00007ffff272c5c1 in _glfwPlatformInit () from /libglfw.so.3
    #14 0x00007ffff2724595 in glfwInit () from /libglfw.so.3
    #15 0x0000000000401315 in main () at test_main.cpp:6

    The program executes normally when the tensorflow member and include are commented out. I am running Ubuntu 16.04 and compile with gcc7. I didn't install any custom version of protobuf myself. Has anybody experienced similar issues?

    Thanks,
    Markus
     
  2. Emo Todorov

    Emo Todorov Administrator Staff Member

    If you are using the precompiled glfw library in the mujoco distribution, maybe you should compile glfw yourself, and find some way to make it compatible with tensorflow (no idea how to do the latter).

    There is a call to InitEGL in your post (#12). Are you trying to use OpenGL via EGL? If so, you should first make sure that your video driver is set up to work with EGL, independent of tensorflow. The default driver installation may not have EGL support enabled.
     
  3. Building glfw from source solved the problem in the end.
    Thank you!