Skip to content

Commit

Permalink
gonna go insane finding this memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
Kade-github committed Apr 25, 2024
1 parent 957a5f2 commit 078e68b
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/Game/Objects/Base/Block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ BlockFace Block::BreakBottomFace()
return BlockFace(bottomVertices, { 0, 1, 3, 1, 2, 3 });
}

Block::~Block()
{
faces.clear();
}

void Block::Draw(std::vector<GameObject::VVertex>& verts, std::vector<unsigned int>& inds)
{
for (int i = 0; i < faces.size(); i++)
Expand Down
5 changes: 3 additions & 2 deletions src/Game/Objects/Base/Block.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
#include "../../Data/World.h"
#include <OpenGL/Texture.h>

class BlockFace {
public:
struct BlockFace {
glm::vec3 position;
glm::vec3 sum;
std::vector<GameObject::VVertex> vertices;
Expand Down Expand Up @@ -122,6 +121,8 @@ class Block
BlockFace BreakTopFace();
BlockFace BreakBottomFace();

~Block();

virtual void OnInteract() {};

virtual bool Update(int tick) { return true; };
Expand Down
12 changes: 12 additions & 0 deletions src/Game/Objects/Base/Chunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,18 @@ void Chunk::Destroy()
void Chunk::Unload()
{
DestroySubChunks();

vertices.clear();
indices.clear();

transparentVertices.clear();
transparentIndices.clear();

shadowVertices.clear();
shadowIndices.clear();

size = 0;
shadowSize = 0;
}

void Chunk::DrawRegular()
Expand Down
5 changes: 3 additions & 2 deletions src/Game/Scenes/Gameplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ Gameplay::Gameplay(WorldManager* _wm)

void Gameplay::Create()
{
CraftingManager::GetInstance()->Init();

Game::instance->log->Write("Loaded World: " + wm->name);

Expand Down Expand Up @@ -337,7 +336,7 @@ void Gameplay::UpdateChunks()

float distanceToCenter = glm::distance(fakePos, glm::vec3(r.startX + (regionSize / 2), 0, r.startZ + (regionSize / 2)));

if (distanceToCenter > camera->cameraFar * 4.0f && r.loaded)
if (distanceToCenter > camera->cameraFar * 3.0f && r.loaded)
{
wm->SaveRegion(r.startX, r.startZ);

Expand Down Expand Up @@ -657,6 +656,8 @@ void Gameplay::Destroy()
c->Unload();
delete c;
}

r.chunks.clear();
}

wm->regions.clear();
Expand Down
3 changes: 3 additions & 0 deletions src/Game/Scenes/MainMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
#include <Helpers/Collision2D.h>
#include "../MusicManager.h"
#include "BlockTest.h"
#include "../CraftingManager.h"

void MainMenu::Create()
{
CraftingManager::GetInstance()->Init();

c2d = new Camera2D(glm::vec3(0, 0, 0));

c2d->s = new Shader();
Expand Down
5 changes: 5 additions & 0 deletions src/Game/WorldManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ void WorldManager::CheckGeneratedRegions()
}
}

WorldManager::~WorldManager()
{
instance = nullptr;
}

void WorldManager::GenerateRegion(int x, int z)
{
Data::Region r = _world.generateRegion(x, z);
Expand Down
2 changes: 2 additions & 0 deletions src/Game/WorldManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ class WorldManager

void CheckGeneratedRegions();

~WorldManager();

bool IsRegionGenerated(int x, int z);
bool isRegionLoaded(float x, float z);
void LoadRegion(int x, int z);
Expand Down

0 comments on commit 078e68b

Please sign in to comment.