From a18dca27392b257ba2cc58ceabdf15471f34ee25 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Tue, 26 Sep 2023 15:40:22 -0400 Subject: Fix for epoch/ASTBuilder* nullptr issue (#3240) * Fix issue with failing tests tests/serialization/serialized-module-test.slang tests/serialization/extern/extern-test.slang * Fix issue with session destruction order on Session. * Improve comment. --- source/slang/slang.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'source/slang/slang.cpp') diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index 38ebcccd6..46ccb6ce9 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -4726,6 +4726,13 @@ void Session::addBuiltinSource( Session::~Session() { + // This is necessary because this ASTBuilder uses the SharedASTBuilder also owned by the session. + // If the SharedASTBuilder gets dtored before the globalASTBuilder it has a dangling pointer, which + // is referenced in the ASTBuilder dtor (likely) causing a crash. + // + // By destroying first we know it is destroyed, before the SharedASTBuilder. + globalAstBuilder.setNull(); + // destroy modules next stdlibModules = decltype(stdlibModules)(); } -- cgit v1.2.3