From 2e3cb7f584dee5484e5ac01334879501d23e6c11 Mon Sep 17 00:00:00 2001 From: Howard Butler Date: Thu, 18 Oct 2012 10:22:45 -0500 Subject: [PATCH] provide getGDALEnvironment to wake up GDAL on-demand for things that need it while still preventing it from being tore down while others might still depend on it --- include/pdal/GlobalEnvironment.hpp | 5 ++++- src/GlobalEnvironment.cpp | 23 +++++++++++++++++------ src/filters/Colorization.cpp | 4 +++- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/include/pdal/GlobalEnvironment.hpp b/include/pdal/GlobalEnvironment.hpp index cdc4cb15aa..bad69e8490 100644 --- a/include/pdal/GlobalEnvironment.hpp +++ b/include/pdal/GlobalEnvironment.hpp @@ -65,6 +65,8 @@ class PDAL_DLL GlobalEnvironment // forwarded function boost::random::mt19937* getRNG(); + + void getGDALEnvironment(); private: GlobalEnvironment(); @@ -73,9 +75,10 @@ class PDAL_DLL GlobalEnvironment static void init(); typedef std::map thread_map; - thread_map m_threadMap; + thread_map m_threadMap; plang::PythonEnvironment* m_pythonEnvironment; + bool m_bIsGDALInitialized; GlobalEnvironment(const GlobalEnvironment&); // nope GlobalEnvironment& operator=(const GlobalEnvironment&); // nope diff --git a/src/GlobalEnvironment.cpp b/src/GlobalEnvironment.cpp index 69455e4d13..a3035b2c62 100644 --- a/src/GlobalEnvironment.cpp +++ b/src/GlobalEnvironment.cpp @@ -98,20 +98,27 @@ void GlobalEnvironment::init() // GlobalEnvironment::GlobalEnvironment() -#ifdef PDAL_HAVE_PYTHON : m_pythonEnvironment(0) -#endif +, m_bIsGDALInitialized(false) { // this should be the not-a-thread thread environment (void) createThreadEnvironment(boost::thread::id()); -#ifdef PDAL_HAVE_GDAL - (void) GDALAllRegister(); -#endif + return; } +void GlobalEnvironment::getGDALEnvironment() +{ +#ifdef PDAL_HAVE_GDAL + if (!m_bIsGDALInitialized) + { + (void) GDALAllRegister(); + m_bIsGDALInitialized = true; + } +#endif +} GlobalEnvironment::~GlobalEnvironment() { @@ -130,7 +137,11 @@ GlobalEnvironment::~GlobalEnvironment() #endif #ifdef PDAL_HAVE_GDAL - (void) GDALDestroyDriverManager(); + if (m_bIsGDALInitialized) + { + (void) GDALDestroyDriverManager(); + m_bIsGDALInitialized = false; + } #endif return; diff --git a/src/filters/Colorization.cpp b/src/filters/Colorization.cpp index f3a88fbe3c..92994d4e7f 100644 --- a/src/filters/Colorization.cpp +++ b/src/filters/Colorization.cpp @@ -39,6 +39,7 @@ #include #include +#include #ifdef PDAL_HAVE_GDAL #include @@ -93,7 +94,8 @@ void Colorization::initialize() collectOptions(); #ifdef PDAL_HAVE_GDAL - + + pdal::GlobalEnvironment::get().getGDALEnvironment(); m_gdal_debug = new pdal::gdal::Debug(isDebug(), log()); m_forward_transform.assign(0.0); m_inverse_transform.assign(0.0);