From eadfea9d631f6596c503e15082b33d587ce1758b Mon Sep 17 00:00:00 2001 From: Aaldert Date: Tue, 21 Jun 2016 14:45:41 +0200 Subject: [PATCH] Sound pointers worden gedelete --- Enemy.cpp | 2 +- Portal.cpp | 3 +-- SoundSystem.cpp | 8 ++++++++ SoundSystem.h | 1 + World.cpp | 9 ++++----- World.h | 2 +- 6 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Enemy.cpp b/Enemy.cpp index 664dc3c..df5107a 100644 --- a/Enemy.cpp +++ b/Enemy.cpp @@ -30,7 +30,7 @@ Enemy::~Enemy() if (model) Model::unload(model); - delete music; + CrystalPoint::GetSoundSystem().UnloadSound(hit_sound_id); } void Enemy::draw() diff --git a/Portal.cpp b/Portal.cpp index fcd2f07..a5015d4 100644 --- a/Portal.cpp +++ b/Portal.cpp @@ -30,7 +30,7 @@ Portal::Portal(const std::string &fileName, Portal::~Portal() { // Model::unload(model); -// delete music; + CrystalPoint::GetSoundSystem().UnloadSound(sound_id); } void Portal::collide() @@ -46,7 +46,6 @@ bool Portal::enter(float deltaTime) { if (delay > 3 && started) { - delete music; delay = 0; return true; } diff --git a/SoundSystem.cpp b/SoundSystem.cpp index f57a526..df8ab36 100644 --- a/SoundSystem.cpp +++ b/SoundSystem.cpp @@ -48,3 +48,11 @@ Sound* SoundSystem::GetSound(unsigned int inID) return nullptr; return sounds[inID]; } + +void SoundSystem::UnloadSound(unsigned int inID) +{ + if (inID > sounds.size()) + return; + delete sounds[inID]; +// sounds.erase[inID]; +} diff --git a/SoundSystem.h b/SoundSystem.h index b9e289b..1d29dcd 100644 --- a/SoundSystem.h +++ b/SoundSystem.h @@ -24,6 +24,7 @@ public: unsigned int LoadSound(const char* inWavPath, bool inLooping); Sound* GetSound(unsigned int inID); + void UnloadSound(unsigned int inID); private: ALCdevice* device; diff --git a/World.cpp b/World.cpp index 550f400..79e0d46 100644 --- a/World.cpp +++ b/World.cpp @@ -8,8 +8,7 @@ #include #include "WorldHandler.h" -World::World(const std::string &fileName): - music_id(-1) +World::World(const std::string &fileName) { nextworld = false; @@ -183,8 +182,8 @@ World::World(const std::string &fileName): if (!v["world"]["music"].isNull()) { - music_id = CrystalPoint::GetSoundSystem().LoadSound(v["world"]["music"].asString().c_str(), true); - music = CrystalPoint::GetSoundSystem().GetSound(music_id); + sound_id = CrystalPoint::GetSoundSystem().LoadSound(v["world"]["music"].asString().c_str(), true); + music = CrystalPoint::GetSoundSystem().GetSound(sound_id); } if (!v["portal"].isNull()) @@ -218,7 +217,7 @@ World::~World() { delete heightmap; music->Stop(); - delete music; + CrystalPoint::GetSoundSystem().UnloadSound(sound_id); delete skybox; delete portal; } diff --git a/World.h b/World.h index 523c5c1..9dbebcf 100644 --- a/World.h +++ b/World.h @@ -27,7 +27,7 @@ private: bool nextworld; - int music_id,maxCrystals,maxEnemies; + int sound_id,maxCrystals,maxEnemies; std::vector entities; std::vector enemies;