Skip to content
This repository has been archived by the owner on Aug 23, 2023. It is now read-only.

Commit

Permalink
Fixed free effects error caused by deletion of effect zone after play…
Browse files Browse the repository at this point in the history
…back. Can't delete effect zone during playback.
  • Loading branch information
adct-the-experimenter committed Jun 30, 2021
1 parent f1178ad commit 3153119
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 8 deletions.
35 changes: 29 additions & 6 deletions src/echo-zone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,7 @@ EchoZone::EchoZone() : EffectZone()

EchoZone::~EchoZone()
{
if(m_effect != 0 && m_slot != 0)
{
FreeEffects();
}

}

void EchoZone::InitEchoZone(std::string& thisName,
Expand Down Expand Up @@ -210,16 +207,42 @@ ALuint EchoZone::GetEffectsSlot(){return m_slot;}

void EchoZone::FreeEffects()
{
if(m_effect != 0)
//std::cout << "\nFree effects called!\n";
ALenum err;

err = alGetError();
if(err != AL_NO_ERROR)
{
fprintf(stderr, "1. free effects. value above code wrong. OpenAL error: %s\n", alGetString(err));
}

if(m_effect)
{
alDeleteEffects(1, &m_effect);
m_effect = 0;
}
if(m_slot != 0)

m_effect = 0;

err = alGetError();
if(err != AL_NO_ERROR)
{
fprintf(stderr, "2. free effects. value above code wrong. OpenAL error: %s\n", alGetString(err));
}

if(m_slot)
{
alDeleteAuxiliaryEffectSlots(1, &m_slot);
m_slot = 0;
}

err = alGetError();
if(err != AL_NO_ERROR)
{
fprintf(stderr, "3. free effects. value above code wrong. OpenAL error: %s\n", alGetString(err));
}

m_slot = 0;
}

EchoZoneSaveData EchoZone::GetEchoZoneSaveData()
Expand Down
13 changes: 13 additions & 0 deletions src/effects-manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,3 +444,16 @@ void EffectsManager::SetEffectZonePicked(bool state,EffectZoneType& type, int& i
default:{ break;}
}
}

void EffectsManager::RemoveEffectFromAllSources()
{
for(size_t i = 0; i < m_sound_producer_reg_ptr->sound_producer_vector_ref->size(); i++)
{
SoundProducer* thisSoundProducer = m_sound_producer_reg_ptr->sound_producer_vector_ref->at(i).get();

ALuint* source_ptr = thisSoundProducer->getSource();

EffectsManager::RemoveEffectFromThisSource(source_ptr);
thisSoundProducer->SetEffectAppliedBool(false);
}
}
4 changes: 4 additions & 0 deletions src/effects-manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ class EffectsManager
friend class SaveSystem;
friend class LoadSystem;

void RemoveEffectFromAllSources();

private:

//pointer to manager that contains all soundproducer tracks used
Expand Down Expand Up @@ -101,6 +103,8 @@ class EffectsManager

//std::vector <SoundProducerTrack*> *GetReferenceToSoundProducerTracksVector();
SoundProducerRegistry* m_sound_producer_reg_ptr;


};


Expand Down
12 changes: 12 additions & 0 deletions src/immediate_mode_sound_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ ImmediateModeSoundPlayer::ImmediateModeSoundPlayer()
m_sound_producer_reg_ptr = nullptr;

time_res_seconds = double(TIME_RESOLUTION) / 1000;

player_active_use = false;
}

ImmediateModeSoundPlayer::~ImmediateModeSoundPlayer()
Expand All @@ -37,6 +39,8 @@ void ImmediateModeSoundPlayer::SetPointerToEffectsManager(EffectsManager* effect
local_effect_manager_ptr = effects_manager;
}

bool ImmediateModeSoundPlayer::PlayerInActiveUse(){return player_active_use;}

void ImmediateModeSoundPlayer::RunStateForPlayer()
{

Expand Down Expand Up @@ -119,6 +123,8 @@ void DetermineEffect()

void ImmediateModeSoundPlayer::PlayAll()
{
player_active_use = true;

typedef std::chrono::high_resolution_clock clock;
typedef std::chrono::duration<float, std::milli> duration;

Expand Down Expand Up @@ -243,6 +249,9 @@ void ImmediateModeSoundPlayer::PauseAll()
}

m_current_time += time_res_seconds;

player_active_use = false;
m_effects_manager_ptr->RemoveEffectFromAllSources();
}

}
Expand All @@ -268,6 +277,9 @@ void ImmediateModeSoundPlayer::StopAll()

}

player_active_use = false;
m_effects_manager_ptr->RemoveEffectFromAllSources();

m_current_time = 0;
}

Expand Down
6 changes: 6 additions & 0 deletions src/immediate_mode_sound_player.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class ImmediateModeSoundPlayer

enum class IMSoundPlayerState : std::uint8_t {NONE=0,PLAYING, PAUSED, REWINDING, FAST_FORWARDING };

//function to indicate that player is not in none or paused state.
bool PlayerInActiveUse();

private:

//state of immmediate mode player
Expand Down Expand Up @@ -65,6 +68,9 @@ class ImmediateModeSoundPlayer

//amonut of time to increment for playback
double time_res_seconds;

bool player_active_use;

};

#endif
5 changes: 4 additions & 1 deletion src/main_gui_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,8 @@ static float new_listener_position_x = 0;
static float new_listener_position_y = 0;
static float new_listener_position_z = 0;

static bool sound_player_active = false;

void MainGuiEditor::logic()
{
float dt = GetFrameTime();
Expand Down Expand Up @@ -444,7 +446,7 @@ void MainGuiEditor::logic()

}

if(deleteKeyPressed)
if(deleteKeyPressed && !sound_player_active)
{
if(soundproducer_picked != -1)
{
Expand Down Expand Up @@ -476,6 +478,7 @@ void MainGuiEditor::logic()
//run state for immediate mode sound player
im_sound_player.RunStateForPlayer();

sound_player_active = im_sound_player.PlayerInActiveUse();
}

void MainGuiEditor::DrawGUI_Items()
Expand Down
2 changes: 1 addition & 1 deletion src/reverb-zone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ ALuint ReverbZone::GetEffectsSlot(){return m_slot;}

void ReverbZone::FreeEffects()
{
std::cout << "\nFree effects called!\n";
//std::cout << "\nFree effects called!\n";
ALenum err;

err = alGetError();
Expand Down

0 comments on commit 3153119

Please sign in to comment.