Closed cebtenzzre closed 5 years ago
Yea, that line shouldn't be there. It was left over from some earlier implementation. As for why I don't use dynamic cast all the time - it has (or used to have?) an annoying requirement that the derived must override some method in the base class which often times makes no sense when the derived is a pure extension of the base. I found this intrusive enough to avoid using it.
Should be fixed by https://github.com/RPCS3/rpcs3/pull/6784
RPCS3 version: 0.0.7-8901 Alpha (commit 0fe46934de258826e72bfb00eb20c606d0a635cd) OS: Arch Linux (x86_64), kernel v5.3.6-arch1
Steps to reproduce:
Expected behavior: The game starts.
Actual behavior: RPCS3 sometimes crashes after it has loaded precompiled shaders, but before the games starts. Other times, it silently corrupts the heap but works anyway.
Here's what I believe is going on:
render_target::get_resolve_target_safe
allocates avk::viewable_image
calledresolve_surface
. https://github.com/RPCS3/rpcs3/blob/0fe46934de258826e72bfb00eb20c606d0a635cd/rpcs3/Emu/RSX/VK/VKRenderTargets.h#L31render_target::resolve
callsvk::resolve_image
withresolve_surface
asdst
. https://github.com/RPCS3/rpcs3/blob/0fe46934de258826e72bfb00eb20c606d0a635cd/rpcs3/Emu/RSX/VK/VKRenderTargets.h#L92vk::resolve_image
callsvk::as_rtt
ondst
. https://github.com/RPCS3/rpcs3/blob/0fe46934de258826e72bfb00eb20c606d0a635cd/rpcs3/Emu/RSX/VK/VKResolveHelper.cpp#L106vk::as_rtt
castsdst
to avk::render_target
, which it is not. https://github.com/RPCS3/rpcs3/blob/0fe46934de258826e72bfb00eb20c606d0a635cd/rpcs3/Emu/RSX/VK/VKRenderTargets.h#L544From cppreference, under conversion number 2:
Since RPCS3 implements no safety mechanism for this cast, it would make sense to follow the above recommendation and use
dynamic_cast
. This is a simple patch that would accomplish this:This uses
dynamic_cast
on a reference so that instead of unpredictable memory corruption, you get a reliablestd::bad_cast
exception in the RPCS3 console.gl::as_rtt
performs a similar cast (withreinterpret_cast
for some reason), which should also usedynamic_cast
. Obviously, the bug is still there, it is just reliably caught this way.The following ASAN report is triggered by this bug. It shows that
vk::resolve_image
is usingvk::as_rtt
to write past the end ofresolve_surface
, which in this instance contained memory that was previously freed.