mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-24 21:21:04 +00:00
16-byte align frames on the VMFrameStack
- Fixed: Don't assume operator new will return a pointer with 16-byte alignment when allocating a block for the VMFrameStack. Because it seems it's actually guaranteed to be 8-byte aligned. Don't know where I got the idea it would always be 16-byte aligned.
This commit is contained in:
parent
649875b17e
commit
9b81e0e597
2 changed files with 8 additions and 2 deletions
|
@ -682,6 +682,7 @@ struct VMFrame
|
|||
|
||||
VMValue *GetParam() const
|
||||
{
|
||||
assert(((size_t)this & 15) == 0 && "VM frame is unaligned");
|
||||
return (VMValue *)(((size_t)(this + 1) + 15) & ~15);
|
||||
}
|
||||
|
||||
|
@ -789,6 +790,11 @@ private:
|
|||
VMFrame *LastFrame;
|
||||
VM_UBYTE *FreeSpace;
|
||||
int BlockSize;
|
||||
|
||||
void InitFreeSpace()
|
||||
{
|
||||
FreeSpace = (VM_UBYTE *)(((size_t)(this + 1) + 15) & ~15);
|
||||
}
|
||||
};
|
||||
BlockHeader *Blocks;
|
||||
BlockHeader *UnusedBlocks;
|
||||
|
|
|
@ -286,7 +286,7 @@ VMFrame *VMFrameStack::Alloc(int size)
|
|||
block = (BlockHeader *)new VM_UBYTE[blocksize];
|
||||
block->BlockSize = blocksize;
|
||||
}
|
||||
block->FreeSpace = (VM_UBYTE *)block + ((sizeof(BlockHeader) + 15) & ~15);
|
||||
block->InitFreeSpace();
|
||||
block->LastFrame = NULL;
|
||||
block->NextBlock = Blocks;
|
||||
Blocks = block;
|
||||
|
@ -340,7 +340,7 @@ VMFrame *VMFrameStack::PopFrame()
|
|||
{
|
||||
assert(Blocks->NextBlock == NULL);
|
||||
Blocks->LastFrame = NULL;
|
||||
Blocks->FreeSpace = (VM_UBYTE *)Blocks + ((sizeof(BlockHeader) + 15) & ~15);
|
||||
Blocks->InitFreeSpace();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue