Skip to content

Commit 4389072

Browse files
committed
Throw exception when gpu buffer fails to map on creation
1 parent 20f0063 commit 4389072

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/pt/gpu_buffer.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,15 +167,19 @@ GpuBuffer::GpuBuffer(
167167

168168
if (!mBuffer)
169169
{
170-
throw std::runtime_error(fmt::format("Failed to create buffer: {}.", label));
170+
throw std::runtime_error(fmt::format("Failed to create buffer \"{}\".", label));
171171
}
172172

173173
// It's legal to set mappedAtCreation = true and use the mapped range even if the usage doesn't
174174
// include MAP_READ or MAP_WRITE.
175175
// https://www.w3.org/TR/webgpu/#dom-gpubufferdescriptor-mappedatcreation
176176

177177
void* const mappedData = wgpuBufferGetMappedRange(mBuffer, 0, mByteSize);
178-
NLRS_ASSERT(mappedData);
178+
if (!mappedData)
179+
{
180+
throw std::runtime_error(
181+
fmt::format("Failed to map buffer \"{}\", bytesize: {}.", label, mByteSize));
182+
}
179183
std::memcpy(mappedData, data.data(), mByteSize);
180184
wgpuBufferUnmap(mBuffer);
181185
}

0 commit comments

Comments
 (0)