diff --git a/glslang/MachineIndependent/ShaderLang.cpp b/glslang/MachineIndependent/ShaderLang.cpp index ed40c366..a38e19db 100644 --- a/glslang/MachineIndependent/ShaderLang.cpp +++ b/glslang/MachineIndependent/ShaderLang.cpp @@ -1768,13 +1768,45 @@ TShader::TShader(EShLanguage s) environment.target.hlslFunctionality1 = false; } +// BEGIN @MEWIN - 2022-12-08 - Added code to allow moving TShaders (and storing them inside STL containers). +TShader::TShader(TShader&& other) +{ + (*this) = std::move(other); +} + +TShader& TShader::operator=(TShader&& other) +{ + if (this != &other) + { + pool = std::exchange(other.pool, nullptr); + stage = other.stage; + compiler = std::exchange(other.compiler, nullptr); + intermediate = std::exchange(other.intermediate, nullptr); + infoSink = std::exchange(other.infoSink, nullptr); + strings = other.strings; + lengths = other.lengths; + stringNames = other.stringNames; + numStrings = other.numStrings; + preamble = other.preamble; + sourceEntryPointName = other.sourceEntryPointName; + overrideVersion = other.overrideVersion; + environment = other.environment; + } + + return *this; +} + TShader::~TShader() { - delete infoSink; - delete compiler; - delete intermediate; - delete pool; + if (infoSink) + { + delete infoSink; + delete compiler; + delete intermediate; + delete pool; + } } +// END @MEWIN void TShader::setStrings(const char* const* s, int n) { diff --git a/glslang/Public/ShaderLang.h b/glslang/Public/ShaderLang.h index 90a5302a..e338c654 100644 --- a/glslang/Public/ShaderLang.h +++ b/glslang/Public/ShaderLang.h @@ -464,7 +464,14 @@ enum TBlockStorageClass class TShader { public: GLSLANG_EXPORT explicit TShader(EShLanguage); - GLSLANG_EXPORT virtual ~TShader(); + // BEGIN @MEWIN - 2022-12-08 - Added code to allow moving TShaders (and storing them inside STL containers). + GLSLANG_EXPORT TShader(const TShader&) = delete; + GLSLANG_EXPORT TShader(TShader&& other); + GLSLANG_EXPORT ~TShader(); + + GLSLANG_EXPORT TShader& operator=(const TShader&) = delete; + GLSLANG_EXPORT TShader& operator=(TShader&& other); + // END @MEWIN GLSLANG_EXPORT void setStrings(const char* const* s, int n); GLSLANG_EXPORT void setStringsWithLengths( const char* const* s, const int* l, int n);