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 <sugoi@google.com>
Presubmit-Ready: Alexis Hétu <sugoi@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
diff --git a/src/Vulkan/VkFence.hpp b/src/Vulkan/VkFence.hpp
index 6b6ab02..7b990ef 100644
--- a/src/Vulkan/VkFence.hpp
+++ b/src/Vulkan/VkFence.hpp
@@ -82,7 +82,7 @@
 
 static inline Fence* Cast(VkFence object)
 {
-	return static_cast<Fence*>(reinterpret_cast<Object<Fence, VkFence>*>(object.get()));
+	return reinterpret_cast<Fence*>(object.get());
 }
 
 } // namespace vk
diff --git a/src/Vulkan/VkObject.hpp b/src/Vulkan/VkObject.hpp
index 2b6a7ab..0fdcc23 100644
--- a/src/Vulkan/VkObject.hpp
+++ b/src/Vulkan/VkObject.hpp
@@ -61,6 +61,9 @@
 
 	*outObject = *object;
 
+	// Assert that potential v-table offsets from multiple inheritance aren't causing an offset on the handle
+	ASSERT(*outObject == objectMemory);
+
 	return VK_SUCCESS;
 }
 
@@ -87,7 +90,9 @@
 public:
 	operator VkT()
 	{
-		return reinterpret_cast<typename VkT::HandleType>(this);
+		// The static_cast<T*> is used to make sure the returned pointer points to the
+		// beginning of the object, even if the derived class uses multiple inheritance
+		return reinterpret_cast<typename VkT::HandleType>(static_cast<T*>(this));
 	}
 };