Skip to content

Commit

Permalink
Fix CopyTextureRegion crash in some games
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Nov 16, 2023
1 parent c7e66e9 commit 0a6a126
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/mods/vr/FFakeStereoRenderingHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3851,6 +3851,27 @@ void FFakeStereoRenderingHook::adjust_view_rect(FFakeStereoRendering* stereo, in
index_starts_from_one = false;
}

// The purpose of this is to prevent the game from crashing in IDirect3D12CommandList::Close
// Because the game will try to copy a texture region that is out of bounds.
if (g_hook->m_skip_next_adjust_view_rect) {
*x = 0;
*y = 0;
*w = std::min<uint32_t>(VR::get()->get_hmd_width(), *w);
*h = std::min<uint32_t>(VR::get()->get_hmd_height(), *h);
g_hook->m_skip_next_adjust_view_rect = false;
g_hook->m_skip_next_adjust_view_rect_count = 1;
return;
}

if (g_hook->m_skip_next_adjust_view_rect_count > 0) {
*x = 0;
*y = 0;
*w = std::min<uint32_t>(VR::get()->get_hmd_width(), *w);
*h = std::min<uint32_t>(VR::get()->get_hmd_height(), *h);
--g_hook->m_skip_next_adjust_view_rect_count;
return;
}

if (VR::get()->is_stereo_emulation_enabled()) {
*w *= 2;
} else {
Expand Down
3 changes: 3 additions & 0 deletions src/mods/vr/FFakeStereoRenderingHook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ class FFakeStereoRenderingHook : public ModComponent {

void set_should_recreate_textures(bool recreate) {
m_wants_texture_recreation = recreate;
m_skip_next_adjust_view_rect = true;
}

void on_device_reset() override {
Expand Down Expand Up @@ -415,6 +416,8 @@ class FFakeStereoRenderingHook : public ModComponent {
bool m_wants_texture_recreation{false};
bool m_has_view_extension_hook{false};
bool m_has_game_viewport_client_draw_hook{false};
bool m_skip_next_adjust_view_rect{false};
int32_t m_skip_next_adjust_view_rect_count{1};

// Synchronized AFR
float m_ignored_engine_delta{0.0f};
Expand Down

0 comments on commit 0a6a126

Please sign in to comment.