From 2090e689390d2f93df0230fcbd586e47f1d5acc4 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 10 Dec 2017 19:36:54 -0800 Subject: [PATCH] Clean up sources and buffers when destroying the context --- src/context.cpp | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/context.cpp b/src/context.cpp index efb5d51..41ff967 100644 --- a/src/context.cpp +++ b/src/context.cpp @@ -728,8 +728,6 @@ void ContextImpl::destroy() { if(mRefs != 0) throw std::runtime_error("Context is in use"); - if(!mBuffers.empty()) - throw std::runtime_error("Trying to destroy a context with buffers"); if(mThread.joinable()) { @@ -740,6 +738,37 @@ void ContextImpl::destroy() mThread.join(); } + std::unique_lock lock(gGlobalCtxMutex); + if(UNLIKELY(alcMakeContextCurrent(getALCcontext()) == ALC_FALSE)) + std::cerr<< "Failed to cleanup context!" <getId(); + alDeleteBuffers(1, &id); + } + mBuffers.clear(); + + ALCcontext *alctx = sCurrentCtx ? sCurrentCtx->getALCcontext() : nullptr; + if(UNLIKELY(alcMakeContextCurrent(alctx) == ALC_FALSE)) + std::cerr<< "Failed to reset global context!" <getALCcontext(); + if(UNLIKELY(DeviceManagerImpl::SetThreadContext(alctx) == ALC_FALSE)) + std::cerr<< "Failed to reset thread context!" <