fix: Popups not appearing at launch sometimes and crashes when exiting
This commit is contained in:
parent
c89d19cd27
commit
409b3ccd6c
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#include <hex/ui/view.hpp>
|
#include <hex/ui/view.hpp>
|
||||||
#include <hex/ui/popup.hpp>
|
#include <hex/ui/popup.hpp>
|
||||||
|
#include <hex/ui/toast.hpp>
|
||||||
|
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
@ -98,6 +99,7 @@ namespace hex::init {
|
|||||||
|
|
||||||
ContentRegistry::Views::impl::getEntries().clear();
|
ContentRegistry::Views::impl::getEntries().clear();
|
||||||
impl::PopupBase::getOpenPopups().clear();
|
impl::PopupBase::getOpenPopups().clear();
|
||||||
|
impl::ToastBase::getQueuedToasts().clear();
|
||||||
|
|
||||||
|
|
||||||
ContentRegistry::Tools::impl::getEntries().clear();
|
ContentRegistry::Tools::impl::getEntries().clear();
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
|
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
#include <hex/ui/toast.hpp>
|
#include <hex/ui/toast.hpp>
|
||||||
|
#include <wolv/utils/guards.hpp>
|
||||||
|
|
||||||
namespace hex {
|
namespace hex {
|
||||||
|
|
||||||
@ -673,10 +674,17 @@ namespace hex {
|
|||||||
static bool positionSet = false;
|
static bool positionSet = false;
|
||||||
static bool sizeSet = false;
|
static bool sizeSet = false;
|
||||||
static double popupDelay = -2.0;
|
static double popupDelay = -2.0;
|
||||||
|
static u32 displayFrameCount = 0;
|
||||||
|
|
||||||
static std::unique_ptr<impl::PopupBase> currPopup;
|
static std::unique_ptr<impl::PopupBase> currPopup;
|
||||||
static Lang name("");
|
static Lang name("");
|
||||||
|
|
||||||
|
AT_FIRST_TIME {
|
||||||
|
EventImHexClosing::subscribe([] {
|
||||||
|
currPopup.reset();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
if (auto &popups = impl::PopupBase::getOpenPopups(); !popups.empty()) {
|
if (auto &popups = impl::PopupBase::getOpenPopups(); !popups.empty()) {
|
||||||
if (!ImGui::IsPopupOpen(ImGuiID(0), ImGuiPopupFlags_AnyPopupId)) {
|
if (!ImGui::IsPopupOpen(ImGuiID(0), ImGuiPopupFlags_AnyPopupId)) {
|
||||||
if (popupDelay <= -1.0) {
|
if (popupDelay <= -1.0) {
|
||||||
@ -687,6 +695,7 @@ namespace hex {
|
|||||||
popupDelay = -2.0;
|
popupDelay = -2.0;
|
||||||
currPopup = std::move(popups.back());
|
currPopup = std::move(popups.back());
|
||||||
name = Lang(currPopup->getUnlocalizedName());
|
name = Lang(currPopup->getUnlocalizedName());
|
||||||
|
displayFrameCount = 0;
|
||||||
|
|
||||||
ImGui::OpenPopup(name);
|
ImGui::OpenPopup(name);
|
||||||
popups.pop_back();
|
popups.pop_back();
|
||||||
@ -720,6 +729,7 @@ namespace hex {
|
|||||||
|
|
||||||
const auto createPopup = [&](bool displaying) {
|
const auto createPopup = [&](bool displaying) {
|
||||||
if (displaying) {
|
if (displaying) {
|
||||||
|
displayFrameCount += 1;
|
||||||
currPopup->drawContent();
|
currPopup->drawContent();
|
||||||
|
|
||||||
if (ImGui::GetWindowSize().x > ImGui::GetStyle().FramePadding.x * 10)
|
if (ImGui::GetWindowSize().x > ImGui::GetStyle().FramePadding.x * 10)
|
||||||
@ -746,6 +756,10 @@ namespace hex {
|
|||||||
else
|
else
|
||||||
createPopup(ImGui::BeginPopup(name, flags));
|
createPopup(ImGui::BeginPopup(name, flags));
|
||||||
|
|
||||||
|
if (!ImGui::IsPopupOpen(name) && displayFrameCount < 10) {
|
||||||
|
ImGui::OpenPopup(name);
|
||||||
|
}
|
||||||
|
|
||||||
if (currPopup->shouldClose()) {
|
if (currPopup->shouldClose()) {
|
||||||
log::debug("Closing popup '{}'", name);
|
log::debug("Closing popup '{}'", name);
|
||||||
positionSet = sizeSet = false;
|
positionSet = sizeSet = false;
|
||||||
|
Loading…
Reference in New Issue
Block a user