AcademySoftwareFoundation / openvdb

OpenVDB - Sparse volume data structure and tools
http://www.openvdb.org/
Apache License 2.0
2.71k stars 660 forks source link

Fixed a crash on Android in the StreamState static instance constructor #1609

Closed jnkvca closed 1 year ago

jnkvca commented 1 year ago

I built OpenVDB for Android as a shared library and it seemed to crash every time when it was loaded. Further investigation showed that it crashes in the static initialization of the sStreamState instance. The class has a non-trivial constructor which makes calls to xalloc(), iword() and pword() as can be seen here. These functions crash on Android when called from static initializers when the library is being loaded.

The fix is to delay initialization of sStreamState object and do it from the openvdb::initialize() function.

linux-foundation-easycla[bot] commented 1 year ago

CLA Signed

The committers listed above are authorized under a signed CLA.

Idclip commented 1 year ago

Hey @jnkvca thanks a lot for highlighting this. Indeed we have a number of non-trivially constructable objects declared at file scope and thus suffer from SIOF (i.e. non-deterministic/compiler dependent construction order). I've incorporated your changes in a slightly different way and additionally fixed all remaining occurrences of such behavior (as well as enabling Clang's -Wglobal-constructors warning):

https://github.com/AcademySoftwareFoundation/openvdb/pull/1620

Let me know if this also looks like it would solve your issue

Idclip commented 1 year ago

This should now be fixed as part of https://github.com/AcademySoftwareFoundation/openvdb/pull/1620 - thanks again for highlighting this!