Skip to content
This repository has been archived by the owner on Jul 15, 2020. It is now read-only.

Commit

Permalink
Update SoundBuffer.cpp
Browse files Browse the repository at this point in the history
Refractor code
  • Loading branch information
Valentyn Bondarenko authored Jun 22, 2018
1 parent 1d512a6 commit 001b24d
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Source/SoundType/SoundBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,23 @@ namespace onesnd

xaBuffer = XABuffer::create(this, strm->Size(), strm);
strm->CloseStream(); // close this manually, otherwise we get a nasty error when the dtor runs...

return xaBuffer != nullptr;
}

bool SoundBuffer::Unload()
{
if (!xaBuffer)
return true; // yes, its unloaded

if (referance_count > 0)
{
//indebug(printf("SoundBuffer::Unload() Memory Leak: failed to delete alBuffer, because it's still in use.\n"));
return false; // can't do anything here while still referenced
}

XABuffer::destroy(xaBuffer);

return true;
}

Expand All @@ -134,6 +138,7 @@ namespace onesnd

so->getSource()->SubmitSourceBuffer(xaBuffer); // enqueue this buffer
++referance_count;

return true;
}

Expand All @@ -144,8 +149,10 @@ namespace onesnd
so->getSource()->Stop(); // make sure its stopped (otherwise Flush won't work)
if (XABuffer::getBuffersQueued(so->getSource()))
so->getSource()->FlushSourceBuffers(); // ensure not in queue anymore

--referance_count;
}

return true;
}

Expand All @@ -159,6 +166,7 @@ namespace onesnd
so->getSource()->FlushSourceBuffers();

so->getSource()->SubmitSourceBuffer(xaBuffer);

return true;
}
}
}

0 comments on commit 001b24d

Please sign in to comment.