Commit a71a1dbb by Antonio Maiorano

Fix Cast(vkFence) crashing on Windows

Fence has a second base class with virtual functions, but its first base does not. In "static VkResult Create(...), when assigning the handle via: *outObject = *object; since this is code run in the context of the first base class, the address returned is offset by sizeof the vtable pointer from the second base class (8 bytes on x64). Problem is that the Cast overload for Fence does a simple reinterpret_cast of this stored pointer back to Fence*, without the offset being taken into account. The fix is to simply first cast the stored pointer back to the first base class type, and then static_cast it to the derived Fence type. Bug: b/117835459 Change-Id: Ieb2856320e996a5ad5d9e69aad5e01cfaee1cd9e Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/31988Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Tested-by: 's avatarAntonio Maiorano <amaiorano@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
parent 5e9441a2
...@@ -82,7 +82,7 @@ private: ...@@ -82,7 +82,7 @@ private:
static inline Fence* Cast(VkFence object) static inline Fence* Cast(VkFence object)
{ {
return reinterpret_cast<Fence*>(object.get()); return static_cast<Fence*>(reinterpret_cast<Object<Fence, VkFence>*>(object.get()));
} }
} // namespace vk } // namespace vk
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment