Skip to content

Commit 42232ab

Browse files
committed
Fix VkFence destruction crashing on Windows
vk::destroy was crashing for vk::Fence after: https://swiftshader-review.googlesource.com/c/SwiftShader/+/31988 Reverted that change and fixed it in VkObject.cpp to make sure the result of the cast is always equal to the allocated memory. Bug: b/117835459 Change-Id: I831625418fc83503329e833d48d9765b75d83b80 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/31990 Tested-by: Alexis Hétu <[email protected]> Presubmit-Ready: Alexis Hétu <[email protected]> Reviewed-by: Antonio Maiorano <[email protected]> Reviewed-by: Nicolas Capens <[email protected]> Kokoro-Presubmit: kokoro <[email protected]>
1 parent a71a1db commit 42232ab

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/Vulkan/VkFence.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class Fence : public Object<Fence, VkFence>, public sw::TaskEvents
8282

8383
static inline Fence* Cast(VkFence object)
8484
{
85-
return static_cast<Fence*>(reinterpret_cast<Object<Fence, VkFence>*>(object.get()));
85+
return reinterpret_cast<Fence*>(object.get());
8686
}
8787

8888
} // namespace vk

src/Vulkan/VkObject.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ static VkResult Create(const VkAllocationCallbacks* pAllocator, const CreateInfo
6161

6262
*outObject = *object;
6363

64+
// Assert that potential v-table offsets from multiple inheritance aren't causing an offset on the handle
65+
ASSERT(*outObject == objectMemory);
66+
6467
return VK_SUCCESS;
6568
}
6669

@@ -87,7 +90,9 @@ class Object : public ObjectBase<T, VkT>
8790
public:
8891
operator VkT()
8992
{
90-
return reinterpret_cast<typename VkT::HandleType>(this);
93+
// The static_cast<T*> is used to make sure the returned pointer points to the
94+
// beginning of the object, even if the derived class uses multiple inheritance
95+
return reinterpret_cast<typename VkT::HandleType>(static_cast<T*>(this));
9196
}
9297
};
9398

0 commit comments

Comments
 (0)