Skip to content

Add a Schwarz counter for token singletons

David Gobbi requested to merge dgobbi/vtk:token-schwarz into master

If we use a Schwarz counter to initialize/cleanup the token singletons, we can ensure that the vtkFilteringInformationKeyManager cleanup always occurs before the singletons cleanup by including "token/Singletons.h" in vtkFilteringInformationKeyManager.h.

See utils/token!23 (merged) for the proposed changes to the token repository.

Pedantic notes: This fix is modelled on the Schwarz counter in Common/Core/vtkDebugLeaksManager.cxx. The comments in that source file mention that MSVC has a bug in its global optimizer (not used in typical cmake-based VTK builds) that can break the Schwarz counter idiom. That bug has been fixed in Visual Studio 2022, and is unlikely to be encountered in typical VTK builds anyway, so I'd rather not implement the work-around given in vtkDebugLeaksManager.cxx.

This fixes a static build issue on macOS, where programs built against VTK would raise an exception on exit because destruction of static variables wasn't occurring in the correct order (see !11392#note_1585339).

Backport: release

Edited by David Gobbi

Merge request reports

Loading