Skip to content

Commit

Permalink
fix(core): Fix issues running release build.
Browse files Browse the repository at this point in the history
  • Loading branch information
na2axl committed Nov 5, 2024
1 parent 16e10f3 commit c3643a3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
16 changes: 11 additions & 5 deletions src/Core/Thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ namespace SparkyStudios::Audio::Amplitude::Thread
AmThreadData* data;
};

struct AmMutexHandleData
{
CRITICAL_SECTION cs;
};

static DWORD WINAPI ThreadFunc(LPVOID d)
{
auto* p = static_cast<AmThreadData*>(d);
Expand All @@ -53,8 +58,9 @@ namespace SparkyStudios::Audio::Amplitude::Thread

AmMutexHandle CreateMutex(AmUInt64 spinCount)
{
auto* cs = ampoolnew(eMemoryPoolKind_IO, CRITICAL_SECTION);
AMPLITUDE_ASSERT(::InitializeCriticalSectionAndSpinCount(cs, spinCount) == TRUE);
auto* cs = ampoolnew(eMemoryPoolKind_IO, AmMutexHandleData);
const BOOL res = ::InitializeCriticalSectionAndSpinCount(&cs->cs, spinCount);
AMPLITUDE_ASSERT(res == TRUE);
return static_cast<AmMutexHandle>(cs);
}

Expand All @@ -63,9 +69,9 @@ namespace SparkyStudios::Audio::Amplitude::Thread
if (handle == nullptr)
return;

auto* cs = static_cast<CRITICAL_SECTION*>(handle);
::DeleteCriticalSection(cs);
ampooldelete(eMemoryPoolKind_IO, CRITICAL_SECTION, cs);
auto* cs = static_cast<AmMutexHandleData*>(handle);
::DeleteCriticalSection(&cs->cs);
ampooldelete(eMemoryPoolKind_IO, AmMutexHandleData, cs);
}

void LockMutex(AmMutexHandle handle)
Expand Down
6 changes: 3 additions & 3 deletions src/Mixer/Amplimix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ namespace SparkyStudios::Audio::Amplitude
}

private:
AmplimixImpl* m_mixer;
AmplimixImpl* m_mixer = nullptr;
bool m_locked = false;
};

Expand Down Expand Up @@ -1110,7 +1110,7 @@ namespace SparkyStudios::Audio::Amplitude
if (_audioThreadMutex)
Thread::LockMutex(_audioThreadMutex);

_insideAudioThreadMutex[Thread::GetCurrentThreadId()] = true;
_insideAudioThreadMutex.insert_or_assign(Thread::GetCurrentThreadId(), true);
}

void AmplimixImpl::UnlockAudioMutex()
Expand All @@ -1120,7 +1120,7 @@ namespace SparkyStudios::Audio::Amplitude
if (_audioThreadMutex)
Thread::UnlockMutex(_audioThreadMutex);

_insideAudioThreadMutex[Thread::GetCurrentThreadId()] = false;
_insideAudioThreadMutex.insert_or_assign(Thread::GetCurrentThreadId(), false);
}

AmplimixLayerImpl::~AmplimixLayerImpl()
Expand Down

0 comments on commit c3643a3

Please sign in to comment.