From 7dad68f869502e5c0ab32c12cbf8db866e020713 Mon Sep 17 00:00:00 2001 From: Jay Kwak <82421531+jkwak-work@users.noreply.github.com> Date: Wed, 11 Jun 2025 22:33:16 -0700 Subject: Fix intermittent debug failures with Debug build (#7369) This PR replaces enable/disable style C function calls with C++ RAII style code. In debug build, when an assertion failed in between enable and disable functions, an exception is thrown and the disable function is not called. RAII style code is safer for an exception --- source/slang/slang-ir-validate.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'source/slang/slang-ir-validate.cpp') diff --git a/source/slang/slang-ir-validate.cpp b/source/slang/slang-ir-validate.cpp index 565ae97d8..b3d6504ab 100644 --- a/source/slang/slang-ir-validate.cpp +++ b/source/slang/slang-ir-validate.cpp @@ -273,14 +273,19 @@ void validateIRInstOperands(IRValidateContext* context, IRInst* inst) } static thread_local bool _enableIRValidationAtInsert = false; -void disableIRValidationAtInsert() + +// RAII class implementation for exception-safe IR validation state management +IRValidationScope::IRValidationScope(bool enableValidation) + : m_previousState(_enableIRValidationAtInsert) { - _enableIRValidationAtInsert = false; + _enableIRValidationAtInsert = enableValidation; } -void enableIRValidationAtInsert() + +IRValidationScope::~IRValidationScope() { - _enableIRValidationAtInsert = true; + _enableIRValidationAtInsert = m_previousState; } + void validateIRInstOperands(IRInst* inst) { if (!_enableIRValidationAtInsert) -- cgit v1.2.3