diff --git a/library/PolyVoxCore/include/PolyVoxCore/BaseVolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/BaseVolumeSampler.inl index 1e67a020..aabf0287 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/BaseVolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/BaseVolumeSampler.inl @@ -374,8 +374,8 @@ namespace PolyVox } default: { - //Should never happen - POLYVOX_THROW(std::invalid_argument, "Wrap mode parameter has an unrecognised value."); + //Should never happen. We don't log because this hurts performance (preventing inlining?). + POLYVOX_THROW_DONT_LOG(std::invalid_argument, "Wrap mode parameter has an unrecognised value."); } } } diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h index 847ae008..5080f7db 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h @@ -258,6 +258,12 @@ namespace PolyVox #define POLYVOX_THROW(type, message) \ PolyVox::logError() << (message); \ throw type((message)) + + // Some fast functions (getVoxel(), etc) use exceptions for error handling but don't want the overhead of logging. + // This overhead is present even if no exception is thrown, probably because the presence of the logging code prevents + // some inlining. Therefore we provide this macro which doesn't log for such specialised circumstances. + #define POLYVOX_THROW_DONT_LOG(type, message) \ + throw type((message)) #else namespace PolyVox { @@ -271,6 +277,13 @@ namespace PolyVox PolyVox::logError() << (message); \ type except = (type)((message)); \ getThrowHandler()((except), __FILE__, __LINE__) + + // Some fast functions (getVoxel(), etc) use exceptions for error handling but don't want the overhead of logging. + // This overhead is present even if no exception is thrown, probably because the presence of the logging code prevents + // some inlining. Therefore we provide this macro which doesn't log for such specialised circumstances. + #define POLYVOX_THROW_DONT_LOG(type, message) \ + type except = (type)((message)); \ + getThrowHandler()((except), __FILE__, __LINE__) #endif namespace PolyVox diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl index 0bc880ef..a0c778f6 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl @@ -241,8 +241,8 @@ namespace PolyVox } default: { - //Should never happen - POLYVOX_THROW(std::invalid_argument, "Wrap mode parameter has an unrecognised value."); + //Should never happen. We don't log because this hurts performance (preventing inlining?). + POLYVOX_THROW_DONT_LOG(std::invalid_argument, "Wrap mode parameter has an unrecognised value."); } } } diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl index 39e51690..5614650d 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl @@ -199,8 +199,8 @@ namespace PolyVox } default: { - //Should never happen - POLYVOX_THROW(std::invalid_argument, "Wrap mode parameter has an unrecognised value."); + //Should never happen. We don't log because this hurts performance (preventing inlining?). + POLYVOX_THROW_DONT_LOG(std::invalid_argument, "Wrap mode parameter has an unrecognised value."); } } } diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl index b17bf517..7f5ff9d6 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl @@ -199,8 +199,8 @@ namespace PolyVox } default: { - //Should never happen - POLYVOX_THROW(std::invalid_argument, "Wrap mode parameter has an unrecognised value."); + //Should never happen. We don't log because this hurts performance (preventing inlining?). + POLYVOX_THROW_DONT_LOG(std::invalid_argument, "Wrap mode parameter has an unrecognised value."); } } }