Skip to content

Commit 9e7cbe2

Browse files
committed
fix nullptr dereference bug in IShaderCompiler, add some comments to CHLSLCompiler
1 parent 1e48c59 commit 9e7cbe2

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

include/nbl/asset/utils/CHLSLCompiler.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class NBL_API2 CHLSLCompiler final : public IShaderCompiler
3232

3333
struct SOptions : IShaderCompiler::SCompilerOptions
3434
{
35-
std::span<const std::string> dxcOptions;
35+
std::span<const std::string> dxcOptions; // TODO: span is a VIEW to memory, so to something which we should treat immutable - why not span of string_view then? Since its span we force users to keep those std::strings alive anyway but now we cannnot even make nice constexpr & pass such expression here directly
3636
IShader::E_CONTENT_TYPE getCodeContentType() const override { return IShader::E_CONTENT_TYPE::ECT_HLSL; };
3737
};
3838

@@ -54,7 +54,7 @@ class NBL_API2 CHLSLCompiler final : public IShaderCompiler
5454
std::string preprocessShader(std::string&& code, IShader::E_SHADER_STAGE& stage, const SPreprocessorOptions& preprocessOptions, std::vector<std::string>& dxc_compile_flags_override, std::vector<CCache::SEntry::SPreprocessingDependency>* dependencies = nullptr) const;
5555

5656
void insertIntoStart(std::string& code, std::ostringstream&& ins) const override;
57-
constexpr static inline const wchar_t* RequiredArguments[] = {
57+
constexpr static inline const wchar_t* RequiredArguments[] = { // TODO: and if dxcOptions is span of std::string then why w_chars there? https://en.cppreference.com/w/cpp/string/basic_string
5858
L"-spirv",
5959
L"-Zpr",
6060
L"-enable-16bit-types",

include/nbl/asset/utils/IShaderCompiler.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,10 @@ class NBL_API2 IShaderCompiler : public core::IReferenceCounted
442442
return found;
443443
}
444444
auto retVal = compileToSPIRV_impl(code, options, options.writeCache ? &dependencies : nullptr);
445+
446+
if (!retVal)
447+
return nullptr;
448+
445449
// compute the SPIR-V shader content hash
446450
{
447451
auto backingBuffer = retVal->getContent();

0 commit comments

Comments
 (0)