Skip to content

Commit

Permalink
GS: Fix crash when resizing window
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek authored and refractionpcsx2 committed Apr 8, 2023
1 parent 1b8f5f2 commit 7f24a5c
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions pcsx2/GS/Renderers/Common/GSDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,22 +196,31 @@ bool GSDevice::GetHostRefreshRate(float* refresh_rate)

bool GSDevice::UpdateImGuiFontTexture()
{
ImGuiIO& io = ImGui::GetIO();

unsigned char* pixels;
int width, height;
ImGui::GetIO().Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);
io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);

const GSVector4i r(0, 0, width, height);
const int pitch = sizeof(u32) * width;

if (m_imgui_font && m_imgui_font->GetWidth() == width && m_imgui_font->GetHeight() == height)
return m_imgui_font->Update(r, pixels, pitch);
if (m_imgui_font && m_imgui_font->GetWidth() == width && m_imgui_font->GetHeight() == height &&
m_imgui_font->Update(r, pixels, pitch))
{
io.Fonts->SetTexID(m_imgui_font->GetNativeHandle());
return true;
}

GSTexture* new_font = CreateTexture(width, height, 1, GSTexture::Format::Color);
if (!new_font || !new_font->Update(r, pixels, pitch))
{
io.Fonts->SetTexID(m_imgui_font ? m_imgui_font->GetNativeHandle() : nullptr);
return false;
}

if (m_imgui_font)
Recycle(m_imgui_font);
// Don't bother recycling, it's unlikely we're going to reuse the same size as imgui for rendering.
delete m_imgui_font;

m_imgui_font = new_font;
ImGui::GetIO().Fonts->SetTexID(new_font->GetNativeHandle());
Expand Down

0 comments on commit 7f24a5c

Please sign in to comment.