Skip to content

Commit

Permalink
Throw exception when gpu buffer fails to map on creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Nelarius committed Apr 6, 2024
1 parent 20f0063 commit 4389072
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/pt/gpu_buffer.hpp
Expand Up @@ -167,15 +167,19 @@ GpuBuffer::GpuBuffer(

if (!mBuffer)
{
throw std::runtime_error(fmt::format("Failed to create buffer: {}.", label));
throw std::runtime_error(fmt::format("Failed to create buffer \"{}\".", label));
}

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

void* const mappedData = wgpuBufferGetMappedRange(mBuffer, 0, mByteSize);
NLRS_ASSERT(mappedData);
if (!mappedData)
{
throw std::runtime_error(
fmt::format("Failed to map buffer \"{}\", bytesize: {}.", label, mByteSize));
}
std::memcpy(mappedData, data.data(), mByteSize);
wgpuBufferUnmap(mBuffer);
}
Expand Down

0 comments on commit 4389072

Please sign in to comment.