mirror of
https://github.com/UberGames/lilium-voyager.git
synced 2024-11-14 00:10:39 +00:00
Add some checks when reloading QVMs via VM_Restart()
This commit is contained in:
parent
acc2da023c
commit
d176ebe84a
1 changed files with 43 additions and 14 deletions
|
@ -447,13 +447,26 @@ vmHeader_t *VM_LoadQVM( vm_t *vm, qboolean alloc ) {
|
||||||
}
|
}
|
||||||
dataLength = 1 << i;
|
dataLength = 1 << i;
|
||||||
|
|
||||||
if( alloc ) {
|
if(alloc)
|
||||||
|
{
|
||||||
// allocate zero filled space for initialized and uninitialized data
|
// allocate zero filled space for initialized and uninitialized data
|
||||||
vm->dataBase = Hunk_Alloc( dataLength, h_high );
|
vm->dataBase = Hunk_Alloc(dataLength, h_high);
|
||||||
vm->dataMask = dataLength - 1;
|
vm->dataMask = dataLength - 1;
|
||||||
} else {
|
}
|
||||||
// clear the data
|
else
|
||||||
Com_Memset( vm->dataBase, 0, dataLength );
|
{
|
||||||
|
// clear the data, but make sure we're not clearing more than allocated
|
||||||
|
if(vm->dataMask + 1 != dataLength)
|
||||||
|
{
|
||||||
|
VM_Free(vm);
|
||||||
|
FS_FreeFile(header.v);
|
||||||
|
|
||||||
|
Com_Printf(S_COLOR_YELLOW "Warning: Data region size of %s not matching after"
|
||||||
|
"VM_Restart()\n", filename);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
Com_Memset(vm->dataBase, 0, dataLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy the intialized data
|
// copy the intialized data
|
||||||
|
@ -465,18 +478,34 @@ vmHeader_t *VM_LoadQVM( vm_t *vm, qboolean alloc ) {
|
||||||
*(int *)(vm->dataBase + i) = LittleLong( *(int *)(vm->dataBase + i ) );
|
*(int *)(vm->dataBase + i) = LittleLong( *(int *)(vm->dataBase + i ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( header.h->vmMagic == VM_MAGIC_VER2 ) {
|
if(header.h->vmMagic == VM_MAGIC_VER2)
|
||||||
vm->numJumpTableTargets = header.h->jtrgLength >> 2;
|
{
|
||||||
Com_Printf( "Loading %d jump table targets\n", vm->numJumpTableTargets );
|
Com_Printf("Loading %d jump table targets\n", vm->numJumpTableTargets);
|
||||||
|
|
||||||
if( alloc ) {
|
header.h->jtrgLength &= ~0x03;
|
||||||
vm->jumpTableTargets = Hunk_Alloc( header.h->jtrgLength, h_high );
|
|
||||||
} else {
|
if(alloc)
|
||||||
Com_Memset( vm->jumpTableTargets, 0, header.h->jtrgLength );
|
{
|
||||||
|
vm->jumpTableTargets = Hunk_Alloc(header.h->jtrgLength, h_high);
|
||||||
|
vm->numJumpTableTargets = header.h->jtrgLength >> 2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if((header.h->jtrgLength >> 2) != vm->numJumpTableTargets)
|
||||||
|
{
|
||||||
|
VM_Free(vm);
|
||||||
|
FS_FreeFile(header.v);
|
||||||
|
|
||||||
|
Com_Printf(S_COLOR_YELLOW "Warning: Jump table size of %s not matching after"
|
||||||
|
"VM_Restart()\n", filename);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Com_Memcpy( vm->jumpTableTargets, (byte *)header.h + header.h->dataOffset +
|
Com_Memset(vm->jumpTableTargets, 0, header.h->jtrgLength);
|
||||||
header.h->dataLength + header.h->litLength, header.h->jtrgLength );
|
}
|
||||||
|
|
||||||
|
Com_Memcpy(vm->jumpTableTargets, (byte *) header.h + header.h->dataOffset +
|
||||||
|
header.h->dataLength + header.h->litLength, header.h->jtrgLength);
|
||||||
|
|
||||||
// byte swap the longs
|
// byte swap the longs
|
||||||
for ( i = 0 ; i < header.h->jtrgLength ; i += 4 ) {
|
for ( i = 0 ; i < header.h->jtrgLength ; i += 4 ) {
|
||||||
|
|
Loading…
Reference in a new issue