1919
2020namespace mx = MaterialX;
2121
22+ namespace
23+ {
24+
25+ // RAII helper that invokes a callable on scope exit (normal or exception).
26+ template <typename F>
27+ class ScopeGuard
28+ {
29+ public:
30+ explicit ScopeGuard (F fn) : _fn(std::move(fn)) {}
31+ ~ScopeGuard () { _fn (); }
32+
33+ ScopeGuard (const ScopeGuard&) = delete ;
34+ ScopeGuard& operator =(const ScopeGuard&) = delete ;
35+
36+ private:
37+ F _fn;
38+ };
39+
40+ } // anonymous namespace
41+
2242namespace RenderUtil
2343{
2444
@@ -45,6 +65,15 @@ bool ShaderRenderTester::validate(const mx::FilePath optionsFilePath)
4565 _logger.start (target, _testRun.options );
4666 _profiler.start ();
4767
68+ // Ensure cleanup on any exit path (normal return or exception).
69+ ScopeGuard cleanup ([this ]() {
70+ _profiler.end (_testRun.options , _logger.profilingLog (), _testRun.dependLib );
71+ _logger.end ();
72+ #ifdef MATERIALX_BUILD_PERFETTO_TRACING
73+ _tracer.end ();
74+ #endif
75+ });
76+
4877 // Data search path
4978 _testRun.searchPath = mx::getDefaultDataSearchPath ();
5079
@@ -81,12 +110,6 @@ bool ShaderRenderTester::validate(const mx::FilePath optionsFilePath)
81110 }
82111 }
83112
84- _profiler.end (_testRun.options , _logger.profilingLog (), _testRun.dependLib );
85- _logger.end ();
86- #ifdef MATERIALX_BUILD_PERFETTO_TRACING
87- _tracer.end ();
88- #endif
89-
90113 return true ;
91114}
92115
@@ -105,7 +128,7 @@ void ShaderRenderTester::loadDependentLibraries()
105128 }
106129 }
107130
108- // Load any addition per renderer libraries
131+ // Load any additional per- renderer libraries
109132 loadAdditionalLibraries (_testRun.dependLib , _testRun.options );
110133}
111134
@@ -131,17 +154,6 @@ void ShaderRenderTester::getGenerationOptions(const GenShaderUtil::TestSuiteOpti
131154 }
132155}
133156
134- void ShaderRenderTester::printRunLog (const RenderProfileTimes &profileTimes,
135- const GenShaderUtil::TestSuiteOptions& options,
136- std::ostream& stream,
137- mx::DocumentPtr)
138- {
139- profileTimes.print (stream);
140-
141- stream << " ---------------------------------------" << std::endl;
142- options.print (stream);
143- }
144-
145157void ShaderRenderTester::addAdditionalTestStreams (mx::MeshPtr mesh)
146158{
147159 size_t vertexCount = mesh->getVertexCount ();
0 commit comments