Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Random segmentation faults with samples #23

Closed
MichaelMackus opened this issue May 16, 2019 · 6 comments
Closed

Random segmentation faults with samples #23

MichaelMackus opened this issue May 16, 2019 · 6 comments
Assignees
Labels

Comments

@MichaelMackus
Copy link
Contributor

I got everything compiled and working, but am getting random segmentation faults with the samples. Sometimes it runs successfully, other times, not:

 ~/dev/libtcod/samples (master) $ ./samples_c
Segmentation fault
 ~/dev/libtcod/samples (master) $ ./samples_c
Segmentation fault
 ~/dev/libtcod/samples (master) $ ./samples_c
Segmentation fault
 ~/dev/libtcod/samples (master) $ ./samples_c
Segmentation fault
 ~/dev/libtcod/samples (master) $ ./samples_c
Segmentation fault
 ~/dev/libtcod/samples (master) $ ./samples_c
Segmentation fault
 ~/dev/libtcod/samples (master) $ ./samples_c
Segmentation fault
 ~/dev/libtcod/samples (master) $ ./samples_c
Segmentation fault
 ~/dev/libtcod/samples (master) $ ./samples_c
Segmentation fault
 ~/dev/libtcod/samples (master) $ ./samples_c
 ~/dev/libtcod/samples (master) $
(Runs successfully)

Is this related to #13? If so, any guidance on how to avoid?

@MichaelMackus
Copy link
Contributor Author

For reference, I'm on commit SHA: 8584e74 (HEAD -> master, tag: 1.11.5, origin/master, origin/HEAD) Prepare 1.11.5 release.

uname -a
Linux deathstar 4.14.56-gentoo #1 SMP Sun Jul 22 12:22:13 PDT 2018 x86_64 Intel(R) Core(TM)2 Duo CPU P8600 @ 2.40GHz GenuineIntel GNU/Linux

@HexDecimal
Copy link
Collaborator

Heightmaps are not used in the samples so this isn't related to issue #13.

I'm unable to reproduce the crash.

Are you able to use gdb or valgrind? It would help if there was more info on where the crash could be. samples_cpp is better for debugging.

@HexDecimal HexDecimal self-assigned this May 16, 2019
@HexDecimal HexDecimal added the bug label May 16, 2019
@haxpor
Copy link

haxpor commented May 20, 2019

I gathered some of debugging info here

samples_cpp

Whenever navigate to "Name generator" (note all others are fine), it will crash

Thread 1 "samples_cpp" received signal SIGSEGV, Segmentation fault.
0x000055555555a080 in render_name (first=<optimized out>, key=0x7fffffffd030, mouse=<optimized out>) at ../../samples/samples_cpp.cpp:1119
1119		sampleConsole.printf(1,1,"%s\n\n+ : next generator\n- : prev generator",
(gdb) bt
#0  0x000055555555a080 in render_name (first=<optimized out>, key=0x7fffffffd030, mouse=<optimized out>)
    at ../../samples/samples_cpp.cpp:1119
#1  0x0000555555558489 in main (argc=<optimized out>, argv=<optimized out>) at ../../samples/samples_cpp.cpp:1510

samples_c
It will crash right at the startup time with following log

Thread 1 "samples_c" received signal SIGABRT, Aborted.
__GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
51	../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) bt
#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
#1  0x00007ffff7389801 in __GI_abort () at abort.c:79
#2  0x00007ffff68ba957 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#3  0x00007ffff68c0ab6 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#4  0x00007ffff68c0af1 in std::terminate() () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#5  0x00007ffff68c0d24 in __cxa_throw () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#6  0x00007ffff7b542d5 in tcod::console::UnicodeIterator::parse_unicode (this=<optimized out>)
    at ../../src/libtcod/console/printing.cpp:890
#7  tcod::console::UnicodeIterator::operator++ (this=<optimized out>) at ../../src/libtcod/console/printing.cpp:819
#8  tcod::console::FormattedUnicodeIterator::operator++ (this=<optimized out>) at ../../src/libtcod/console/printing.cpp:927
#9  tcod::console::print_internal_ (con=..., x=<optimized out>, y=47, width=<optimized out>, height=<optimized out>, 
    string="\342\000 : select a sample", fg=0x555555772fb8, bg=0x555555772fbb, flag=TCOD_BKGND_NONE, align=TCOD_LEFT, can_split=0, 
    count_only=0) at ../../src/libtcod/console/printing.cpp:1128
#10 0x00007ffff7b544c6 in tcod::console::print (con=<optimized out>, con@entry=0x555555772fa0, x=<optimized out>, x@entry=2, y=y@entry=47, 
    str="\342\000 : select a sample", fg=fg@entry=0x555555772fb8, bg=bg@entry=0x555555772fbb, flag=TCOD_BKGND_NONE, alignment=TCOD_LEFT)
    at ../../src/libtcod/console/printing.cpp:1180
#11 0x00007ffff7b54d0c in TCOD_console_printf (con=<optimized out>, x=2, y=47, fmt=<optimized out>)
    at ../../src/libtcod/console/printing.cpp:1308
#12 0x000055555555793e in main ()

Note: Tested on Ubuntu 18.04 (0ea514f)

@HexDecimal
Copy link
Collaborator

I was able to reproduce and the fix the problem, there was a bad use of variable argument handling affecting the formatted print functions.

@MichaelMackus
Copy link
Contributor Author

Thanks all for your help 👍! Next time I'll try to be more helpful with my initial post.

On a side note, I did notice some segfaults due to running the samples from the wrong directory. The result (after running with debug CLI switch) was that the fonts weren't being loaded properly. This could perhaps be handled a little more clean, I'll try to open a PR to do some error checking when I get a chance.

@HexDecimal
Copy link
Collaborator

The font loading code is a mess. I can answer questions about it if you have any.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants