allow optional mixes again; fix openal so it can *tell* when it fails to allocate sources, rather than just copying 400 bytes of ununitialized garbage into our managed space

This commit is contained in:
Chris Forbes
2010-02-05 13:05:03 +13:00
parent 20c631a7f9
commit 3b763d00fd
5 changed files with 26 additions and 13 deletions

View File

@@ -136,7 +136,7 @@ namespace OpenRa
{
float volume = 1f;
Dictionary<int, bool> sourcePool = new Dictionary<int, bool>();
const int POOL_SIZE = 100;
const int POOL_SIZE = 32;
public OpenAlSoundEngine()
{
@@ -145,16 +145,18 @@ namespace OpenRa
if (dev == IntPtr.Zero)
throw new InvalidOperationException("Can't create OpenAL device");
var ctx = OpenAlInterop.alcCreateContext(dev, IntPtr.Zero);
if (ctx == IntPtr.Zero)
throw new InvalidOperationException("Can't create OpenAL context");
OpenAlInterop.alcMakeContextCurrent(ctx);
int[] sources = new int[POOL_SIZE];
IntPtr pTemp = Marshal.AllocHGlobal(sizeof(int) * POOL_SIZE);
OpenAlInterop.alGenSources(POOL_SIZE, pTemp);
Marshal.Copy(pTemp, sources, 0, POOL_SIZE);
Marshal.FreeHGlobal(pTemp);
foreach (int source in sources)
for (var i = 0; i < POOL_SIZE; i++)
{
var source = 0;
OpenAlInterop.alGenSources(1, out source);
if (0 != OpenAlInterop.alGetError())
throw new InvalidOperationException("failed generating source {0}".F(i));
sourcePool.Add(source, false);
}
}
int GetSourceFromPool()