fix: Make sure all textures are destroyed before glfw gets uninitialized

This commit is contained in:
WerWolv
2025-01-27 22:10:30 +01:00
parent 6e6c5bbc67
commit 24e7c2f3db
17 changed files with 104 additions and 56 deletions

View File

@@ -306,7 +306,7 @@ namespace hex::plugin::builtin {
const auto &rawData = this->getBufferOnInput(0);
m_data = rawData;
m_texture = {};
m_texture.reset();
}
private:
@@ -332,7 +332,7 @@ namespace hex::plugin::builtin {
}
void process() override {
m_texture = { };
m_texture.reset();
const auto &rawData = this->getBufferOnInput(0);
const auto &width = this->getIntegerOnInput(1);
@@ -343,7 +343,7 @@ namespace hex::plugin::builtin {
throwNodeError(hex::format("Image requires at least {} bytes of data, but only {} bytes are available", requiredBytes, rawData.size()));
m_data = rawData;
m_texture = {};
m_texture.reset();
}
private:

View File

@@ -10,6 +10,7 @@
#include <hex/api/theme_manager.hpp>
#include <hex/api/tutorial_manager.hpp>
#include <hex/helpers/utils.hpp>
#include <hex/helpers/auto_reset.hpp>
#include <romfs/romfs.hpp>
#include <wolv/hash/uuid.hpp>
@@ -24,8 +25,8 @@ namespace hex::plugin::builtin {
namespace {
ImGuiExt::Texture s_imhexBanner;
ImGuiExt::Texture s_compassTexture, s_globeTexture;
AutoReset<ImGuiExt::Texture> s_imhexBanner;
AutoReset<ImGuiExt::Texture> s_compassTexture, s_globeTexture;
std::list<std::pair<std::fs::path, ImGuiExt::Texture>> s_screenshots;
nlohmann::json s_screenshotDescriptions;
@@ -77,9 +78,9 @@ namespace hex::plugin::builtin {
// Draw banner
ImGui::SetCursorPos(scaled({ 25 * bannerSlideIn, 25 }));
const auto bannerSize = s_imhexBanner.getSize() / (3.0F * (1.0F / ImHexApi::System::getGlobalScale()));
const auto bannerSize = s_imhexBanner->getSize() / (3.0F * (1.0F / ImHexApi::System::getGlobalScale()));
ImGui::Image(
s_imhexBanner,
*s_imhexBanner,
bannerSize,
{ 0, 0 }, { 1, 1 },
{ 1, 1, 1, (bannerFadeIn - 0.5F) * 2.0F }
@@ -222,9 +223,9 @@ namespace hex::plugin::builtin {
currLanguage = languages.begin();
// Draw globe image
const auto imageSize = s_compassTexture.getSize() / (1.5F * (1.0F / ImHexApi::System::getGlobalScale()));
const auto imageSize = s_compassTexture->getSize() / (1.5F * (1.0F / ImHexApi::System::getGlobalScale()));
ImGui::SetCursorPos((ImGui::GetWindowSize() / 2 - imageSize / 2) - ImVec2(0, 50_scaled));
ImGui::Image(s_globeTexture, imageSize);
ImGui::Image(*s_globeTexture, imageSize);
ImGui::NewLine();
ImGui::NewLine();
@@ -372,9 +373,9 @@ namespace hex::plugin::builtin {
ImGui::NewLine();
// Draw compass image
const auto imageSize = s_compassTexture.getSize() / (1.5F * (1.0F / ImHexApi::System::getGlobalScale()));
const auto imageSize = s_compassTexture->getSize() / (1.5F * (1.0F / ImHexApi::System::getGlobalScale()));
ImGui::SetCursorPos((ImGui::GetWindowSize() / 2 - imageSize / 2) - ImVec2(0, 50_scaled));
ImGui::Image(s_compassTexture, imageSize);
ImGui::Image(*s_compassTexture, imageSize);
// Draw information text about playing the tutorial
ImGui::SetCursorPosX(0);

View File

@@ -155,14 +155,18 @@ namespace hex::plugin::builtin {
ImGui::NewLine();
struct DonationPage {
ImGuiExt::Texture texture;
const char *link;
DonationPage(const std::fs::path &path, const std::string &link) :
texture(ImGuiExt::Texture::fromImage(romfs::get(path).span<std::byte>(), ImGuiExt::Texture::Filter::Linear)),
link(std::move(link)) { }
AutoReset<ImGuiExt::Texture> texture;
std::string link;
};
static std::array DonationPages = {
DonationPage { ImGuiExt::Texture::fromImage(romfs::get("assets/common/donation/paypal.png").span<std::byte>(), ImGuiExt::Texture::Filter::Linear), "https://werwolv.net/donate" },
DonationPage { ImGuiExt::Texture::fromImage(romfs::get("assets/common/donation/github.png").span<std::byte>(), ImGuiExt::Texture::Filter::Linear), "https://github.com/sponsors/WerWolv" },
DonationPage { ImGuiExt::Texture::fromImage(romfs::get("assets/common/donation/patreon.png").span<std::byte>(), ImGuiExt::Texture::Filter::Linear), "https://patreon.com/werwolv" },
DonationPage("assets/common/donation/paypal.png", "https://werwolv.net/donate"),
DonationPage("assets/common/donation/github.png", "https://github.com/sponsors/WerWolv"),
DonationPage("assets/common/donation/patreon.png", "https://patreon.com/werwolv")
};
if (ImGui::BeginTable("DonationLinks", 5, ImGuiTableFlags_SizingStretchSame)) {
@@ -172,9 +176,9 @@ namespace hex::plugin::builtin {
for (const auto &page : DonationPages) {
ImGui::TableNextColumn();
const auto size = page.texture.getSize() / 1.5F;
const auto size = page.texture->getSize() / 1.5F;
const auto startPos = ImGui::GetCursorScreenPos();
ImGui::Image(page.texture, page.texture.getSize() / 1.5F);
ImGui::Image(*page.texture, page.texture->getSize() / 1.5F);
if (ImGui::IsItemHovered()) {
ImGui::GetForegroundDrawList()->AddShadowCircle(startPos + size / 2, size.x / 2, ImGui::GetColorU32(ImGuiCol_Button), 100.0F, ImVec2(), ImDrawFlags_ShadowCutOutShapeBackground);

View File

@@ -41,7 +41,7 @@
namespace hex::plugin::builtin {
namespace {
ImGuiExt::Texture s_bannerTexture, s_nightlyTexture, s_backdropTexture, s_infoBannerTexture;
AutoReset<ImGuiExt::Texture> s_bannerTexture, s_nightlyTexture, s_backdropTexture, s_infoBannerTexture;
std::string s_tipOfTheDay;
@@ -173,7 +173,7 @@ namespace hex::plugin::builtin {
void drawWelcomeScreenContentSimplified() {
const ImVec2 backdropSize = scaled({ 350, 350 });
ImGui::SetCursorPos((ImGui::GetContentRegionAvail() - backdropSize) / 2);
ImGui::Image(s_backdropTexture, backdropSize);
ImGui::Image(*s_backdropTexture, backdropSize);
ImGuiExt::TextFormattedCentered("hex.builtin.welcome.drop_file"_lang);
}
@@ -193,7 +193,7 @@ namespace hex::plugin::builtin {
if (ImGui::BeginTable("Welcome Left", 1, ImGuiTableFlags_NoBordersInBody, ImVec2(availableSpace.x / 2, 0))) {
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImGui::Image(s_bannerTexture, s_bannerTexture.getSize());
ImGui::Image(*s_bannerTexture, s_bannerTexture->getSize());
if (ImHexApi::System::isNightlyBuild()) {
auto cursor = ImGui::GetCursorPos();
@@ -202,7 +202,7 @@ namespace hex::plugin::builtin {
ImGui::SetCursorPosX(ImGui::GetCursorPosX() - 15_scaled);
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 5_scaled);
ImGui::Image(s_nightlyTexture, s_nightlyTexture.getSize());
ImGui::Image(*s_nightlyTexture, s_nightlyTexture->getSize());
ImGuiExt::InfoTooltip(hex::format("{0}\n\nCommit: {1}@{2}", "hex.builtin.welcome.nightly_build"_lang, ImHexApi::System::getCommitBranch(), ImHexApi::System::getCommitHash(true)).c_str());
ImGui::SetCursorPos(cursor);
@@ -344,7 +344,7 @@ namespace hex::plugin::builtin {
ImGuiExt::EndSubWindow();
}
if (s_infoBannerTexture.isValid()) {
if (s_infoBannerTexture->isValid()) {
static bool hovered = false;
ImGui::PushStyleColor(ImGuiCol_Border, ImGui::GetStyleColorVec4(hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Border));
@@ -352,7 +352,7 @@ namespace hex::plugin::builtin {
if (ImGuiExt::BeginSubWindow("hex.builtin.welcome.header.info"_lang, nullptr, ImVec2(), ImGuiChildFlags_AutoResizeX)) {
const auto height = 80_scaled;
ImGui::Image(s_infoBannerTexture, ImVec2(height * s_infoBannerTexture.getAspectRatio(), height));
ImGui::Image(*s_infoBannerTexture, ImVec2(height * s_infoBannerTexture->getAspectRatio(), height));
hovered = ImGui::IsItemHovered();
if (ImGui::IsItemClicked()) {
@@ -464,7 +464,7 @@ namespace hex::plugin::builtin {
auto imagePos = (ImGui::GetContentRegionAvail() - imageSize) / 2;
ImGui::SetCursorPos(imagePos);
ImGui::Image(s_backdropTexture, imageSize);
ImGui::Image(*s_backdropTexture, imageSize);
auto loadDefaultText = "hex.builtin.layouts.none.restore_default"_lang;
auto textSize = ImGui::CalcTextSize(loadDefaultText);
@@ -544,7 +544,7 @@ namespace hex::plugin::builtin {
s_nightlyTexture = changeTextureSvg(hex::format("assets/{}/nightly.svg", "common"), 35_scaled);
s_backdropTexture = changeTexture(hex::format("assets/{}/backdrop.png", ThemeManager::getImageTheme()));
if (!s_bannerTexture.isValid()) {
if (!s_bannerTexture->isValid()) {
log::error("Failed to load banner texture!");
}
});
@@ -671,14 +671,14 @@ namespace hex::plugin::builtin {
if (wolv::io::fs::exists(infoBannerPath)) {
s_infoBannerTexture = ImGuiExt::Texture::fromImage(infoBannerPath, ImGuiExt::Texture::Filter::Linear);
if (s_infoBannerTexture.isValid())
if (s_infoBannerTexture->isValid())
break;
}
}
auto allowNetworking = ContentRegistry::Settings::read<bool>("hex.builtin.setting.general", "hex.builtin.setting.general.network_interface", false)
&& ContentRegistry::Settings::read<int>("hex.builtin.setting.general", "hex.builtin.setting.general.server_contact", 0) != 0;
if (!s_infoBannerTexture.isValid() && allowNetworking) {
if (!s_infoBannerTexture->isValid() && allowNetworking) {
TaskManager::createBackgroundTask("hex.builtin.task.loading_banner"_lang, [](auto&) {
HttpRequest request("GET",
ImHexApiURL + hex::format("/info/{}/image", hex::toLower(ImHexApi::System::getOSName())));

View File

@@ -15,6 +15,7 @@
#include <fonts/vscode_icons.hpp>
#include <hex/api/tutorial_manager.hpp>
#include <hex/helpers/auto_reset.hpp>
#include <romfs/romfs.hpp>
#include <wolv/utils/guards.hpp>
@@ -27,7 +28,7 @@ namespace hex::plugin::builtin {
std::string s_windowTitle, s_windowTitleFull;
u32 s_searchBarPosition = 0;
ImGuiExt::Texture s_logoTexture;
AutoReset<ImGuiExt::Texture> s_logoTexture;
bool s_showSearchBar = true;
bool s_displayShortcutHighlights = true;
bool s_useNativeMenuBar = false;