gazebosim / gazebosim/gz-rendering

Examples crashes when exiting with ESC

Open
#1,164 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
C++
Stars
81
Forks
90
Avg merge
1d 13h
Merged PRs (30d)
10

Description

## Environment
* OS Version: 24.04
* Source or binary build?
source build, gz-rendering10 branch

## Description
* Expected behavior: Example should exit normally when pressing `ESC`
* Actual behavior: Example exists with segmentation fault when pressing `ESC`

## Steps to reproduce
1. Build an example, e.g. [heightmap](https://github.com/gazebosim/gz-rendering/tree/gz-rendering10/examples/heightmap)

```
mkdir build
cd build
cmake ..
make -j 4
```

2. Run the example

```
./heightmap
```

3. Press `ESC` to exit and see the crash

## Output

Here's a backtrace:

```
Thread 1 "heightmap" received signal SIGSEGV, Segmentation fault.
0x0000555555560ce1 in std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release_last_use() ()
(gdb) bt
#0 0x0000555555560ce1 in std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release_last_use() ()
#1 0x000055555555fd8c in std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release_last_use_cold()
()
#2 0x000055555555f53d in std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release() ()
#3 0x000055555555fdfb in std::__shared_count<(__gnu_cxx::_Lock_policy)2>::~__shared_count() ()
#4 0x0000555555566ef2 in std::__shared_ptr::~__shared_ptr() ()
#5 0x0000555555566f12 in std::shared_ptr::~shared_ptr() ()
#6 0x00007ffff765da76 in __run_exit_handlers (status=0, listp=,
run_list_atexit=run_list_atexit@entry=true, run_dtors=run_dtors@entry=true) at ./stdlib/exit.c:108
#7 0x00007ffff765dbbe in __GI_exit (status=) at ./stdlib/exit.c:138
#8 0x0000555555566419 in keyboardCB(unsigned char, int, int) ()
#9 0x00007ffff7f13515 in fgPlatformProcessSingleEvent () from /lib/x86_64-linux-gnu/libglut.so.3.12
#10 0x00007ffff7f0c7e7 in glutMainLoopEvent () from /lib/x86_64-linux-gnu/libglut.so.3.12
#11 0x00007ffff7f0c97c in glutMainLoop () from /lib/x86_64-linux-gnu/libglut.so.3.12
#12 0x0000555555566876 in run(std::vector, std::allocator > >) ()
#13 0x000055555555ea2d in main ()
```

Note if I manually reset the ray query shared pointer (`g_rayQuery.reset`) before [exit](https://github.com/gazebosim/gz-rendering/blob/fde53a65311c9eeeba73d68fbbe0689aa41332a5/examples/heightmap/GlutWindow.cc#L272), the segfault goes away. We should handle this better than having to manually reset the pointer.

Contributor guide

Open the contributing guide

Research direction

Start with examples/heightmap/GlutWindow.cc, especially the ESC handling near the linked exit line, and reproduce the crash using the documented CMake build and ./heightmap steps. Trace the g_rayQuery lifetime shown in the backtrace and verify that pressing ESC exits without a segmentation fault, without requiring a manual reset at the call site.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
computer-graphics
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.