Segmentation Fault vs libG4graphics?

Ubuntu 18.04 LTS (used through Windows WSL)
Geant4-10.6.p03
gcc 7.5.0

Hello,
I have followed the standard guidelines here for building and installing Geant4.
By the end of it, I have run the geant.sh and geant4make.sh scripts and my environmental variables are

aeroulis89@DESKTOP-J2QLNGA:~/g4B1example/build$ printenv | grep G4
G4UI_USE_TCSH=1
G4INCLDATA=/home/aeroulis89/geant4.10.06.p03-install/share/Geant4-10.6.3/data/G4INCL1.0
G4INSTALL=/home/aeroulis89/geant4.10.06.p03-install/share/Geant4-10.6.3/geant4make
G4WORKDIR=/home/aeroulis89/geant4_workdir
G4LIB_USE_ZLIB=1
G4LEVELGAMMADATA=/home/aeroulis89/geant4.10.06.p03-install/share/Geant4-10.6.3/data/PhotonEvaporation5.5
G4RADIOACTIVEDATA=/home/aeroulis89/geant4.10.06.p03-install/share/Geant4-10.6.3/data/RadioactiveDecay5.4
G4MULTITHREADED=1
G4PIIDATA=/home/aeroulis89/geant4.10.06.p03-install/share/Geant4-10.6.3/data/G4PII1.3
G4SAIDXSDATA=/home/aeroulis89/geant4.10.06.p03-install/share/Geant4-10.6.3/data/G4SAIDDATA2.0
G4ABLADATA=/home/aeroulis89/geant4.10.06.p03-install/share/Geant4-10.6.3/data/G4ABLA3.1
G4SYSTEM=Linux-g++
G4REALSURFACEDATA=/home/aeroulis89/geant4.10.06.p03-install/share/Geant4-10.6.3/data/RealSurface2.1.1
G4INCLUDE=/home/aeroulis89/geant4.10.06.p03-install/include/Geant4
G4NEUTRONHPDATA=/home/aeroulis89/geant4.10.06.p03-install/share/Geant4-10.6.3/data/G4NDL4.6
G4PARTICLEXSDATA=/home/aeroulis89/geant4.10.06.p03-install/share/Geant4-10.6.3/data/G4PARTICLEXS2.1
G4LIB=/home/aeroulis89/geant4.10.06.p03-install/lib/Geant4-10.6.3
G4VIS_USE_OPENGLQT=1
G4ENSDFSTATEDATA=/home/aeroulis89/geant4.10.06.p03-install/share/Geant4-10.6.3/data/G4ENSDFSTATE2.2
G4LEDATA=/home/aeroulis89/geant4.10.06.p03-install/share/Geant4-10.6.3/data/G4EMLOW7.9.1
G4UI_USE_QT=1
G4LIB_BUILD_SHARED=1

Then, I embark on trying out example B1:

cp -r geant4.10.06.p03-install/share/Geant4-10.6.3/examples/basic/B1 g4B1example
cd /home/g4B1example
mkdir build
cd build

aeroulis89@DESKTOP-J2QLNGA:~/g4B1example/build$ cmake -DGEANT4_DIR= /home/aeroulis89/geant4.10.06.p03-install/lib/Geant4-10.6.3/ /home/aeroulis89/g4B1example/
    -- The C compiler identification is GNU 7.5.0
    -- The CXX compiler identification is GNU 7.5.0
    -- Check for working C compiler: /usr/bin/cc
    -- Check for working C compiler: /usr/bin/cc -- works
    -- Detecting C compiler ABI info
    -- Detecting C compiler ABI info - done
    -- Detecting C compile features
    -- Detecting C compile features - done
    -- Check for working CXX compiler: /usr/bin/c++
    -- Check for working CXX compiler: /usr/bin/c++ -- works
    -- Detecting CXX compiler ABI info
    -- Detecting CXX compiler ABI info - done
    -- Detecting CXX compile features
    -- Detecting CXX compile features - done
    -- Found EXPAT: /usr/lib/x86_64-linux-gnu/libexpat.so (found suitable version "2.2.5", minimum required is "2.2.5")
    -- Found OpenGL: /usr/lib/x86_64-linux-gnu/libOpenGL.so
    -- Configuring done
    -- Generating done
    CMake Warning:
      Manually-specified variables were not used by the project:

    GEANT4_DIR
-- Build files have been written to: /home/aeroulis89/g4B1example/build

Then I do make

aeroulis89@DESKTOP-J2QLNGA:~/g4B1example/build$ make
Scanning dependencies of target exampleB1
[ 12%] Building CXX object CMakeFiles/exampleB1.dir/exampleB1.cc.o
[ 25%] Building CXX object CMakeFiles/exampleB1.dir/src/B1ActionInitialization.cc.o
[ 37%] Building CXX object CMakeFiles/exampleB1.dir/src/B1DetectorConstruction.cc.o
[ 50%] Building CXX object CMakeFiles/exampleB1.dir/src/B1EventAction.cc.o
[ 62%] Building CXX object CMakeFiles/exampleB1.dir/src/B1PrimaryGeneratorAction.cc.o
[ 75%] Building CXX object CMakeFiles/exampleB1.dir/src/B1RunAction.cc.o
[ 87%] Building CXX object CMakeFiles/exampleB1.dir/src/B1SteppingAction.cc.o
[100%] Linking CXX executable exampleB1
[100%] Built target exampleB1

Finally, I attempt to run it

aeroulis89@DESKTOP-J2QLNGA:~/g4B1example/build$ ./exampleB1
Available UI session types: [ Qt, GAG, tcsh, csh ]
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-aeroulis89'
G4WT1 > /control/saveHistory
G4WT0 > /control/saveHistory
G4WT1 > /run/verbose 2
G4WT0 > /run/verbose 2
G4WT1 > /run/initialize
G4WT0 > /run/initialize
G4WT0 > /run/physicsModified
G4WT1 > /run/physicsModified
Segmentation fault

I do not get a specific error number which is strange…
Then I try a naive idea, which tells me something about the libG4graphics library…

aeroulis89@DESKTOP-J2QLNGA:~/g4B1example/build$ sudo ./exampleB1
./exampleB1: error while loading shared libraries: libG4graphics_reps.so: cannot open shared object file: No such file or directory

However this library does exist…

aeroulis89@DESKTOP-J2QLNGA:~/g4B1example/build$ ldd exampleB1 | grep libG4graphics
        libG4graphics_reps.so => /home/aeroulis89/geant4.10.06.p03-install/lib/libG4graphics_reps.so (0x00007f06d4be1000)

As another clue that I saw might be useful to know from other similar forum questions is my LD_LIBRARY_PATH

aeroulis89@DESKTOP-J2QLNGA:~/g4B1example/build$ echo $LD_LIBRARY_PATH
/usr/lib/x86_64-linux-gnu:/home/aeroulis89/geant4.10.06.p03-install/lib:/home/aeroulis89/geant4.10.06.p03-install/lib:/home/aeroulis89/builddir/lib

Can someone help me debug this? Any hint would be much appreciated.
Alex

I think it’s case sensitive when you run cmake, so you need to use -DGeant4_DIR and not -DGEANT4_DIR.

That is why you get the CMake Warning section of the ouput. Don’t know if the space after the equals matters, but I would also get rid of that.

Thank you very much for that.
Indeed, after making these changes, the warning disappears

aeroulis89@DESKTOP-J2QLNGA:~/B1example/build$ cmake -DGeant4_DIR=/home/aeroulis89/geant4.10.06.p03-install/lib/Geant4-10.6.3/ /home/aeroulis89/B1example/B1/
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found EXPAT: /usr/lib/x86_64-linux-gnu/libexpat.so (found suitable version "2.2.5", minimum required is "2.2.5")
-- Found OpenGL: /usr/lib/x86_64-linux-gnu/libOpenGL.so
-- Configuring done
-- Generating done
-- Build files have been written to: /home/aeroulis89/B1example/build

Unfortunately, the segmentation fault still persists though even with this change…

Your install and setup look correct, can you run other UI applications through that instance of Linux?

I don’t have any experience with WSL, but a quick google suggests you need to have an X server running on your windows machine for Linux based UI programs to work.

Yes, I am setting up an X server so that I can open up UI programs from Linux. This has worked for me for different programs (firefox, gedit,…etc.)
If it is of any help, the command I have to run in order to “connect” Linux with the X server is
export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0 export LIBGL_ALWAYS_INDIRECT=1

Is there a log where I could check what sort of segmentation fault I get?

I think (but I’ve not used WSL yet) that you should be able to use normal debugging tools like gdb to run and get a backtrace of the segfault. Geant4’s built in Release mode by default (but you can change to RelWithDebInfo, so won’t give line numbers, but this should at least identify the class/member function where it goes wrong.

Thank you both for taking the time to help.

I did run the executable with gdb and got the following

(gdb) run
Starting program: /home/aeroulis89/B1example/build/exampleB1
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Available UI session types: [ Qt, GAG, tcsh, csh ]
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-aeroulis89'
[New Thread 0x7fffe2589700 (LWP 1685)]
[New Thread 0x7fffe1032700 (LWP 1686)]
[New Thread 0x7fffe0809700 (LWP 1688)]
[New Thread 0x7fffd3fff700 (LWP 1689)]
G4WT1 > /control/saveHistory
G4WT0 > /control/saveHistory
G4WT1 > /run/verbose 2
G4WT0 > /run/verbose 2
G4WT1 > /run/initialize
G4WT0 > /run/initialize
G4WT1 > /run/physicsModified
G4WT0 > /run/physicsModified

Thread 1 "exampleB1" received signal SIGSEGV, Segmentation fault.
0x00007fffecf141e8 in QOpenGLContext::format() const () from /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5

any clue where that points to?
Alex

This is beyond me now, but running bt in gdb after the crash to get the full stack trace might be helpful.

Thanks for the backtrace command tip (I am not familiar with using gdb).

(gdb) bt
#0  0x00007fffecf141e8 in QOpenGLContext::format() const () from /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5
#1  0x00007fffecf14354 in QOpenGLContext::isOpenGLES() const () from /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5
#2  0x00007fffecf143b9 in QOpenGLContext::versionFunctions(QOpenGLVersionProfile const&) const ()
   from /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5
#3  0x00007fffedda6634 in ?? () from /usr/lib/x86_64-linux-gnu/libQt5OpenGL.so.5
#4  0x00007fffeddaa3b0 in QGLWidget::renderText(double, double, double, QString const&, QFont const&) ()
   from /usr/lib/x86_64-linux-gnu/libQt5OpenGL.so.5
#5  0x00007ffff70803b0 in G4OpenGLQtViewer::DrawText(G4Text const&) ()
   from /home/aeroulis89/geant4.10.06.p03-build/BuildProducts/lib/libG4OpenGL.so
#6  0x00007ffff705877b in G4OpenGLStoredSceneHandler::AddPrimitive(G4Text const&) ()
   from /home/aeroulis89/geant4.10.06.p03-build/BuildProducts/lib/libG4OpenGL.so
#7  0x00007ffff70557cc in G4OpenGLStoredViewer::AddPrimitiveForASingleFrame(G4Text const&) ()
   from /home/aeroulis89/geant4.10.06.p03-build/BuildProducts/lib/libG4OpenGL.so
#8  0x00007ffff7055bc6 in G4OpenGLStoredViewer::DrawDisplayLists() ()
   from /home/aeroulis89/geant4.10.06.p03-build/BuildProducts/lib/libG4OpenGL.so
#9  0x00007ffff7087a7e in G4OpenGLStoredQtViewer::ComputeView() ()
   from /home/aeroulis89/geant4.10.06.p03-build/BuildProducts/lib/libG4OpenGL.so
#10 0x00007ffff7087bfa in G4OpenGLStoredQtViewer::paintGL() ()
   from /home/aeroulis89/geant4.10.06.p03-build/BuildProducts/lib/libG4OpenGL.so
#11 0x00007fffedda9cc4 in QGLWidget::glDraw() () from /usr/lib/x86_64-linux-gnu/libQt5OpenGL.so.5
#12 0x00007fffed6d5048 in QWidget::event(QEvent*) () from /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#13 0x00007fffed69683c in QApplicationPrivate::notify_helper(QObject*, QEvent*) ()
   from /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#14 0x00007fffed69e104 in QApplication::notify(QObject*, QEvent*) () from /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#15 0x00007fffec9188d8 in QCoreApplication::notifyInternal2(QObject*, QEvent*) ()
   from /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#16 0x00007fffed6ce19a in QWidgetPrivate::sendPaintEvent(QRegion const&) ()
   from /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#17 0x00007fffed6ce75a in QWidgetPrivate::drawWidget(QPaintDevice*, QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*) () from /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#18 0x00007fffed6a3f5b in QWidgetPrivate::repaint_sys(QRegion const&) ()
   from /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#19 0x00007fffed6f1d4e in ?? () from /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#20 0x00007fffed6f266d in ?? () from /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#21 0x00007fffed69683c in QApplicationPrivate::notify_helper(QObject*, QEvent*) ()
   from /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#22 0x00007fffed69e104 in QApplication::notify(QObject*, QEvent*) () from /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#23 0x00007fffec9188d8 in QCoreApplication::notifyInternal2(QObject*, QEvent*) ()
   from /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#24 0x00007fffecedb49f in QGuiApplicationPrivate::processExposeEvent(QWindowSystemInterfacePrivate::ExposeEvent*) ()
   from /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5
#25 0x00007fffecedc0dd in QGuiApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent*) () from /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5
#26 0x00007fffeceb32eb in QWindowSystemInterface::sendWindowSystemEvents(QFlags<QEventLoop::ProcessEventsFlag>) ()
   from /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5
#27 0x00007fffe6c97260 in ?? () from /usr/lib/x86_64-linux-gnu/libQt5XcbQpa.so.5
#28 0x00007fffea50f417 in g_main_context_dispatch () from /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
#29 0x00007fffea50f650 in ?? () from /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
#30 0x00007fffea50f6dc in g_main_context_iteration () from /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
#31 0x00007fffec97188f in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) ()
   from /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#32 0x00007fffec91690a in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) ()
   from /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#33 0x00007fffec91f9b4 in QCoreApplication::exec() () from /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#34 0x00007ffff6ded6c4 in G4UIQt::SessionStart() ()
   from /home/aeroulis89/geant4.10.06.p03-build/BuildProducts/lib/libG4interfaces.so
#35 0x0000555555559a83 in main (argc=<optimized out>, argv=0x7fffffffd978)
    at /home/aeroulis89/B1example/B1/exampleB1.cc:103

I get a black window opened up but it crashes at the ui->SessionStart();
It seems to be a visualisation issue?
By the way, I noticed some “??” in frames #3, 19, 20, 27 and 29. Is that normal?

Alex

I think the “??” mean that you compiled geant4 in Release mode rather than RelWithDebInfo so some of the binaries don’t have debug symbols. See the CMAKE_BUILD_TYPE option during configuration.

Poking around a bit I found this post suggesting to disable LIBGL_ALWAYS_INDIRECT. From one of your comments above, you look to enable it. Have you tried that?

Magic! that worked for me! I can’t thank you more. I learnt quite a few things 2 days now.

To sum up, when launching VcXsrv from a GUI client, I had to leave the second option box “Native opengl” unchecked.
image
then, on a bash I would connect Linux to the X server by
export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0
and then I was able to run B1 example.

3 Likes

Thanks both for the feedback and info - we don’t test/support WSL at the moment, so really useful to have this info :+1:

Hi

sudo cmake -DCMAKE_INSTALL_PREFIX=…/GEANT4.10.07.p01 -DGEANT4_BUILD_MULTITHREADED=ON -DGEANT4_INSTALL_DATA=ON -DGEANT4_USE_QT=ON -DGEANT4_USE_RAYTRACER_X11=OFF -DGEANT4_USE_OPENGL_X11=ON -DGEANT4_USE_GDML=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo -DGEANT4_USE_XM=OFF -DGEANT4_ENABLE_TESTING=OFF -DGEANT4_BUILD_CXXSTD=14 -DGEANT4_USE_RAYTRACER_X11=OFF -DGEANT4_USE_SYSTEM_CLHEP=OFF -DGEANT4_USE_SYSTEM_ZLIB=OFF …/geant4.10.07.p01

Known Features:
staticlibs[no] multithreading[yes] smartstack[no] php_as_hp[no] clhep[yes] expat[no] zlib[yes] gdml[yes] usolids[no] freetype[no] hdf5[no] g3tog4[no] qt[yes] motif[no] raytracer-x11[no] opengl-x11[yes] openinventor[no]

I’m also trying to use geant4 with WSL2(ubnutu 20.04). For the example B2a, with 100 events it crashs and says to increase the “/vis/ogl/set/displayListLimit”. Once done, it works but the 3D view is verry lagged(low fps), is it normal ?

Otherwise it is clearly due to wsl drivers/opengl lib. By default examples use “OpenGLStoredQt”, do you know the difference between OpenGLStoredQt and OpenGLImmediateQt ?

I launched the example B2a with gdb, after typing “where” I get this if it can help :
Thread 1 “exampleB2a” received signal SIGINT, Interrupt.
0x00007ffff6d5faff in poll () from /usr/lib/x86_64-linux-gnu/libc.so.6
(gdb) where
#0 0x00007ffff6d5faff in poll () from /usr/lib/x86_64-linux-gnu/libc.so.6
#1 0x00007ffff2a8636e in ?? () from /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
#2 0x00007ffff2a864a3 in g_main_context_iteration ()
from /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
#3 0x00007ffff3e8d565 in QEventDispatcherGlib::processEvents(QFlagsQEventLoop::ProcessEventsFlag) () from /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#4 0x00007ffff3e344db in QEventLoop::exec(QFlagsQEventLoop::ProcessEventsFlag) ()
from /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#5 0x00007ffff3e3c246 in QCoreApplication::exec() ()
from /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#6 0x00007ffff7b90063 in G4UIQt::SessionStart (this=0x5555555ee130)
at /home/dz/products/geant4.10.07.p01/source/interfaces/basic/src/G4UIQt.cc:1922
#7 0x000055555555dd5b in main (argc=, argv=0x7fffffffd828)
at /home/dz/TEST/B2/B2a/exampleB2a.cc:98

Regards

Also, for the option /run/numberOfThreads , it doesn’t work I get this message, you already faced this message?

illegal application state – command refused:"/run/numberOfThreads 8"

Hi

The second query first. Some commands can only be executed in certain application states. /run/numberOfThreads can only be executed in “PreInit” state, before run initialisation. Juts move it earlier. For example, in exampleB1 it is init_vis.mac.

John

Hi again

Now the first query. 100 B2 events have lots of particle tracks - I’d expect it to have a low fps.

The difference between OpenGLStoredQt and OpenGLImmediateQt is that the former uses a graphical database (OpenGL display lists) so that rotating and zooming, etc., is fast. The latter does not so for every new frame the image is re-generated from the Geant4 kernel objects (volumes and trajectories, etc.).

Re the crash, looks like you are in the Qt graphical event loop. I have noticed Qt sometimes crashes if you ask too much it. All I can suggest is, please try again, perhaps with just a few events to start with. If it persists, we’ll have another look.

John

1 Like

So if I’ve well understand, I type ./exampleB1 init_vis.mac. This input gives me this error, and no visualization :

# Use this open statement to create an OpenGL view: /vis/open OGL 600x600-0+0 /vis/sceneHandler/create OGL WARNING: G4VisCommandSceneHandlerCreate::SetNewValue: Using fallback graphics system: OpenGLStoredX (OGLSX) /vis/viewer/create ! ! 600x600-0+0 /vis/viewer/refresh #

I report it but I do not think there is a possible thing to do, this is related to wsl I think

Hi,
can you see this command line /vis/open OGL in your init_vis.mac
or to run example B1 simply write ./exampleB1
i think it should work. can you try this ?
Priyanshu

Oh yes only “./exampleB1” it works, I have the qt vis but there is warnings(refer to the first message). And “./exampleB1 init_vis.mac” did not work at all

Regards

Sorry I was not understanding when you talked about the init_vis.mac, now I found it and there is no line with /vis/open OGL. I tried to add it with “OGLI”, does not work, it uses OGLS

I edited the file in the build folder of example

Regards