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

**URL:** https://discourse.vtk.org/t/just-including-some-vtk-headers-lead-to-exception-numerical-in-linux/11733
**Category:** Support
**Created:** [June 15, 2023, 2:04pm UTC](https://discourse.vtk.org/t/just-including-some-vtk-headers-lead-to-exception-numerical-in-linux/11733 "2023-06-15T14:04:21Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![segretar](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/s/cdc98d/32.png) [@segretar](https://discourse.vtk.org/u/segretar)
#### Post date: [June 15, 2023, 2:04pm UTC](https://discourse.vtk.org/t/just-including-some-vtk-headers-lead-to-exception-numerical-in-linux/11733/1 "2023-06-15T14:04:21Z")

</div>

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 :

```auto
#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 :

```auto
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…

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [June 16, 2023, 6:32pm UTC](https://discourse.vtk.org/t/just-including-some-vtk-headers-lead-to-exception-numerical-in-linux/11733/2 "2023-06-16T18:32:10Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [June 16, 2023, 6:40pm UTC](https://discourse.vtk.org/t/just-including-some-vtk-headers-lead-to-exception-numerical-in-linux/11733/3 "2023-06-16T18:40:24Z")

</div>

> [@segretar](#):
>
> crash instantly even before the execution enter the main

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()`.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [June 18, 2023, 1:46pm UTC](https://discourse.vtk.org/t/just-including-some-vtk-headers-lead-to-exception-numerical-in-linux/11733/4 "2023-06-18T13:46:41Z")

</div>

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

---

<div class="post-metadata">

### Author: ![segretar](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/s/cdc98d/32.png) [@segretar](https://discourse.vtk.org/u/segretar)
#### Post date: [June 19, 2023, 8:02am UTC](https://discourse.vtk.org/t/just-including-some-vtk-headers-lead-to-exception-numerical-in-linux/11733/5 "2023-06-19T08:02:30Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![dcthomp](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dcthomp/32/60_2.png) [@dcthomp](https://discourse.vtk.org/u/dcthomp)
#### Post date: [June 19, 2023, 1:04pm UTC](https://discourse.vtk.org/t/just-including-some-vtk-headers-lead-to-exception-numerical-in-linux/11733/6 "2023-06-19T13:04:44Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![segretar](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/s/cdc98d/32.png) [@segretar](https://discourse.vtk.org/u/segretar)
#### Post date: [June 19, 2023, 3:34pm UTC](https://discourse.vtk.org/t/just-including-some-vtk-headers-lead-to-exception-numerical-in-linux/11733/7 "2023-06-19T15:34:16Z")

</div>

The workaround is working, thanks a lot 🙂
