[host] dxgi: check for correct comRef usage

This commit is contained in:
Geoffrey McRae 2023-10-29 20:29:14 +11:00
parent c591f7a8ae
commit 52410beea7
2 changed files with 20 additions and 1 deletions

View File

@ -32,12 +32,16 @@ typedef struct
} }
COMRef; COMRef;
static bool comInit = false;
static int comScope = -1; static int comScope = -1;
static Vector comObjectsLocal = {0}; static Vector comObjectsLocal = {0};
static Vector comObjectsGlobal = {0}; static Vector comObjectsGlobal = {0};
bool comRef_init(unsigned globals, unsigned locals) bool comRef_init(unsigned globals, unsigned locals)
{ {
if (comInit)
return true;
if (!vector_create(&comObjectsGlobal, sizeof(COMRef), globals)) if (!vector_create(&comObjectsGlobal, sizeof(COMRef), globals))
return false; return false;
@ -47,11 +51,15 @@ bool comRef_init(unsigned globals, unsigned locals)
return false; return false;
} }
comInit = true;
return true; return true;
} }
void comRef_free(void) void comRef_free(void)
{ {
if (!comInit)
return;
COMRef * ref; COMRef * ref;
if (comScope > -1) if (comScope > -1)
@ -74,10 +82,13 @@ void comRef_free(void)
comScope = -1; comScope = -1;
vector_destroy(&comObjectsLocal); vector_destroy(&comObjectsLocal);
vector_destroy(&comObjectsGlobal); vector_destroy(&comObjectsGlobal);
comInit = false;
} }
static IUnknown ** comRef_new(Vector * vector, IUnknown *** dst) 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 // 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 // address it will invalidate any external pointers to members in it
DEBUG_ASSERT(vector_size(vector) < vector_capacity(vector) && DEBUG_ASSERT(vector_size(vector) < vector_capacity(vector) &&
@ -112,10 +123,15 @@ IUnknown ** comRef_newLocal(IUnknown *** dst)
return ret; return ret;
} }
void comRef_scopePush(void) { ++comScope; } void comRef_scopePush(void)
{
DEBUG_ASSERT(comInit && "comRef has not been initialized");
++comScope;
}
void comRef_scopePop(void) void comRef_scopePop(void)
{ {
DEBUG_ASSERT(comInit && "comRef has not been initialized");
DEBUG_ASSERT(comScope >= 0); DEBUG_ASSERT(comScope >= 0);
COMRef * ref; COMRef * ref;

View File

@ -58,6 +58,9 @@ IUnknown ** comRef_newLocal(IUnknown *** dst);
*/ */
inline static ULONG comRef_release(IUnknown ** ref) inline static ULONG comRef_release(IUnknown ** ref)
{ {
if (!ref)
return 0;
ULONG count = 0; ULONG count = 0;
if (*ref) if (*ref)
count = IUnknown_Release(*ref); count = IUnknown_Release(*ref);