From a3dd78eb6ec0dc091d61a54a68cbf68c93104c7e Mon Sep 17 00:00:00 2001 From: Jonathan Laroche Date: Wed, 11 Dec 2024 19:22:34 -0500 Subject: [PATCH] Fix for bug in split string and move order of functions --- src/OpenColorIO/Config.cpp | 64 ++++++++++++++++++++++------------ src/OpenColorIO/ParseUtils.cpp | 4 +-- 2 files changed, 44 insertions(+), 24 deletions(-) diff --git a/src/OpenColorIO/Config.cpp b/src/OpenColorIO/Config.cpp index 5511699d2..d80c59367 100644 --- a/src/OpenColorIO/Config.cpp +++ b/src/OpenColorIO/Config.cpp @@ -4005,20 +4005,54 @@ const char * Config::getActiveDisplays() const return getImpl()->m_activeDisplaysStr.c_str(); } +void Config::addActiveDisplay(const char * view) +{ + if( !view || !view[0] ) + { + throw Exception("Active display could not be added to config, display name has to be a " + "non-empty name."); + } + + auto it = std::find(getImpl()->m_activeDisplays.begin(), + getImpl()->m_activeDisplays.end(), view); + + if( it != getImpl()->m_activeDisplays.end() ) + { + std::ostringstream os; + os << "Active display could not be added to config. An active display named '" + << view << "' already exists."; + throw Exception(os.str().c_str()); + } + + getImpl()->m_activeDisplays.push_back(view); + + getImpl()->m_displayCache.clear(); + + AutoMutex lock(getImpl()->m_cacheidMutex); + getImpl()->resetCacheIDs(); +} + void Config::removeActiveDisplay(const char * display) { if( !display || !display[0] ) { - throw Exception("Active display could not be removed from config, display name has to be a " - "non-empty name."); + throw Exception("Active display could not be removed from config, display name has to be a " + "non-empty name."); } auto it = std::find(getImpl()->m_activeDisplays.begin(), getImpl()->m_activeDisplays.end(), display); - if(it!=getImpl()->m_activeDisplays.end()) + if( it != getImpl()->m_activeDisplays.end() ) + { + getImpl()->m_activeDisplays.erase(it); + } + else { - getImpl()->m_activeDisplays.erase(it); + std::ostringstream os; + os << "Active display could not be removed from config. An active display named '" + << display << "' could be be found."; + throw Exception(os.str().c_str()); } getImpl()->m_displayCache.clear(); @@ -4039,7 +4073,8 @@ void Config::clearActiveDisplays() const char * Config::getActiveDisplay( int index ) const { - if( index<0 || index >= static_cast(getImpl()->m_activeDisplays.size())) + if( index<0 || + index >= static_cast(getImpl()->m_activeDisplays.size())) { return nullptr; } @@ -4052,22 +4087,6 @@ int Config::getNumActiveDisplays() const return static_cast(getImpl()->m_activeDisplays.size()); } -void Config::addActiveDisplay(const char * view) -{ - if( !view || !view[0] ) - { - throw Exception("Active view could not be added to config, view name has to be a " - "non-empty name."); - } - - getImpl()->m_activeDisplays.push_back(view); - - getImpl()->m_displayCache.clear(); - - AutoMutex lock(getImpl()->m_cacheidMutex); - getImpl()->resetCacheIDs(); -} - void Config::setActiveViews(const char * views) { getImpl()->m_activeViews.clear(); @@ -4132,7 +4151,8 @@ void Config::clearActiveViews() const char * Config::getActiveView( int index ) const { - if( index<0 || index >= static_cast(getImpl()->m_activeViews.size())) + if( index<0 || + index >= static_cast(getImpl()->m_activeViews.size())) { return nullptr; } diff --git a/src/OpenColorIO/ParseUtils.cpp b/src/OpenColorIO/ParseUtils.cpp index 94eb3854a..64d459a8f 100644 --- a/src/OpenColorIO/ParseUtils.cpp +++ b/src/OpenColorIO/ParseUtils.cpp @@ -741,7 +741,7 @@ StringUtils::StringVec SplitStringEnvStyle(const std::string & str) const std::string s = StringUtils::Trim(str); if( s.size() == 0 ) { - return {""}; + return {}; } StringUtils::StringVec outputvec; @@ -788,7 +788,7 @@ std::string JoinStringEnvStyle(const StringUtils::StringVec & outputvec) const int nElement = static_cast(outputvec.size()); if( nElement == 0 ) { - return ""; + return ""; } // We check if the value contains a symbol that could be interpreted as a separator