guillaumeblanc / ozz-animation

Open source c++ skeletal animation library and toolset
http://guillaumeblanc.github.io/ozz-animation/
Other
2.46k stars 302 forks source link

Segmentation Fault creating a RawSkeleton on Linux, works on other platforms #120

Closed Ravbug closed 3 years ago

Ravbug commented 3 years ago

On GCC 10.2.1 and Clang 10.0.1 on Linux, executing the following code results in a segmentation fault:

ozz::animation::offline::RawSkeleton raw_skeleton;
raw_skeleton.roots.resize(1);                                      // crash here

This code works correctly on macOS, iOS, and tvOS with Apple Clang and Windows with MSVC.

Linux stack trace in gdb:

0x000000000051b35f in ozz::StdAllocator<ozz::animation::offline::RawSkeleton::Joint>::construct<ozz::animation::offline::RawSkeleton::Joint> (this=0x7fffffffc980, _ptr=0x0) at ../RavEngine/deps/ozz-animation/include/ozz/base/containers/std_allocator.h:64
64      ::new (static_cast<void*>(_ptr)) _Other(std::forward<_Args>(_args)...);
(gdb) list
59    pointer address(reference _ref) const noexcept { return &_ref; }
60    const_pointer address(const_reference _ref) const noexcept { return &_ref; }
61  
62    template <class _Other, class... _Args>
63    void construct(_Other* _ptr, _Args&&... _args) {
64      ::new (static_cast<void*>(_ptr)) _Other(std::forward<_Args>(_args)...);
65    }
66  
67    template <class _Other>
68    void destroy(_Other* _ptr) {
(gdb) backtrace
#0  0x000000000051b35f in ozz::StdAllocator<ozz::animation::offline::RawSkeleton::Joint>::construct<ozz::animation::offline::RawSkeleton::Joint> (
    this=0x7fffffffc980, _ptr=0x0) at ../RavEngine/deps/ozz-animation/include/ozz/base/containers/std_allocator.h:64
#1  0x000000000051aa15 in std::allocator_traits<ozz::StdAllocator<ozz::animation::offline::RawSkeleton::Joint> >::_S_construct<ozz::animation::offline::RawSkeleton::Joint> (__a=..., __p=0x0) at /usr/include/c++/10/bits/alloc_traits.h:247
#2  0x0000000000519f57 in std::allocator_traits<ozz::StdAllocator<ozz::animation::offline::RawSkeleton::Joint> >::construct<ozz::animation::offline::RawSkeleton::Joint> (__a=..., __p=0x0) at /usr/include/c++/10/bits/alloc_traits.h:360
#3  0x00000000005191f2 in std::__uninitialized_default_n_a<ozz::animation::offline::RawSkeleton::Joint*, unsigned long, ozz::StdAllocator<ozz::animation::offline::RawSkeleton::Joint> > (__first=0x0, __n=1, __alloc=...) at /usr/include/c++/10/bits/stl_uninitialized.h:671
#4  0x000000000051655d in std::vector<ozz::animation::offline::RawSkeleton::Joint, ozz::StdAllocator<ozz::animation::offline::RawSkeleton::Joint> >::_M_default_append (this=0x7fffffffc980, __n=1) at /usr/include/c++/10/bits/vector.tcc:627
#5  0x0000000000515b11 in std::vector<ozz::animation::offline::RawSkeleton::Joint, ozz::StdAllocator<ozz::animation::offline::RawSkeleton::Joint> >::resize (
    this=0x7fffffffc980, __new_size=1) at /usr/include/c++/10/bits/stl_vector.h:940

Printing out the value of raw_skeleton with gdb results in $1 = {roots = std::vector of length 0, capacity 1465970764458}, so maybe the RawSkeleton was not properly initialized in the allocator?

guillaumeblanc commented 3 years ago

Hi,

this seems pretty similar to #111 (prebuilt packages vs _GLIBCXX_DEBUG flag), have you checked already ?

Guillaume

Ravbug commented 3 years ago

Disabling line 102 of compiler_settings.cmake fixed it on Linux, thanks!

# disable this line:
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS "$<$<CONFIG:Debug>:_GLIBCXX_DEBUG>")