Fixed memory issue.

This commit is contained in:
2025-01-03 20:39:35 -05:00
parent 283678e257
commit 84c552c5b8
5 changed files with 15 additions and 7 deletions

View File

@@ -22,7 +22,7 @@ CPMAddPackage(
URL https://git.redacted.cc/Redacted/ReWindow/archive/Prerelease-26.zip
)
set(CMAKE_CXX_FLAGS "-O3 -Wall -Wextra")
#set(CMAKE_CXX_FLAGS "-O3 -Wall -Wextra")
file(GLOB_RECURSE HEADERS "include/*.h" "include/*.hpp")
file(GLOB_RECURSE SOURCES "src/*.c" "src/*.cpp")

View File

@@ -9,7 +9,7 @@ namespace Engine {
class Engine::InstancedTexture {
protected:
JGL::Texture* texture;
JGL::Texture* texture = nullptr;
std::vector<const InstancedSprite*> users{};
public:
[[nodiscard]] size_t ReferenceCount() { return users.size(); }

View File

@@ -3,13 +3,22 @@
using namespace Engine;
Texture* InstancedSprite::GetTexture() {
return Globals::CurrentScene->GetInstancedTexture(this)->GetTexture();
auto* itx = Globals::CurrentScene->GetInstancedTexture(this);
if (itx)
return itx->GetTexture();
return nullptr;
}
Texture* InstancedSprite::GetAlphaMask() {
if (Sprite::GetAlphaMask())
return Sprite::GetAlphaMask();
return Globals::CurrentScene->GetInstancedAlphaMask(this)->GetTexture();
auto* ita = Globals::CurrentScene->GetInstancedAlphaMask(this);
if (ita)
return ita->GetTexture();
return nullptr;
}
InstancedSprite::~InstancedSprite() {

View File

@@ -167,10 +167,10 @@ InstancedTexture* Scene::GetInstancedAlphaMask(const InstancedSprite* user) {
if (itx->InUseBy(user))
return itx;
if (!user->GetAlphaMaskFilesystemPath().empty()) {
if (!user->GetAlphaMaskFilesystemPath().empty() && !instanced_alpha_masks.empty()) {
auto *t = new Texture(user->GetTextureFilesystemPath());
auto *itx = new InstancedTexture(t, user);
instanced_textures.push_back(itx);
instanced_alpha_masks.push_back(itx);
return itx;
}
return nullptr;

View File

@@ -1,6 +1,5 @@
#include <Game/entity/Box.h>
#include <Engine/Globals.h>
#include <JGL/JGL.h>
void Game::Box::Update() {
if (Globals::Window->IsKeyDown(Keys::W))