0
\$\begingroup\$

I'm developing application with C++ language and Irrlicht engine.

When I add std::runtime_error("err") expression into my code, I got segmentation fault at address 0 (before entering to main). If instead I use std::exception(), app runs fine.

How std::runtime_error() causes segfault and how to fix it? Thanks!

#include <stdexcept>
#include <exception>
#include "irrlicht.h"

int main() {
    irr::IrrlichtDevice* device = irr::createDevice();
    if (!device)
        throw std::runtime_error("err");  //without this run fine
}

Compile:

g++ -ggdb -Wall -Wextra -std=c++11 -o main main2.cc \
-lIrrlicht -lGL -lXxf86vm -lXext -lX11 -lXcursor

Backtrace:

(gdb) bt full
#0  0x00000000 in ?? ()
No symbol table info available.
#1  0xb5d88fe1 in init () at dlerror.c:177
No locals.
#2  0xb5d8942e in _dlerror_run          (operate=operate@entry=0xb5d88e10 <dlsym_doit>,     args=args@entry=0xbffff160) at dlerror.c:129
    result = <optimized out>
#3  0xb5d88e98 in __dlsym (handle=0x0, name=0xb7f8afe5  "posix_memalign") at dlsym.c:70
    args = {handle = 0x0, name = 0xb7f8afe5 "posix_memalign", who = 0xb7f674bc, sym = 0xb5d65b20}
    result = <optimized out>
#4  0xb7f674bc in ?? () from /usr/lib/nvidia-   304/libGL.so.1
No symbol table info available.
Backtrace stopped: previous frame inner to this frame     (corrupt stack?)

LD debug

LD_DEBUG=all LD_DEBUG_OUTPUT=log.txt ./main
tail log.txt.*

   3848:    symbol=__pthread_key_create;  lookup in file=/lib/i386-linux-gnu/libgcc_s.so.1 [0]
  3848: symbol=__pthread_key_create;  lookup in file=/lib/i386-linux-gnu/libc.so.6 [0]
  3848: symbol=__pthread_key_create;  lookup in file=/usr/lib/nvidia-304/tls/libnvidia-tls.so.304.131 [0]
  3848: symbol=__pthread_key_create;  lookup in file=/usr/lib/nvidia-304/libnvidia-glcore.so.304.131 [0]
  3848: symbol=__pthread_key_create;  lookup in file=/usr/lib/i386-linux-gnu/libXext.so.6 [0]
  3848: symbol=__pthread_key_create;  lookup in file=/lib/i386-linux-gnu/libdl.so.2 [0]
  3848: symbol=__pthread_key_create;  lookup in file=/usr/lib/i386-linux-gnu/libxcb.so.1 [0]
  3848: symbol=__pthread_key_create;  lookup in file=/lib/ld-linux.so.2 [0]
  3848: symbol=__pthread_key_create;  lookup in file=/usr/lib/i386-linux-gnu/libXau.so.6 [0]
  3848: symbol=__pthread_key_create;  lookup in file=/usr/lib/i386-linux-gnu/libXdmcp.so.6 [0]
\$\endgroup\$
2
  • \$\begingroup\$ What happens if you compile with -O0 and -g to disable optimizations and include debug symbols? Does the problem change? Does the stack trace become more useful? \$\endgroup\$
    – piojo
    Commented Mar 22, 2016 at 6:24
  • 1
    \$\begingroup\$ Nothing changes in the stack trace when compiled with -g -O0 flags. In the question I'm also including debug symbols (-ggdb flag) \$\endgroup\$
    – makrusan
    Commented Mar 22, 2016 at 6:49

1 Answer 1

0
\$\begingroup\$

Looks like a bug related to NVidia. I've found workaround on this site: https://bugs.launchpad.net/ubuntu/+source/nvidia-graphics-drivers-319/+bug/1248642

(post #18)

explicitly specifying the path to NVIDIA's libGL using gcc's -L flag:

g++ -g -O0 -Wall -Wextra -std=c++11  -o main \
    main3.cc -L/usr/lib/nvidia-304/ -lGL -lglut

in this case app runs fine, no segfaults.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .