Skip to content

Commit 3a34db6

Browse files
authored
Test if blob is returned. (shader-slang#1535)
1 parent 8740252 commit 3a34db6

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed

source/slang/slang-compiler.cpp

+13-4
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,17 @@ namespace Slang
122122
{
123123
switch(format)
124124
{
125-
case ResultFormat::None:
126125
default:
127-
break;
128-
126+
case ResultFormat::None:
127+
{
128+
// If no blob is returned, it's an error
129+
return SLANG_FAIL;
130+
}
129131
case ResultFormat::Text:
132+
{
130133
blob = StringUtil::createStringBlob(outputString);
131134
break;
135+
}
132136
case ResultFormat::Binary:
133137
{
134138
if (downstreamResult)
@@ -1968,7 +1972,11 @@ SlangResult dissassembleDXILUsingDXC(
19681972
case ResultFormat::Binary:
19691973
{
19701974
ComPtr<ISlangBlob> blob;
1971-
result.getBlob(blob);
1975+
if (SLANG_FAILED(result.getBlob(blob)))
1976+
{
1977+
SLANG_UNEXPECTED("No blob to emit");
1978+
return;
1979+
}
19721980
writeOutputFile(compileRequest,
19731981
outputPath,
19741982
blob->getBufferPointer(),
@@ -2020,6 +2028,7 @@ SlangResult dissassembleDXILUsingDXC(
20202028
ComPtr<ISlangBlob> blob;
20212029
if (SLANG_FAILED(result.getBlob(blob)))
20222030
{
2031+
SLANG_UNEXPECTED("No blob to emit");
20232032
return;
20242033
}
20252034

source/slang/slang-emit-cpp.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -2598,7 +2598,12 @@ void CPPSourceEmitter::emitModuleImpl(IRModule* module)
25982598
targetProgram->getOrCreateEntryPointResult(index, &sink);
25992599

26002600
Slang::ComPtr<ISlangBlob> blob;
2601-
result.getBlob(blob);
2601+
if (SLANG_FAILED(result.getBlob(blob)))
2602+
{
2603+
SLANG_UNEXPECTED("No blob to emit");
2604+
return;
2605+
}
2606+
26022607
auto ptr = (const unsigned char*)blob->getBufferPointer();
26032608

26042609
m_writer->emit("size_t __");

source/slang/slang.cpp

+10-10
Original file line numberDiff line numberDiff line change
@@ -3390,6 +3390,13 @@ SLANG_API void const* spGetEntryPointCode(
33903390
size_t* outSize)
33913391
{
33923392
using namespace Slang;
3393+
3394+
// Zero the size initially, in case need to return nullptr for error.
3395+
if (outSize)
3396+
{
3397+
*outSize = 0;
3398+
}
3399+
33933400
auto req = Slang::asInternal(request);
33943401
auto linkage = req->getLinkage();
33953402
auto program = req->getSpecializedGlobalAndEntryPointsComponentType();
@@ -3411,22 +3418,15 @@ SLANG_API void const* spGetEntryPointCode(
34113418
return nullptr;
34123419
CompileResult& result = targetProgram->getExistingEntryPointResult(entryPointIndex);
34133420

3414-
void const* data = nullptr;
3415-
size_t size = 0;
3416-
34173421
ComPtr<ISlangBlob> blob;
3418-
if (SLANG_SUCCEEDED(result.getBlob(blob)))
3419-
{
3420-
data = blob->getBufferPointer();
3421-
size = blob->getBufferSize();
3422-
}
3422+
SLANG_RETURN_NULL_ON_FAIL(result.getBlob(blob));
34233423

34243424
if (outSize)
34253425
{
3426-
*outSize = size;
3426+
*outSize = blob->getBufferSize();
34273427
}
34283428

3429-
return data;
3429+
return (void*)blob->getBufferPointer();
34303430
}
34313431

34323432
static SlangResult _getEntryPointResult(

0 commit comments

Comments
 (0)