wined3d: Handle error conditions better in RemoveContextFromArray().
This commit is contained in:
parent
695c69f6a0
commit
4e2c87dd22
|
@ -919,31 +919,50 @@ out:
|
||||||
*
|
*
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
static void RemoveContextFromArray(IWineD3DDeviceImpl *This, WineD3DContext *context) {
|
static void RemoveContextFromArray(IWineD3DDeviceImpl *This, WineD3DContext *context) {
|
||||||
UINT t, s;
|
WineD3DContext **new_array;
|
||||||
WineD3DContext **oldArray = This->contexts;
|
BOOL found = FALSE;
|
||||||
|
UINT i;
|
||||||
|
|
||||||
TRACE("Removing ctx %p\n", context);
|
TRACE("Removing ctx %p\n", context);
|
||||||
|
|
||||||
This->numContexts--;
|
for (i = 0; i < This->numContexts; ++i)
|
||||||
|
{
|
||||||
if(This->numContexts) {
|
if (This->contexts[i] == context)
|
||||||
This->contexts = HeapAlloc(GetProcessHeap(), 0, sizeof(*This->contexts) * This->numContexts);
|
{
|
||||||
if(!This->contexts) {
|
|
||||||
ERR("Cannot allocate a new context array, PANIC!!!\n");
|
|
||||||
}
|
|
||||||
t = 0;
|
|
||||||
/* Note that we decreased numContexts a few lines up, so use '<=' instead of '<' */
|
|
||||||
for(s = 0; s <= This->numContexts; s++) {
|
|
||||||
if(oldArray[s] == context) continue;
|
|
||||||
This->contexts[t] = oldArray[s];
|
|
||||||
t++;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
This->contexts = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
HeapFree(GetProcessHeap(), 0, context);
|
HeapFree(GetProcessHeap(), 0, context);
|
||||||
HeapFree(GetProcessHeap(), 0, oldArray);
|
found = TRUE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!found)
|
||||||
|
{
|
||||||
|
ERR("Context %p doesn't exist in context array\n", context);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (i < This->numContexts - 1)
|
||||||
|
{
|
||||||
|
This->contexts[i] = This->contexts[i + 1];
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
|
||||||
|
--This->numContexts;
|
||||||
|
if (!This->numContexts)
|
||||||
|
{
|
||||||
|
HeapFree(GetProcessHeap(), 0, This->contexts);
|
||||||
|
This->contexts = NULL;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
new_array = HeapReAlloc(GetProcessHeap(), 0, This->contexts, This->numContexts * sizeof(*This->contexts));
|
||||||
|
if (!new_array)
|
||||||
|
{
|
||||||
|
ERR("Failed to shrink context array. Oh well.\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
This->contexts = new_array;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
|
|
Loading…
Reference in New Issue