mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-08-10 14:09:07 +00:00
Fix Vulkan leak if vkMapMemory fails
This introduces a macro DAWN_TRY_WITH_CLEANUP which allows some code to be run before the early return. Bug: chromium:1177332 Change-Id: I529c9ca6f2b0cf6ffd4bf85719a4e2a1c2552d1b Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/42003 Commit-Queue: Austin Eng <enga@chromium.org> Reviewed-by: Stephen White <senorblanco@chromium.org>
This commit is contained in:
parent
ef9e4412f5
commit
eea1209b12
@ -97,16 +97,20 @@ namespace dawn_native {
|
|||||||
// When Errors aren't handled explicitly, calls to functions returning errors should be
|
// When Errors aren't handled explicitly, calls to functions returning errors should be
|
||||||
// wrapped in an DAWN_TRY. It will return the error if any, otherwise keep executing
|
// wrapped in an DAWN_TRY. It will return the error if any, otherwise keep executing
|
||||||
// the current function.
|
// the current function.
|
||||||
#define DAWN_TRY(EXPR) \
|
#define DAWN_TRY(EXPR) DAWN_TRY_WITH_CLEANUP(EXPR, {})
|
||||||
{ \
|
|
||||||
auto DAWN_LOCAL_VAR = EXPR; \
|
#define DAWN_TRY_WITH_CLEANUP(EXPR, BODY) \
|
||||||
if (DAWN_UNLIKELY(DAWN_LOCAL_VAR.IsError())) { \
|
{ \
|
||||||
std::unique_ptr<::dawn_native::ErrorData> error = DAWN_LOCAL_VAR.AcquireError(); \
|
auto DAWN_LOCAL_VAR = EXPR; \
|
||||||
error->AppendBacktrace(__FILE__, __func__, __LINE__); \
|
if (DAWN_UNLIKELY(DAWN_LOCAL_VAR.IsError())) { \
|
||||||
return {std::move(error)}; \
|
{BODY} /* comment to force the formatter to insert a newline */ \
|
||||||
} \
|
std::unique_ptr<::dawn_native::ErrorData> \
|
||||||
} \
|
error = DAWN_LOCAL_VAR.AcquireError(); \
|
||||||
for (;;) \
|
error->AppendBacktrace(__FILE__, __func__, __LINE__); \
|
||||||
|
return {std::move(error)}; \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
for (;;) \
|
||||||
break
|
break
|
||||||
|
|
||||||
// DAWN_TRY_ASSIGN is the same as DAWN_TRY for ResultOrError and assigns the success value, if
|
// DAWN_TRY_ASSIGN is the same as DAWN_TRY for ResultOrError and assigns the success value, if
|
||||||
|
@ -150,11 +150,14 @@ namespace dawn_native { namespace vulkan {
|
|||||||
|
|
||||||
void* mappedPointer = nullptr;
|
void* mappedPointer = nullptr;
|
||||||
if (mappable) {
|
if (mappable) {
|
||||||
DAWN_TRY(
|
DAWN_TRY_WITH_CLEANUP(
|
||||||
CheckVkSuccess(mDevice->fn.MapMemory(mDevice->GetVkDevice(),
|
CheckVkSuccess(mDevice->fn.MapMemory(mDevice->GetVkDevice(),
|
||||||
ToBackend(resourceHeap.get())->GetMemory(), 0,
|
ToBackend(resourceHeap.get())->GetMemory(), 0,
|
||||||
size, 0, &mappedPointer),
|
size, 0, &mappedPointer),
|
||||||
"vkMapMemory"));
|
"vkMapMemory"),
|
||||||
|
{
|
||||||
|
mAllocatorsPerType[memoryType]->DeallocateResourceHeap(std::move(resourceHeap));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
AllocationInfo info;
|
AllocationInfo info;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user