KiCad PCB EDA Suite
Loading...
Searching...
No Matches
navlib_safe_init.h File Reference

Safe initialization wrapper for the 3Dconnexion navlib SDK. More...

#include <kicommon.h>
#include <functional>

Go to the source code of this file.

Functions

KICOMMON_API bool SafeNavlibInit (const std::function< void()> &aInitFunc)
 Attempt to run the given function, recovering from both C++ exceptions and abort() calls triggered by buggy third-party drivers.
 
KICOMMON_API bool NavlibDriverCrashed ()
 Returns true if a previous SafeNavlibInit call detected a driver crash.
 

Detailed Description

Safe initialization wrapper for the 3Dconnexion navlib SDK.

The 3Dconnexion driver on some macOS versions calls std::terminate() during initialization (NlCreate), which cannot be caught by normal C++ exception handling. This wrapper installs a temporary SIGABRT handler to recover from the abort() that std::terminate() triggers.

Definition in file navlib_safe_init.h.

Function Documentation

◆ NavlibDriverCrashed()

KICOMMON_API bool NavlibDriverCrashed ( )

Returns true if a previous SafeNavlibInit call detected a driver crash.

Once the driver is known to be broken, all future SafeNavlibInit calls return false immediately without attempting initialization.

Definition at line 133 of file navlib_safe_init.cpp.

References s_driverCrashed().

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), NL_3D_VIEWER_PLUGIN::NL_3D_VIEWER_PLUGIN(), NL_FOOTPRINT_PROPERTIES_PLUGIN::NL_FOOTPRINT_PROPERTIES_PLUGIN(), NL_GERBVIEW_PLUGIN::NL_GERBVIEW_PLUGIN(), NL_PCBNEW_PLUGIN::NL_PCBNEW_PLUGIN(), NL_PL_EDITOR_PLUGIN::NL_PL_EDITOR_PLUGIN(), and NL_SCHEMATIC_PLUGIN::NL_SCHEMATIC_PLUGIN().

◆ SafeNavlibInit()

KICOMMON_API bool SafeNavlibInit ( const std::function< void()> & aInitFunc)

Attempt to run the given function, recovering from both C++ exceptions and abort() calls triggered by buggy third-party drivers.

On macOS, temporarily installs a SIGABRT handler that uses siglongjmp to recover from abort(). On other platforms, wraps the call in a try/catch.

Parameters
aInitFuncthe initialization function to call
Returns
true if the function completed without error, false otherwise

Definition at line 52 of file navlib_safe_init.cpp.

References navlibSigAbrtHandler(), s_driverCrashed(), s_initMutex, s_jumpBuffer, and s_savedSigAbrtAction.

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), NL_3D_VIEWER_PLUGIN_IMPL::Connect(), NL_PCBNEW_PLUGIN_IMPL::NL_PCBNEW_PLUGIN_IMPL(), NL_GERBVIEW_PLUGIN_IMPL::SetCanvas(), NL_PL_EDITOR_PLUGIN_IMPL::SetCanvas(), and NL_SCHEMATIC_PLUGIN_IMPL::SetCanvas().