EmptyEpsilon icon indicating copy to clipboard operation
EmptyEpsilon copied to clipboard

segfault on science screen

Open Chasethechicken opened this issue 2 years ago • 2 comments

EmptyEpsilon sometimes randomly crashes, when the science or operations screens are open. I compiled from master (commit 61f8666) on Fedora 36.

Running using valgrind gives:

==37468== Invalid read of size 8
==37468==    at 0x5693DC: GuiRadarView::drawObjects(sp::RenderTarget&) (in /usr/local/bin/EmptyEpsilon)
==37468==    by 0x56DABD: GuiRadarView::onDraw(sp::RenderTarget&) (in /usr/local/bin/EmptyEpsilon)
==37468==    by 0x59747F: GuiContainer::drawElements(glm::vec<2, float, (glm::qualifier)0>, sp::Rect, sp::RenderTarget&) (in /usr/local/bin/EmptyEpsilon)
==37468==    by 0x59749B: GuiContainer::drawElements(glm::vec<2, float, (glm::qualifier)0>, sp::Rect, sp::RenderTarget&) (in /usr/local/bin/EmptyEpsilon)
==37468==    by 0x59749B: GuiContainer::drawElements(glm::vec<2, float, (glm::qualifier)0>, sp::Rect, sp::RenderTarget&) (in /usr/local/bin/EmptyEpsilon)
==37468==    by 0x59749B: GuiContainer::drawElements(glm::vec<2, float, (glm::qualifier)0>, sp::Rect, sp::RenderTarget&) (in /usr/local/bin/EmptyEpsilon)
==37468==    by 0x59749B: GuiContainer::drawElements(glm::vec<2, float, (glm::qualifier)0>, sp::Rect, sp::RenderTarget&) (in /usr/local/bin/EmptyEpsilon)
==37468==    by 0x58C314: GuiCanvas::render(sp::RenderTarget&) (in /usr/local/bin/EmptyEpsilon)
==37468==    by 0x66A38E: RenderLayer::render(sp::RenderTarget&) (in /usr/local/bin/EmptyEpsilon)
==37468==    by 0x66A313: RenderLayer::render(sp::RenderTarget&) (in /usr/local/bin/EmptyEpsilon)
==37468==    by 0x64A1D5: Engine::runMainLoop() (in /usr/local/bin/EmptyEpsilon)
==37468==    by 0x461C47: main (in /usr/local/bin/EmptyEpsilon)
==37468==  Address 0xb2507d8 is 8 bytes before a block of size 4,800 alloc'd
==37468==    at 0x4844FF5: operator new(unsigned long) (vg_replace_malloc.c:422)
==37468==    by 0x569316: GuiRadarView::drawObjects(sp::RenderTarget&) (in /usr/local/bin/EmptyEpsilon)
==37468==    by 0x56DABD: GuiRadarView::onDraw(sp::RenderTarget&) (in /usr/local/bin/EmptyEpsilon)
==37468==    by 0x59747F: GuiContainer::drawElements(glm::vec<2, float, (glm::qualifier)0>, sp::Rect, sp::RenderTarget&) (in /usr/local/bin/EmptyEpsilon)
==37468==    by 0x59749B: GuiContainer::drawElements(glm::vec<2, float, (glm::qualifier)0>, sp::Rect, sp::RenderTarget&) (in /usr/local/bin/EmptyEpsilon)
==37468==    by 0x59749B: GuiContainer::drawElements(glm::vec<2, float, (glm::qualifier)0>, sp::Rect, sp::RenderTarget&) (in /usr/local/bin/EmptyEpsilon)
==37468==    by 0x59749B: GuiContainer::drawElements(glm::vec<2, float, (glm::qualifier)0>, sp::Rect, sp::RenderTarget&) (in /usr/local/bin/EmptyEpsilon)
==37468==    by 0x59749B: GuiContainer::drawElements(glm::vec<2, float, (glm::qualifier)0>, sp::Rect, sp::RenderTarget&) (in /usr/local/bin/EmptyEpsilon)
==37468==    by 0x58C314: GuiCanvas::render(sp::RenderTarget&) (in /usr/local/bin/EmptyEpsilon)
==37468==    by 0x66A38E: RenderLayer::render(sp::RenderTarget&) (in /usr/local/bin/EmptyEpsilon)
==37468==    by 0x66A313: RenderLayer::render(sp::RenderTarget&) (in /usr/local/bin/EmptyEpsilon)
==37468==    by 0x64A1D5: Engine::runMainLoop() (in /usr/local/bin/EmptyEpsilon)
==37468==
==37468== Invalid read of size 8
==37468==    at 0x5693E2: GuiRadarView::drawObjects(sp::RenderTarget&) (in /usr/local/bin/EmptyEpsilon)
==37468==    by 0x56DABD: GuiRadarView::onDraw(sp::RenderTarget&) (in /usr/local/bin/EmptyEpsilon)
==37468==    by 0x59747F: GuiContainer::drawElements(glm::vec<2, float, (glm::qualifier)0>, sp::Rect, sp::RenderTarget&) (in /usr/local/bin/EmptyEpsilon)
==37468==    by 0x59749B: GuiContainer::drawElements(glm::vec<2, float, (glm::qualifier)0>, sp::Rect, sp::RenderTarget&) (in /usr/local/bin/EmptyEpsilon)
==37468==    by 0x59749B: GuiContainer::drawElements(glm::vec<2, float, (glm::qualifier)0>, sp::Rect, sp::RenderTarget&) (in /usr/local/bin/EmptyEpsilon)
==37468==    by 0x59749B: GuiContainer::drawElements(glm::vec<2, float, (glm::qualifier)0>, sp::Rect, sp::RenderTarget&) (in /usr/local/bin/EmptyEpsilon)
==37468==    by 0x59749B: GuiContainer::drawElements(glm::vec<2, float, (glm::qualifier)0>, sp::Rect, sp::RenderTarget&) (in /usr/local/bin/EmptyEpsilon)
==37468==    by 0x58C314: GuiCanvas::render(sp::RenderTarget&) (in /usr/local/bin/EmptyEpsilon)
==37468==    by 0x66A38E: RenderLayer::render(sp::RenderTarget&) (in /usr/local/bin/EmptyEpsilon)
==37468==    by 0x66A313: RenderLayer::render(sp::RenderTarget&) (in /usr/local/bin/EmptyEpsilon)
==37468==    by 0x64A1D5: Engine::runMainLoop() (in /usr/local/bin/EmptyEpsilon)
==37468==    by 0x461C47: main (in /usr/local/bin/EmptyEpsilon)
==37468==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
==37468==
==37468==
==37468== Process terminating with default action of signal 11 (SIGSEGV): dumping core
==37468==  Access not within mapped region at address 0x0
==37468==    at 0x5693E2: GuiRadarView::drawObjects(sp::RenderTarget&) (in /usr/local/bin/EmptyEpsilon)
==37468==    by 0x56DABD: GuiRadarView::onDraw(sp::RenderTarget&) (in /usr/local/bin/EmptyEpsilon)
==37468==    by 0x59747F: GuiContainer::drawElements(glm::vec<2, float, (glm::qualifier)0>, sp::Rect, sp::RenderTarget&) (in /usr/local/bin/EmptyEpsilon)
==37468==    by 0x59749B: GuiContainer::drawElements(glm::vec<2, float, (glm::qualifier)0>, sp::Rect, sp::RenderTarget&) (in /usr/local/bin/EmptyEpsilon)
==37468==    by 0x59749B: GuiContainer::drawElements(glm::vec<2, float, (glm::qualifier)0>, sp::Rect, sp::RenderTarget&) (in /usr/local/bin/EmptyEpsilon)
==37468==    by 0x59749B: GuiContainer::drawElements(glm::vec<2, float, (glm::qualifier)0>, sp::Rect, sp::RenderTarget&) (in /usr/local/bin/EmptyEpsilon)
==37468==    by 0x59749B: GuiContainer::drawElements(glm::vec<2, float, (glm::qualifier)0>, sp::Rect, sp::RenderTarget&) (in /usr/local/bin/EmptyEpsilon)
==37468==    by 0x58C314: GuiCanvas::render(sp::RenderTarget&) (in /usr/local/bin/EmptyEpsilon)
==37468==    by 0x66A38E: RenderLayer::render(sp::RenderTarget&) (in /usr/local/bin/EmptyEpsilon)
==37468==    by 0x66A313: RenderLayer::render(sp::RenderTarget&) (in /usr/local/bin/EmptyEpsilon)
==37468==    by 0x64A1D5: Engine::runMainLoop() (in /usr/local/bin/EmptyEpsilon)
==37468==    by 0x461C47: main (in /usr/local/bin/EmptyEpsilon)
==37468==  If you believe this happened as a result of a stack
==37468==  overflow in your program's main thread (unlikely but
==37468==  possible), you can try to increase the size of the
==37468==  main thread stack using the --main-stacksize= flag.
==37468==  The main thread stack size used in this run was 8388608.
==37468==
==37468== HEAP SUMMARY:
==37468==     in use at exit: 12,376,652 bytes in 67,728 blocks
==37468==   total heap usage: 450,154 allocs, 382,426 frees, 144,550,762 bytes allocated
==37468==
==37468== LEAK SUMMARY:
==37468==    definitely lost: 0 bytes in 0 blocks
==37468==    indirectly lost: 0 bytes in 0 blocks
==37468==      possibly lost: 6,130,032 bytes in 43,153 blocks
==37468==    still reachable: 6,246,620 bytes in 24,575 blocks
==37468==         suppressed: 0 bytes in 0 blocks
==37468== Rerun with --leak-check=full to see details of leaked memory
==37468==
==37468== For lists of detected and suppressed errors, rerun with: -s
==37468== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)

Chasethechicken avatar Aug 22 '22 21:08 Chasethechicken

may be related to #1763

Piglit avatar Sep 06 '22 12:09 Piglit

Debugging reveals the source of the SEGFAULT in screenComponents/radarView.cpp:656 It happens in the compare lambda function of std::sort, where rhs gets some invalid value. However objects_to_draw looks fine to me. I have no clue, where this invalid value comes from.

(gdb) p objects_to_draw
$67 = std::vector of length 17, capacity 17 = {0x555557459870, 0x555557459870, 
  0x5555575e9cb0, 0x5555575e9f40, 0x5555575ea210, 0x55555752e860, 0x55555752eb30, 
  0x55555752f210, 0x55555752f8f0, 0x555557765d30, 0x5555577664a0, 0x555557766c10, 
  0x555557767590, 0x555557767d00, 0x555557768470, 0x555557768be0, 0x55555777efd0}
(gdb) s
operator()<SpaceObject*, SpaceObject*> (__closure=0x7fffffff9b77, 
    lhs=@0x7fffffff9b88: 0x5555574657c0, rhs=@0x555557978808: 0x91)
    at /home/oren/EmptyEpsilon/src/screenComponents/radarView.cpp:656
656	        const auto rhsLayer = rhs->getRadarLayer();
(gdb) s 
Thread 1 "EmptyEpsilon" received signal SIGSEGV, Segmentation fault.
0x000055555579b420 in operator()<SpaceObject*, SpaceObject*> (__closure=0x7fffffff9b77, 
    lhs=@0x7fffffff9b88: 0x5555574657c0, rhs=@0x555557978808: 0x91)
    at /home/oren/EmptyEpsilon/src/screenComponents/radarView.cpp:656
656	        const auto rhsLayer = rhs->getRadarLayer();

Piglit avatar Sep 15 '22 15:09 Piglit

Ok, I think I see why that fix fixes it. I'm using std::sort: https://en.cppreference.com/w/cpp/algorithm/sort Which specifies that the elements need to have the Compare requirement: https://en.cppreference.com/w/cpp/named_req/Compare

Which in turn, says that: If comp(a,b)==true then comp(b,a)==false and I think the old code did not satisfy that condition in all cases. And apperently, certain implementations of std::sort then just crash instead of producing bogus results.

daid avatar Sep 16 '22 13:09 daid