From 63bed4c37199f2436c81089a08834d7b58b8e576 Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Thu, 9 Jan 2020 11:26:06 -0800 Subject: Catch exceptions inside FindTypeByName() If `spReflection_FindTypeByName` is called with a string that refers to the name of a variable instead of a type, then it ends up causing a fatal error to be diagnosed, leading to an `AbortCompilationException` being thrown. This exception then propagates up to the application that called `spReflection_FindTypeByName()`, which actually violates the contract for our `extern "C"` API. This change adds a wrapper `try`/`catch` around the meat of the operation and turns any exception into a null result (this function has no other way to report errors to the caller). It would be nice for a separate change to make the error message that caused the problem non-fatal, but that is orthogonal to this fix. --- source/slang/slang-reflection.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'source') diff --git a/source/slang/slang-reflection.cpp b/source/slang/slang-reflection.cpp index c0c5bd72f..037bc2d97 100644 --- a/source/slang/slang-reflection.cpp +++ b/source/slang/slang-reflection.cpp @@ -598,8 +598,15 @@ SLANG_API SlangReflectionType * spReflection_FindTypeByName(SlangReflection * re Slang::DiagnosticSink sink( programLayout->getTargetReq()->getLinkage()->getSourceManager()); - RefPtr result = program->getTypeFromString(name, &sink); - return (SlangReflectionType*)result.Ptr(); + try + { + RefPtr result = program->getTypeFromString(name, &sink); + return (SlangReflectionType*)result.Ptr(); + } + catch( ... ) + { + return nullptr; + } } SLANG_API SlangReflectionTypeLayout* spReflection_GetTypeLayout( -- cgit v1.2.3