Just including some vtk headers lead to "Exception: Numerical" in linux

Hi,

I’m compiling c++ code that use VTK.
The compilation goes fine but when I run tests (using Ctest), the executable that include VTK headers crash instantly even before the execution enter the main with : Exception: Numerical.

To narrow down the problem I cut the call to the methods that use VTK, same error.
I strip all the code from using VTK, only including headers but not using them : same error.
So I test to include only one header at a time to figure out which one cause the errors, turn out that any of the following ones cause the errors to appears :

#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkColorTransferFunction.h>
#include <vtkActor.h>
#include <vtkScalarBarActor.h>
#include <vtkGlyph3DMapper.h>

I tried running the executable with gdb which lead to more info :

Program received signal SIGFPE, Arithmetic exception.
0x0000563db23475c7 in std::__detail::_Mod_range_hashing::operator() (this=0x7ffd8c767237, __num=3849577002, __den=0) at /usr/include/c++/13.1.1/bits/hashtable_policy.h:524
524         { return __num % __den; }
(gdb) bt
#0  0x0000563db23475c7 in std::__detail::_Mod_range_hashing::operator() (this=0x7ffd8c767237, __num=3849577002, __den=0) at /usr/include/c++/13.1.1/bits/hashtable_policy.h:524
#1  0x0000563db2371c50 in std::__detail::_Hash_code_base<vtkStringToken, std::pair<vtkStringToken const, std::function<vtkSmartPointer<vtkCellMetadata> (vtkCellGrid*)> >, std::__detail::_Select1st, std::hash<vtkStringToken>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, true>::_M_bucket_index(unsigned long, unsigned long) const (this=0x563db3e370e0 <vtkCellMetadata::Constructors>, __c=3849577002, __bkt_count=0)
    at /usr/include/c++/13.1.1/bits/hashtable_policy.h:1341
#2  0x0000563db23716a3 in std::_Hashtable<vtkStringToken, std::pair<vtkStringToken const, std::function<vtkSmartPointer<vtkCellMetadata> (vtkCellGrid*)> >, std::allocator<std::pair<vtkStringToken const, std::function<vtkSmartPointer<vtkCellMetadata> (vtkCellGrid*)> > >, std::__detail::_Select1st, std::equal_to<vtkStringToken>, std::hash<vtkStringToken>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<true, false, true> >::_M_bucket_index(unsigned long) const (this=0x563db3e370e0 <vtkCellMetadata::Constructors>, __c=3849577002) at /usr/include/c++/13.1.1/bits/hashtable.h:797
#3  0x0000563db23711bc in std::_Hashtable<vtkStringToken, std::pair<vtkStringToken const, std::function<vtkSmartPointer<vtkCellMetadata> (vtkCellGrid*)> >, std::allocator<std::pair<vtkStringToken const, std::function<vtkSmartPointer<vtkCellMetadata> (vtkCellGrid*)> > >, std::__detail::_Select1st, std::equal_to<vtkStringToken>, std::hash<vtkStringToken>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<true, false, true> >::_M_emplace<std::pair<vtkStringToken, vtkCellMetadata::RegisterType<vtkDGHex>()::{lambda(vtkCellGrid*)#1}> >(std::integral_constant<bool, true>, std::pair<vtkStringToken, vtkCellMetadata::RegisterType<vtkDGHex>()::{lambda(vtkCellGrid*)#1}>&&) (this=0x563db3e370e0 <vtkCellMetadata::Constructors>) at /usr/include/c++/13.1.1/bits/hashtable.h:2083
#4  0x0000563db2370ec4 in std::_Hashtable<vtkStringToken, std::pair<vtkStringToken const, std::function<vtkSmartPointer<vtkCellMetadata> (vtkCellGrid*)> >, std::allocator<std::pair<vtkStringToken const, std::function<vtkSmartPointer<vtkCellMetadata> (vtkCellGrid*)> > >, std::__detail::_Select1st, std::equal_to<vtkStringToken>, std::hash<vtkStringToken>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<true, false, true> >::emplace<std::pair<vtkStringToken, vtkCellMetadata::RegisterType<vtkDGHex>()::{lambda(vtkCellGrid*)#1}> >(std::pair<vtkStringToken, vtkCellMetadata::RegisterType<vtkDGHex>()::{lambda(vtkCellGrid*)#1}>&&) (this=0x563db3e370e0 <vtkCellMetadata::Constructors>) at /usr/include/c++/13.1.1/bits/hashtable.h:961
#5  0x0000563db2370b94 in std::unordered_map<vtkStringToken, std::function<vtkSmartPointer<vtkCellMetadata> (vtkCellGrid*)>, std::hash<vtkStringToken>, std::equal_to<vtkStringToken>, std::allocator<std::pair<vtkStringToken const, std::function<vtkSmartPointer<vtkCellMetadata> (vtkCellGrid*)> > > >::insert<std::pair<vtkStringToken, vtkCellMetadata::RegisterType<vtkDGHex>()::{lambda(vtkCellGrid*)#1}> >(std::pair<vtkStringToken, vtkCellMetadata::RegisterType<vtkDGHex>()::{lambda(vtkCellGrid*)#1}>&&) (this=0x563db3e370e0 <vtkCellMetadata::Constructors>, __x=...) at /usr/include/c++/13.1.1/bits/unordered_map.h:571
#6  0x0000563db2370731 in vtkCellMetadata::RegisterType<vtkDGHex> () at /.../Common/DataModel/vtkCellMetadata.h:72
#7  0x0000563db236f924 in __static_initialization_and_destruction_0 () at /.../Filters/CellGrid/vtkDGHex.cxx:32
#8  0x0000563db2370469 in _GLOBAL__sub_I_vtkDGHex.cxx(void) () at /.../Filters/CellGrid/vtkDGHex.cxx:182
#9  0x00007f0de58a697e in __libc_start_main () from /usr/lib/libc.so.6
#10 0x0000563db229d1b5 in _start ()

I tried on another computer with a less recent gcc, version 8, same error.

As I can’t find any post related to that problem for VTK I suppose that the problem come from me not VTK, but I’m lost about where or what to search…

Hello,

Integer division by zero is the likely cause, despite what SIGFPE stands for. I suspect of { return __num % __den; } code. Something is passing a zero where not supposed to be. Which version of VTK are you using? Did you compile VTK yourself or used a package manager (e.g. yum)? If you used a package manager, did you install the correct devel package that matches your current VTK runtime?

take care,

Paulo

Lots of code may execute before main(). Constructors in code like class MyClass{...} myobject; declared outside a function execute before main(). Shared libraries may have their own “mains” and inits (DllMain() in Windows, for example) which also execute before main().

In this case, it looks like vtkDGHex.cxx has a global object that triggers it. @dcthomp

Hello,

Which version of VTK are you using? Did you compile VTK yourself or used a package manager (e.g. yum)? If you used a package manager, did you install the correct devel package that matches your current VTK runtime?

I compiled VTK myself, as a static lib, using the latest source version available on the main branch.

I will try to reproduce, but it has been working for me.

The string-hashing code looks like it is trying to use a modulus of zero somewhere, causing the exception.

As a temporary workaround, you might try disabling the FiltersCellGrid module in your build of VTK.

2 Likes

The workaround is working, thanks a lot :slight_smile: