Creating shared_ptr seems to cause segfault

I have the following function

static node_ptr make_node_ptr()
  return node_ptr(new node());

where using node_ptr = std::shared_ptr<node>;

I tried to find my segmentation fault with valgrind and gdb. In both I get more or less the same stack trace.

Program received signal SIGSEGV, Segmentation fault.
0x00007fff8f5d7e82 in szone_malloc_should_clear () from /usr/lib/system/libsystem_malloc.dylib
(gdb) bt
#0  0x00007fff8f5d7e82 in szone_malloc_should_clear () from /usr/lib/system/libsystem_malloc.dylib
#1  0x00007fff8f5d7877 in malloc_zone_malloc () from /usr/lib/system/libsystem_malloc.dylib
#2  0x00007fff8f5d6395 in malloc () from /usr/lib/system/libsystem_malloc.dylib
#3  0x00000001000f17d8 in operator new(unsigned long) () from /usr/local/lib/gcc/4.9/libstdc++.6.dylib
#4  0x0000000100009c04 in std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count<msc::scene_manager<float, int, 3ul>::node*> (this=0x7fff5f4002e8, __p=0x10059ffc0)
    at /usr/local/Cellar/gcc49/4.9.2_1/include/c++/4.9.2/bits/shared_ptr_base.h:569
#5  0x0000000100008c78 in std::__shared_ptr<msc::scene_manager<float, int, 3ul>::node, (__gnu_cxx::_Lock_policy)2>::__shared_ptr<msc::scene_manager<float, int, 3ul>::node> (this=0x7fff5f4002e0, __p=0x10059ffc0)
    at /usr/local/Cellar/gcc49/4.9.2_1/include/c++/4.9.2/bits/shared_ptr_base.h:871
#6  0x00000001000079e5 in std::shared_ptr<msc::scene_manager<float, int, 3ul>::node>::shared_ptr<msc::scene_manager<float, int, 3ul>::node> (this=0x7fff5f4002e0, __p=0x10059ffc0)
    at /usr/local/Cellar/gcc49/4.9.2_1/include/c++/4.9.2/bits/shared_ptr.h:113
#7  0x0000000100005bdc in msc::scene_manager<float, int, 3ul>::make_node_ptr () at ../../common/msc/scene.d/scene_manager_def.h:98
#8  0x00000001000037dd in msc::scene_manager<float, int, 3ul>::node::generate_wrapping_node (wrappee=...) at ../../common/msc/scene.d/node_impl.h:73
#9  0x0000000100003d53 in msc::scene_manager<float, int, 3ul>::node::generate_wrapping_node (nodes=...) at ../../common/msc/scene.d/node_impl.h:112
#10 0x0000000100004011 in msc::scene_manager<float, int, 3ul>::insert (this=0x7fff5f82ee90, root=..., other=...) at ../../common/msc/scene.d/scene_manager_impl.h:97
#11 0x0000000100006071 in msc::scene_manager<float, int, 3ul>::insert_if_leq (this=0x7fff5f82ee90, root=..., other=...) at ../../common/msc/scene.d/scene_manager_impl.h:127

The last 2 lines repeat endlessly, I guess at least, as I tried to continue until frame #6000 or smth.

Am I missing something or is the creation of this shared_ptr not allowed?


node_ptr scene_manager::insert(node_ptr & root, node_ptr other)
  bool swapped = false;

  if (root == nullptr)
    root = other;
    auto inside = msc::inside::test(*root, *other);
    if (inside == msc::inside::NONE)
      auto oldRoot = root;
      root = node::generate_wrapping_node(
        std::vector<node_c_ptr>{ oldRoot, other });
      insert_if_leq(root, oldRoot);
    else if ((swapped = (inside == msc::inside::FIRST)))
      std::swap(root, other);
    other = insert_if_leq(root, other);

  return !swapped ? other : root;

node_ptr scene_manager::insert_if_leq(node_ptr root, node_ptr other)
  node_ptr res = root;

  if (are_similar(*root, *other))
    msc::move_append(root->children, other->children);
    auto idx = root->get_quadrant_idx(other->center);
    res = insert(root->quadrants[idx], other);

  return res;

These are the functions which repeat. msc is my own namespace.

Source: New Questions

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.