App crashing at pthread_mutex_lock called from libwayland-client

Hi!

I’m back again trying to compile and run Ogre3D graphics engine.
I could compile it with two different approaches, both of them throwing the same (or almost the same) error:

First, I did a native build inside a container, Dockerfile used was:

FROM --platform=linux/arm64 torizon/wayland-base-vivante:2 AS base
RUN apt-get -y update && apt-get install -y --no-install-recommends \
    apt-utils \
    && apt-mark hold dash && apt-get -y upgrade && apt-mark unhold dash \
    && apt-get clean && apt-get autoremove && rm -rf /var/lib/apt/lists/*
ARG ACCEPT_FSL_EULA=1

RUN apt-get -y update && apt-get install -y git cmake gcc g++ make libxrandr-dev libglu1-mesa-dev libzip-dev libfreeimage-dev libpoco-dev libois-dev libzzip-0-13 libzzip-dev doxygen libcgal-dev libcppunit-dev libxt-dev libxaw7-dev pkg-config gdb x11-apps nano libsdl2-2.0 libegl-vivante1-dev
USER torizon
RUN cd /home/torizon/ && git clone https://github.com/OGRECave/ogre
RUN mkdir -p /home/torizon/ogre/bld && cd /home/torizon/ogre/bld && cmake -DCMAKE_BUILD_TYPE=Debug -DOGRE_GLSUPPORT_USE_EGL=1 -DOGRE_BUILD_RENDERSYSTEM_GLES2=1 -DOGRE_BUILD_SAMPLES=1 -DOGRE_CONFIG_THREADS=0 -DOGRE_INSTALL_DOCS=0 -DOGRE_BUILD_PLUGIN_CG=0 -DOGRE_INSTALL_MEDIA=1 -DOGRE_BUILD_TOOLS=0 -DOGRE_BUILD_TESTS=0 -DOGRE_INSTALL_SAMPLES=1 ../
RUN cd /home/torizon/ogre/bld && make
USER root
RUN cd /home/torizon/ogre/bld && make install

I ran that container as:

docker run -e ACCEPT_FSL_EULA=1 -e DISPLAY=:0 -it --rm --name=wayland-app --user=torizon -v /dev/dri:/dev/dri -v /dev/galcore:/dev/galcore -v /tmp:/tmp -v /run/:/run/ --device-cgroup-rule='c 199:* rmw' --device-cgroup-rule='c 226:* rmw' --cap-add=SYS_PTRACE --security-opt seccomp=unconfined ogre-way-base-egl-j1

Running the sample built at /home/torizon/ogre/bld/bin/SampleBrowser, I got the following error:

torizon@0c2f3e5ed77f:~/ogre/bld/bin$ gdb SampleBrowser
GNU gdb (Debian 9.2-1) 9.2
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "aarch64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from SampleBrowser...
(gdb) catch throw
Catchpoint 1 (throw)
(gdb) r
Starting program: /home/torizon/ogre/bld/bin/SampleBrowser
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/aarch64-linux-gnu/libthread_db.so.1".
Creating resource group General
Creating resource group OgreInternal
Creating resource group OgreAutodetect
SceneManagerFactory for type 'DefaultSceneManager' registered.
Registering ResourceManager for type Material
Registering ResourceManager for type Mesh
Registering ResourceManager for type Skeleton
MovableObjectFactory for type 'ParticleSystem' registered.
ArchiveFactory for archive type FileSystem registered.
ArchiveFactory for archive type Zip registered.
ArchiveFactory for archive type EmbeddedZip registered.
DDS codec registering
ETC codec registering
ASTC codec registering
Registering ResourceManager for type HighLevelGpuProgram
Registering ResourceManager for type Compositor
MovableObjectFactory for type 'Entity' registered.
MovableObjectFactory for type 'Light' registered.
MovableObjectFactory for type 'BillboardSet' registered.
MovableObjectFactory for type 'ManualObject' registered.
MovableObjectFactory for type 'BillboardChain' registered.
MovableObjectFactory for type 'RibbonTrail' registered.
Loading library /home/torizon/ogre/bld/lib/RenderSystem_GLES2.so.1.12.12
Installing plugin: OpenGL ES 2.0 RenderSystem
OpenGL ES 2.x Rendering Subsystem created.
[New Thread 0xffffe5601170 (LWP 22)]
[New Thread 0xffffe4e00170 (LWP 23)]

Thread 1 "SampleBrowser" received signal SIGSEGV, Segmentation fault.
0x0000fffff6e6dbd0 in pthread_mutex_lock () from /lib/aarch64-linux-gnu/libpthread.so.0
(gdb) bt
#0  0x0000fffff6e6dbd0 in pthread_mutex_lock () from /lib/aarch64-linux-gnu/libpthread.so.0
#1  0x0000fffff69432f0 in wl_proxy_create_wrapper () from /usr/lib/aarch64-linux-gnu/libwayland-client.so.0
#2  0x0000fffff6ba1b50 in ?? () from /usr/lib/aarch64-linux-gnu/libEGL.so.1
#3  0x0000fffff6b94534 in eglInitialize () from /usr/lib/aarch64-linux-gnu/libEGL.so.1
#4  0x0000fffff6c7d694 in Ogre::EGLSupport::getGLDisplay (this=0xaaaaaab17b90) at /home/torizon/ogre/RenderSystems/GLSupport/src/EGL/OgreEGLSupport.cpp:65
#5  0x0000fffff6c618c4 in Ogre::X11EGLSupport::getGLDisplay (this=0xaaaaaab17b90) at /home/torizon/ogre/RenderSystems/GLSupport/src/EGL/X11/OgreX11EGLSupport.cpp:280
#6  0x0000fffff6c60ba4 in Ogre::X11EGLSupport::X11EGLSupport (this=0xaaaaaab17b90, profile=4) at /home/torizon/ogre/RenderSystems/GLSupport/src/EGL/X11/OgreX11EGLSupport.cpp:51
#7  0x0000fffff6c60b44 in Ogre::getGLSupport (profile=4) at /home/torizon/ogre/RenderSystems/GLSupport/src/EGL/X11/OgreX11EGLSupport.cpp:45
#8  0x0000fffff6c3d1c4 in Ogre::GLES2RenderSystem::GLES2RenderSystem (this=0xaaaaaab17180) at /home/torizon/ogre/RenderSystems/GLES2/src/OgreGLES2RenderSystem.cpp:178
#9  0x0000fffff6c3cb18 in Ogre::GLES2Plugin::install (this=0xaaaaaab17100) at /home/torizon/ogre/RenderSystems/GLES2/src/OgreGLES2Plugin.cpp:48
#10 0x0000fffff79c026c in Ogre::Root::installPlugin (this=0xaaaaaab00b20, plugin=0xaaaaaab17100) at /home/torizon/ogre/OgreMain/src/OgreRoot.cpp:1188
#11 0x0000fffff6c28bc4 in Ogre::dllStartPlugin () at /home/torizon/ogre/RenderSystems/GLES2/src/OgreGLES2EngineDll.cpp:41
#12 0x0000fffff79c064c in Ogre::Root::loadPlugin (this=0xaaaaaab00b20, pluginName="/home/torizon/ogre/bld/lib/RenderSystem_GLES2") at /home/torizon/ogre/OgreMain/src/OgreRoot.cpp:1237
#13 0x0000fffff79bf2c4 in Ogre::Root::loadPlugins (this=0xaaaaaab00b20, pluginsfile="./plugins.cfg") at /home/torizon/ogre/OgreMain/src/OgreRoot.cpp:973
#14 0x0000fffff79bc9ac in Ogre::Root::Root (this=0xaaaaaab00b20, pluginFileName="./plugins.cfg", configFileName="./ogre.cfg", logFileName="./ogre.log")
    at /home/torizon/ogre/OgreMain/src/OgreRoot.cpp:227
#15 0x0000fffff7f76d3c in OgreBites::ApplicationContextBase::createRoot (this=0xfffffffff238) at /home/torizon/ogre/Components/Bites/src/OgreApplicationContextBase.cpp:191
#16 0x0000fffff7f7663c in OgreBites::ApplicationContextBase::initApp (this=0xfffffffff238) at /home/torizon/ogre/Components/Bites/src/OgreApplicationContextBase.cpp:55
#17 0x0000aaaaaaab6b28 in OgreBites::SampleContext::go (this=0xfffffffff238, initialSample=0x0) at /home/torizon/ogre/Samples/Common/include/SampleContext.h:143
#18 0x0000aaaaaaab44e4 in main (argc=1, argv=0xfffffffff648) at /home/torizon/ogre/Samples/Browser/src/main.cpp:89

After searching in the Internet, I couldn’t solve that issue, so I tried with the second approach: cross-compiling using Visual Studio Code extension for Torizon.

My settings.json file content is:

{
    "torizon.configuration": "debug",
    "cmake.configureOnOpen": false,
    "torizon.appfolder": "appconfig_0",
    "cmake.installPrefix": "/workspaces/ogre/appconfig_0/work/ogre",
    "cmake.configureSettings": {
        "OGRE_GLSUPPORT_USE_EGL":1,
        "OGRE_BUILD_RENDERSYSTEM_GL":0,
        "OGRE_BUILD_RENDERSYSTEM_GL3PLUS":0,
        "OGRE_BUILD_RENDERSYSTEM_TINY":0,
        "OGRE_BUILD_RENDERSYSTEM_GLES2":1,
        "OGRE_BUILD_SAMPLES":1,
        "OGRE_CONFIG_THREADS": 1,
        "OGRE_INSTALL_DOCS":0,
        "OGRE_BUILD_PLUGIN_CG":0,
        "OGRE_INSTALL_MEDIA":1,
        "OGRE_BUILD_TOOLS":0,
        "OGRE_BUILD_TESTS":0,
        "OGRE_INSTALL_SAMPLES":1
    }
}

My config.yaml file content is:

{
"version": "2.0.0",
"tasks": [],
"options": {
    "env": {
        "TORIZON_PROP_APPNAME": "ogre",
        "TORIZON_PROP_ARG": "ARG SSHUSERNAME=#%application.username%#\n",
        "TORIZON_PROP_BUILDCOMMANDS": "COPY work/ogre /home/torizon/ogre",
        "TORIZON_PROP_BUILDFILES": "",
        "TORIZON_PROP_COMMAND": "",
        "TORIZON_PROP_DEVPACKAGES": "libgbm-vivante1-dev:arm64 libegl-vivante1-dev:arm64 libglesv2-vivante1-dev:arm64 libxrandr-dev:arm64  libzip-dev:arm64 libfreeimage-dev:arm64 libpoco-dev:arm64 libois-dev:arm64 libzzip-dev:arm64 doxygen libcgal-dev:arm64 libcppunit-dev:arm64 libxt-dev:arm64 libxaw7-dev:arm64 libsdl2-2.0:arm64",
        "TORIZON_PROP_ENV": "ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/ogre/lib OGRE_PLUGIN_DIR=/ogre/lib/OGRE",
        "TORIZON_PROP_EXENAME": "bin/SampleBrowser",
        "TORIZON_PROP_EXPOSE": "",
        "TORIZON_PROP_EXTRAPACKAGES": "libxt6 libxaw7 libzzip-0-13 libxrandr2 libsdl2-2.0 libwayland-client0 libwayland-server0 libgal-vivante1 libvsc-vivante1 libgbm-vivante1 libegl-vivante1 libgl-vivante1 libglesv2-vivante1 libglesv1-cm-vivante1 libglslc-vivante1",
        "TORIZON_PROP_LANGUAGE": "c-cpp-nossh",
        "TORIZON_PROP_PREINSTALLCOMMANDS": "",
        "TORIZON_PROP_SDKPOSTINSTALLCOMMANDS": "",
        "TORIZON_PROP_SDKPREINSTALLCOMMANDS": "",
        "TORIZON_PROP_TARGETCOMMANDS": "",
        "TORIZON_PROP_TARGETFILES": "",
        "TORIZON_PROP_APPARGS": "",
        "TORIZON_PROP_MAIN": "main.py"
    }
}

As suggested by Valter Minute some time before, I added this line at Ogre3D’s CMakeLists.txt last line:

install (SCRIPT "${CMAKE_SOURCE_DIR}/PostInstall.cmake")

And I created PostInstall.cmake, whose contents are:

message("Post Install Script")
execute_process(COMMAND bash "-c" "sed -i s+/workspaces/ogre/appconfig_0/work/ogre+/ogre+g${CMAKE_INSTALL_PREFIX}/share/OGRE/*.cfg")

To run the SampleBrowser correctly, I had to run the container manually with the same command as before, and do a chmod 777 /home/torizon/ogre/bin as root, because the app needs to create a file inside that folder.
After that, i ran:

torizon@fa64e1d682bc:~/ogre/bin$ gdb SampleBrowser
GNU gdb (Debian 9.2-1) 9.2
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "aarch64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from SampleBrowser...
(gdb) r
Starting program: /home/torizon/ogre/bin/SampleBrowser
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/aarch64-linux-gnu/libthread_db.so.1".
Creating resource group General
Creating resource group OgreInternal
Creating resource group OgreAutodetect
SceneManagerFactory for type 'DefaultSceneManager' registered.
Registering ResourceManager for type Material
Registering ResourceManager for type Mesh
Registering ResourceManager for type Skeleton
MovableObjectFactory for type 'ParticleSystem' registered.
ArchiveFactory for archive type FileSystem registered.
ArchiveFactory for archive type Zip registered.
ArchiveFactory for archive type EmbeddedZip registered.
DDS codec registering
ETC codec registering
ASTC codec registering
Registering ResourceManager for type HighLevelGpuProgram
Registering ResourceManager for type Compositor
MovableObjectFactory for type 'Entity' registered.
MovableObjectFactory for type 'Light' registered.
MovableObjectFactory for type 'BillboardSet' registered.
MovableObjectFactory for type 'ManualObject' registered.
MovableObjectFactory for type 'BillboardChain' registered.
MovableObjectFactory for type 'RibbonTrail' registered.
setting PluginFolder from OGRE_PLUGIN_DIR environment variable
Loading library /ogre/lib/OGRE/RenderSystem_GLES2.so.1.12.12
Installing plugin: OpenGL ES 2.0 RenderSystem
OpenGL ES 2.x Rendering Subsystem created.
[New Thread 0xffffe5603170 (LWP 651)]
[New Thread 0xffffe4e02170 (LWP 652)]

Thread 1 "SampleBrowser" received signal SIGSEGV, Segmentation fault.
0x0000fffff6e6bbd0 in __GI___pthread_mutex_lock (mutex=0xf3) at pthread_mutex_lock.c:67
67      pthread_mutex_lock.c: No such file or directory.
(gdb) bt
#0  0x0000fffff6e6bbd0 in __GI___pthread_mutex_lock (mutex=0xf3) at pthread_mutex_lock.c:67
#1  0x0000fffff69462f0 in wl_proxy_create_wrapper () from /usr/lib/aarch64-linux-gnu/libwayland-client.so.0
#2  0x0000fffff6ba4b50 in ?? () from /usr/lib/aarch64-linux-gnu/libEGL.so.1
#3  0x0000fffff6b97534 in eglInitialize () from /usr/lib/aarch64-linux-gnu/libEGL.so.1
#4  0x0000fffff6c7f984 in Ogre::EGLSupport::getGLDisplay (this=0xaaaaaab15670) at /workspaces/ogre/RenderSystems/GLSupport/src/EGL/OgreEGLSupport.cpp:65
#5  0x0000fffff6c63bc0 in Ogre::X11EGLSupport::getGLDisplay (this=0xaaaaaab15670) at /workspaces/ogre/RenderSystems/GLSupport/src/EGL/X11/OgreX11EGLSupport.cpp:280
#6  0x0000fffff6c62ea0 in Ogre::X11EGLSupport::X11EGLSupport (this=0xaaaaaab15670, profile=4)
    at /workspaces/ogre/RenderSystems/GLSupport/src/EGL/X11/OgreX11EGLSupport.cpp:51
#7  0x0000fffff6c62e40 in Ogre::getGLSupport (profile=4) at /workspaces/ogre/RenderSystems/GLSupport/src/EGL/X11/OgreX11EGLSupport.cpp:45
#8  0x0000fffff6c3f4a8 in Ogre::GLES2RenderSystem::GLES2RenderSystem (this=0xaaaaaab14c60) at /workspaces/ogre/RenderSystems/GLES2/src/OgreGLES2RenderSystem.cpp:178
#9  0x0000fffff6c3edf8 in Ogre::GLES2Plugin::install (this=0xaaaaaab14be0) at /workspaces/ogre/RenderSystems/GLES2/src/OgreGLES2Plugin.cpp:48
#10 0x0000fffff79c00e8 in Ogre::Root::installPlugin (this=0xaaaaaab00b80, plugin=0xaaaaaab14be0) at /workspaces/ogre/OgreMain/src/OgreRoot.cpp:1177
#11 0x0000fffff6c2bea4 in Ogre::dllStartPlugin () at /workspaces/ogre/RenderSystems/GLES2/src/OgreGLES2EngineDll.cpp:41
#12 0x0000fffff79c04c8 in Ogre::Root::loadPlugin (this=0xaaaaaab00b80, pluginName="/ogre/lib/OGRE/RenderSystem_GLES2")
    at /workspaces/ogre/OgreMain/src/OgreRoot.cpp:1226
#13 0x0000fffff79bf140 in Ogre::Root::loadPlugins (this=0xaaaaaab00b80, pluginsfile="/home/torizon/ogre/bin/../share/OGRE/plugins.cfg")
    at /workspaces/ogre/OgreMain/src/OgreRoot.cpp:962
#14 0x0000fffff79bc8d4 in Ogre::Root::Root (this=0xaaaaaab00b80, pluginFileName="/home/torizon/ogre/bin/../share/OGRE/plugins.cfg", configFileName="./ogre.cfg",
    logFileName="./ogre.log") at /workspaces/ogre/OgreMain/src/OgreRoot.cpp:228
#15 0x0000fffff7f76d50 in OgreBites::ApplicationContextBase::createRoot (this=0xfffffffff208)
    at /workspaces/ogre/Components/Bites/src/OgreApplicationContextBase.cpp:191
#16 0x0000fffff7f76650 in OgreBites::ApplicationContextBase::initApp (this=0xfffffffff208) at /workspaces/ogre/Components/Bites/src/OgreApplicationContextBase.cpp:55
#17 0x0000aaaaaaab6b38 in OgreBites::SampleContext::go (this=0xfffffffff208, initialSample=0x0) at /workspaces/ogre/Samples/Common/include/SampleContext.h:143
#18 0x0000aaaaaaab44f4 in main (argc=1, argv=0xfffffffff618) at /workspaces/ogre/Samples/Browser/src/main.cpp:89

As we can see, it seems like the problem is the same as before. I couldn’t find any solution to this problem, and I’m not that experienced to find it by myself. I don’t know if it brings any useful information, but I tried this Waylang EGL example posted by someone here: https://gist.github.com/Miouyouyou/ca15af1c7f2696f66b0e013058f110b4, and it failed creating the context at eglCreateContext() on line 114, returning EGL_NO_CONTEXT.

Side note: on the first build with VSCode, I could make it run, but it wasn’t using GPU at all, and I got a very poor performance, because it was fully rendering with CPU. After testing, I realised that GPU drivers weren’t installed at all, so I had to install them. I don’t know if I’m wrong or if it’s a bug, but I thought that when I import a Torizon C/C++ project in VSCode and pick an “arm64v8 wayland vivante …” board, GPU drivers should have been included. The base container used for release container maybe should be wayland-base-vivante instead of wayland-base.

Thank you

We fixed the issue with the base container.
And we reproduced the issue here.
It seems that ogre relies on X11 to access the screen surfaces, and this seem to crash with the vivante-wayland libGL implementation.
I’ll try to investigate the smaller sample to check if we can get more information about the issue.

I managed to have the small sample working, I uploaded the project here.
But it uses wayland, not X11.

Hi Valter. Thank you for your time. I’m going to test that sample. I guess I should modify Ogre3D sources to use wayland directly, right?

I think this would be the solution. Replacing X11 the implementation under RenderSystem/GlSupport with a wayland-based one.