devtools: fix ReleaseKeyboard assert being triggered if many shader editor windows exist (#2205)

This commit is contained in:
Vinicius Rangel 2025-01-22 12:08:49 -03:00 committed by GitHub
parent 2968cf5a99
commit b3bce086b3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 47 additions and 27 deletions

View file

@ -24,16 +24,33 @@ using namespace ImGui;
namespace Core::Devtools::Widget { namespace Core::Devtools::Widget {
ShaderList::Selection::Selection(int index) : index(index) { ShaderList::Selection::Selection(int index)
isa_editor.SetPalette(TextEditor::GetDarkPalette()); : index(index), isa_editor(std::make_unique<TextEditor>()),
isa_editor.SetReadOnly(true); glsl_editor(std::make_unique<TextEditor>()) {
glsl_editor.SetPalette(TextEditor::GetDarkPalette()); isa_editor->SetPalette(TextEditor::GetDarkPalette());
glsl_editor.SetLanguageDefinition(TextEditor::LanguageDefinition::GLSL()); isa_editor->SetReadOnly(true);
glsl_editor->SetPalette(TextEditor::GetDarkPalette());
glsl_editor->SetLanguageDefinition(TextEditor::LanguageDefinition::GLSL());
presenter->GetWindow().RequestKeyboard(); presenter->GetWindow().RequestKeyboard();
} }
ShaderList::Selection::~Selection() { ShaderList::Selection::~Selection() {
presenter->GetWindow().ReleaseKeyboard(); if (index >= 0) {
presenter->GetWindow().ReleaseKeyboard();
}
}
ShaderList::Selection::Selection(Selection&& other) noexcept
: index{other.index}, isa_editor{std::move(other.isa_editor)},
glsl_editor{std::move(other.glsl_editor)}, open{other.open}, showing_bin{other.showing_bin},
patch_path{std::move(other.patch_path)}, patch_bin_path{std::move(other.patch_bin_path)} {
other.index = -1;
}
ShaderList::Selection& ShaderList::Selection::operator=(Selection other) {
using std::swap;
swap(*this, other);
return *this;
} }
void ShaderList::Selection::ReloadShader(DebugStateType::ShaderDump& value) { void ShaderList::Selection::ReloadShader(DebugStateType::ShaderDump& value) {
@ -72,13 +89,13 @@ bool ShaderList::Selection::DrawShader(DebugStateType::ShaderDump& value) {
value.is_patched = !value.patch_spv.empty(); value.is_patched = !value.patch_spv.empty();
if (!value.is_patched) { // No patch if (!value.is_patched) { // No patch
isa_editor.SetText(value.cache_isa_disasm); isa_editor->SetText(value.cache_isa_disasm);
glsl_editor.SetText(value.cache_spv_disasm); glsl_editor->SetText(value.cache_spv_disasm);
} else { } else {
isa_editor.SetText(value.cache_patch_disasm); isa_editor->SetText(value.cache_patch_disasm);
isa_editor.SetLanguageDefinition(TextEditor::LanguageDefinition::SPIRV()); isa_editor->SetLanguageDefinition(TextEditor::LanguageDefinition::SPIRV());
glsl_editor.SetText(value.patch_source); glsl_editor->SetText(value.patch_source);
glsl_editor.SetReadOnly(false); glsl_editor->SetReadOnly(false);
} }
} }
@ -97,18 +114,18 @@ bool ShaderList::Selection::DrawShader(DebugStateType::ShaderDump& value) {
if (value.patch_source.empty()) { if (value.patch_source.empty()) {
value.patch_source = value.cache_spv_disasm; value.patch_source = value.cache_spv_disasm;
} }
isa_editor.SetText(value.cache_patch_disasm); isa_editor->SetText(value.cache_patch_disasm);
isa_editor.SetLanguageDefinition(TextEditor::LanguageDefinition::SPIRV()); isa_editor->SetLanguageDefinition(TextEditor::LanguageDefinition::SPIRV());
glsl_editor.SetText(value.patch_source); glsl_editor->SetText(value.patch_source);
glsl_editor.SetReadOnly(false); glsl_editor->SetReadOnly(false);
if (!value.patch_spv.empty()) { if (!value.patch_spv.empty()) {
ReloadShader(value); ReloadShader(value);
} }
} else { } else {
isa_editor.SetText(value.cache_isa_disasm); isa_editor->SetText(value.cache_isa_disasm);
isa_editor.SetLanguageDefinition(TextEditor::LanguageDefinition()); isa_editor->SetLanguageDefinition(TextEditor::LanguageDefinition());
glsl_editor.SetText(value.cache_spv_disasm); glsl_editor->SetText(value.cache_spv_disasm);
glsl_editor.SetReadOnly(true); glsl_editor->SetReadOnly(true);
ReloadShader(value); ReloadShader(value);
} }
} }
@ -154,7 +171,7 @@ bool ShaderList::Selection::DrawShader(DebugStateType::ShaderDump& value) {
compile = true; compile = true;
} }
if (save) { if (save) {
value.patch_source = glsl_editor.GetText(); value.patch_source = glsl_editor->GetText();
std::ofstream file{patch_path, std::ios::binary | std::ios::trunc}; std::ofstream file{patch_path, std::ios::binary | std::ios::trunc};
file << value.patch_source; file << value.patch_source;
std::string msg = "Patch saved to "; std::string msg = "Patch saved to ";
@ -192,7 +209,7 @@ bool ShaderList::Selection::DrawShader(DebugStateType::ShaderDump& value) {
DebugState.ShowDebugMessage("Decompilation failed (Compile was ok):\n" + DebugState.ShowDebugMessage("Decompilation failed (Compile was ok):\n" +
res); res);
} else { } else {
isa_editor.SetText(value.cache_patch_disasm); isa_editor->SetText(value.cache_patch_disasm);
ReloadShader(value); ReloadShader(value);
} }
} }
@ -201,9 +218,9 @@ bool ShaderList::Selection::DrawShader(DebugStateType::ShaderDump& value) {
} }
if (showing_bin) { if (showing_bin) {
isa_editor.Render(value.is_patched ? "SPIRV" : "ISA", GetContentRegionAvail()); isa_editor->Render(value.is_patched ? "SPIRV" : "ISA", GetContentRegionAvail());
} else { } else {
glsl_editor.Render("GLSL", GetContentRegionAvail()); glsl_editor->Render("GLSL", GetContentRegionAvail());
} }
End(); End();

View file

@ -14,14 +14,17 @@ class ShaderList {
struct Selection { struct Selection {
explicit Selection(int index); explicit Selection(int index);
~Selection(); ~Selection();
Selection(const Selection& other) = delete;
Selection(Selection&& other) noexcept;
Selection& operator=(Selection other);
void ReloadShader(DebugStateType::ShaderDump& value); void ReloadShader(DebugStateType::ShaderDump& value);
bool DrawShader(DebugStateType::ShaderDump& value); bool DrawShader(DebugStateType::ShaderDump& value);
int index; int index{-1};
TextEditor isa_editor{}; std::unique_ptr<TextEditor> isa_editor{};
TextEditor glsl_editor{}; std::unique_ptr<TextEditor> glsl_editor{};
bool open = true; bool open = true;
bool showing_bin = false; bool showing_bin = false;