diff --git a/host/platform/Windows/capture/DXGI/src/com_ref.c b/host/platform/Windows/capture/DXGI/src/com_ref.c index 9b42f0b1..3aa1c010 100644 --- a/host/platform/Windows/capture/DXGI/src/com_ref.c +++ b/host/platform/Windows/capture/DXGI/src/com_ref.c @@ -32,12 +32,16 @@ typedef struct } COMRef; +static bool comInit = false; static int comScope = -1; static Vector comObjectsLocal = {0}; static Vector comObjectsGlobal = {0}; bool comRef_init(unsigned globals, unsigned locals) { + if (comInit) + return true; + if (!vector_create(&comObjectsGlobal, sizeof(COMRef), globals)) return false; @@ -47,11 +51,15 @@ bool comRef_init(unsigned globals, unsigned locals) return false; } + comInit = true; return true; } void comRef_free(void) { + if (!comInit) + return; + COMRef * ref; if (comScope > -1) @@ -74,10 +82,13 @@ void comRef_free(void) comScope = -1; vector_destroy(&comObjectsLocal); vector_destroy(&comObjectsGlobal); + comInit = false; } static IUnknown ** comRef_new(Vector * vector, IUnknown *** dst) { + DEBUG_ASSERT(comInit && "comRef has not been initialized"); + // we must not allow the vector to grow as if the realloc moves to a new // address it will invalidate any external pointers to members in it DEBUG_ASSERT(vector_size(vector) < vector_capacity(vector) && @@ -112,10 +123,15 @@ IUnknown ** comRef_newLocal(IUnknown *** dst) return ret; } -void comRef_scopePush(void) { ++comScope; } +void comRef_scopePush(void) +{ + DEBUG_ASSERT(comInit && "comRef has not been initialized"); + ++comScope; +} void comRef_scopePop(void) { + DEBUG_ASSERT(comInit && "comRef has not been initialized"); DEBUG_ASSERT(comScope >= 0); COMRef * ref; diff --git a/host/platform/Windows/capture/DXGI/src/com_ref.h b/host/platform/Windows/capture/DXGI/src/com_ref.h index 2134180b..99ff7fb1 100644 --- a/host/platform/Windows/capture/DXGI/src/com_ref.h +++ b/host/platform/Windows/capture/DXGI/src/com_ref.h @@ -58,6 +58,9 @@ IUnknown ** comRef_newLocal(IUnknown *** dst); */ inline static ULONG comRef_release(IUnknown ** ref) { + if (!ref) + return 0; + ULONG count = 0; if (*ref) count = IUnknown_Release(*ref);