From 544befe162d3d7a3647c6f40ae61c7cdf994baf4 Mon Sep 17 00:00:00 2001 From: Zero <128979226+lux-zero-161@users.noreply.github.com> Date: Tue, 26 May 2026 14:47:43 +0200 Subject: [PATCH 1/2] Fix multiple memory leaks and stale pooled allocations (#123) --- Minecraft.Client/GuiParticles.cpp | 10 ++++++++++ Minecraft.Client/GuiParticles.h | 1 + Minecraft.Client/Minecraft.cpp | 5 +++-- Minecraft.Client/Screen.cpp | 12 ++++++++++++ Minecraft.Client/Screen.h | 1 + Minecraft.World/AABB.cpp | 6 ++++++ Minecraft.World/Vec3.cpp | 6 ++++++ 7 files changed, 39 insertions(+), 2 deletions(-) diff --git a/Minecraft.Client/GuiParticles.cpp b/Minecraft.Client/GuiParticles.cpp index 79240288..864ea29e 100644 --- a/Minecraft.Client/GuiParticles.cpp +++ b/Minecraft.Client/GuiParticles.cpp @@ -8,6 +8,15 @@ GuiParticles::GuiParticles(Minecraft *mc) this->mc = mc; } +GuiParticles::~GuiParticles() +{ + for (GuiParticle *gp : particles) + { + delete gp; + } + particles.clear(); +} + void GuiParticles::tick() { for (unsigned int i = 0; i < particles.size(); i++) @@ -19,6 +28,7 @@ void GuiParticles::tick() if (gp->removed) { + delete gp; particles.erase(particles.begin()+i); i--; } diff --git a/Minecraft.Client/GuiParticles.h b/Minecraft.Client/GuiParticles.h index 0fe31811..cbfc089d 100644 --- a/Minecraft.Client/GuiParticles.h +++ b/Minecraft.Client/GuiParticles.h @@ -13,6 +13,7 @@ private: public: GuiParticles(Minecraft *mc); + ~GuiParticles(); void tick(); void add(GuiParticle *guiParticle); void render(float a); diff --git a/Minecraft.Client/Minecraft.cpp b/Minecraft.Client/Minecraft.cpp index 578a9479..886b96a9 100644 --- a/Minecraft.Client/Minecraft.cpp +++ b/Minecraft.Client/Minecraft.cpp @@ -526,9 +526,10 @@ LevelStorageSource *Minecraft::getLevelSource() void Minecraft::setScreen(Screen *screen) { - if (this->screen != nullptr) + Screen *oldScreen = this->screen; + if (oldScreen != nullptr) { - this->screen->removed(); + oldScreen->removed(); } #ifdef _WINDOWS64 diff --git a/Minecraft.Client/Screen.cpp b/Minecraft.Client/Screen.cpp index 071b42cc..38a645bb 100644 --- a/Minecraft.Client/Screen.cpp +++ b/Minecraft.Client/Screen.cpp @@ -23,6 +23,18 @@ Screen::Screen() // 4J added clickedButton = nullptr; } +Screen::~Screen() +{ + delete particles; + particles = nullptr; + + for (Button *button : buttons) + { + delete button; + } + buttons.clear(); +} + void Screen::render(int xm, int ym, float a) { for (Button* button : buttons) diff --git a/Minecraft.Client/Screen.h b/Minecraft.Client/Screen.h index 6b2cb945..04f9296d 100644 --- a/Minecraft.Client/Screen.h +++ b/Minecraft.Client/Screen.h @@ -22,6 +22,7 @@ public: GuiParticles *particles; Screen(); // 4J added + virtual ~Screen(); virtual void render(int xm, int ym, float a); protected: virtual void keyPressed(wchar_t eventCharacter, int eventKey); diff --git a/Minecraft.World/AABB.cpp b/Minecraft.World/AABB.cpp index af0501b4..b6fc1375 100644 --- a/Minecraft.World/AABB.cpp +++ b/Minecraft.World/AABB.cpp @@ -54,10 +54,16 @@ AABB *AABB::newPermanent(double x0, double y0, double z0, double x1, double y1, void AABB::clearPool() { + ThreadStorage *tls = static_cast(TlsGetValue(tlsIdx)); + if (tls != nullptr) + { + tls->poolPointer = 0; + } } void AABB::resetPool() { + clearPool(); } AABB *AABB::newTemp(double x0, double y0, double z0, double x1, double y1, double z1) diff --git a/Minecraft.World/Vec3.cpp b/Minecraft.World/Vec3.cpp index 75619bb0..cc9901a6 100644 --- a/Minecraft.World/Vec3.cpp +++ b/Minecraft.World/Vec3.cpp @@ -49,10 +49,16 @@ Vec3 *Vec3::newPermanent(double x, double y, double z) void Vec3::clearPool() { + ThreadStorage *tls = static_cast(TlsGetValue(tlsIdx)); + if (tls != nullptr) + { + tls->poolPointer = 0; + } } void Vec3::resetPool() { + clearPool(); } Vec3 *Vec3::newTemp(double x, double y, double z) From bb37600c87dee0c0e4ae96444f32f385ff547c49 Mon Sep 17 00:00:00 2001 From: Necmi Date: Tue, 26 May 2026 19:00:08 +0300 Subject: [PATCH 2/2] fix: game startup not checking fullscren values correct (#122) * fix outdated fullscreenload & added a bool to check at startupfullscreen * fix outdated methods & add back accidental deletes + debug things * used old vars & added deleted showwindow & updatewindow * added deleted few things --- .../Windows64/Windows64_Minecraft.cpp | 81 +++++++++++-------- 1 file changed, 46 insertions(+), 35 deletions(-) diff --git a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp index 91fd812f..8e28cb3d 100644 --- a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp +++ b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp @@ -149,47 +149,57 @@ static void CopyWideArgToAnsi(LPCWSTR source, char* dest, size_t destSize) dest[destSize - 1] = 0; } -// ---------- Persistent options (options.txt next to exe) ---------- -static void GetOptionsFilePath(char *out, size_t outSize) +// ---------- Persistent options (options.dat next to exe) ---------- +static void GetOptionsFilePath(char *out, DWORD outSize) { - GetModuleFileNameA(nullptr, out, static_cast(outSize)); - char *p = strrchr(out, '\\'); - if (p) *(p + 1) = '\0'; - strncat_s(out, outSize, "options.txt", _TRUNCATE); + GetModuleFileNameA(nullptr, out, outSize); + char *p = strrchr(out, '\\'); + if (p) *(p + 1) = '\0'; + strncat_s(out, outSize, "settings.dat", _TRUNCATE); } static void SaveFullscreenOption(bool fullscreen) { - char path[MAX_PATH]; - GetOptionsFilePath(path, sizeof(path)); - FILE *f = nullptr; - if (fopen_s(&f, path, "w") == 0 && f) - { - fprintf(f, "fullscreen=%d\n", fullscreen ? 1 : 0); - fclose(f); - } + GAME_SETTINGS settings = {}; + + char path[MAX_PATH] = {}; + GetOptionsFilePath(path, MAX_PATH); + FILE *f = nullptr; + if (fopen_s(&f, path, "rb") == 0 && f) + { + fread(&settings, sizeof(GAME_SETTINGS), 1, f); + fclose(f); + } + + if (fullscreen) + settings.uiBitmaskValues |= (1UL << 25); + else + settings.uiBitmaskValues &= ~(1UL << 25); + + if (fopen_s(&f, path, "wb") == 0 && f) + { + fwrite(&settings, sizeof(GAME_SETTINGS), 1, f); + fclose(f); + } } static bool LoadFullscreenOption() { - char path[MAX_PATH]; + char path[MAX_PATH] = {}; GetOptionsFilePath(path, sizeof(path)); - FILE *f = nullptr; - if (fopen_s(&f, path, "r") == 0 && f) - { - char line[256]; - while (fgets(line, sizeof(line), f)) - { - int val = 0; - if (sscanf_s(line, "fullscreen=%d", &val) == 1) - { - fclose(f); - return val != 0; - } - } - fclose(f); - } - return false; + + FILE *f = nullptr; + if (fopen_s(&f, path, "rb") != 0 || !f) + return false; + + GAME_SETTINGS current = {}; + bool ok = (fread(¤t, sizeof(GAME_SETTINGS), 1, f) == 1); + fclose(f); + + if (!ok) + return false; + + return (current.uiBitmaskValues & (1UL << 25)) != 0; } // ------------------------------------------------------------------ @@ -824,7 +834,7 @@ BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) return FALSE; } - + return TRUE; } @@ -1695,11 +1705,12 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, CleanupDevice(); return 0; } - // Restore fullscreen state from previous session. Route through the // deferred exclusive fullscreen path so the main loop applies it on the // first tick (safer than transitioning during init). - if ((LoadFullscreenOption() && !g_isFullscreen) || launchOptions.fullscreen) + + bool FullScreenEnabled = LoadFullscreenOption(); + if (FullScreenEnabled && !g_isFullscreen) { g_bPendingExclusiveFullscreen = true; g_bPendingExclusiveFullscreenValue = true; @@ -1764,7 +1775,7 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, return 1; } g_bResizeReady = true; - + //app.TemporaryCreateGameStart(); //Sleep(10000);