mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2025-10-30 08:01:28 +00:00
Attempt to fix some lua userdata being corrupted when allocated via PoolAllocator
This commit is contained in:
parent
f4dd4a1be7
commit
811b2e5eee
1 changed files with 10 additions and 0 deletions
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
#include "../cxxutil.hpp"
|
||||
#include "../z_zone.h"
|
||||
#include "../lua_script.h"
|
||||
|
||||
using namespace srb2;
|
||||
|
||||
|
|
@ -117,6 +118,9 @@ void* PoolAllocator::allocate()
|
|||
|
||||
void PoolAllocator::deallocate(void* p)
|
||||
{
|
||||
// Required in case this block is reused
|
||||
LUA_InvalidateUserdata(p);
|
||||
|
||||
FreeBlock* block = reinterpret_cast<FreeBlock*>(p);
|
||||
block->next = head_;
|
||||
head_ = block;
|
||||
|
|
@ -127,6 +131,12 @@ void PoolAllocator::release()
|
|||
ChunkFooter* next = nullptr;
|
||||
for (ChunkFooter* i = first_chunk_; i != nullptr; i = next)
|
||||
{
|
||||
uint8_t *chunk = (uint8_t*)i->start;
|
||||
for (size_t j = 0; j < blocks_; j++)
|
||||
{
|
||||
// Invalidate all blocks that possibly weren't passed to deallocate
|
||||
LUA_InvalidateUserdata(chunk + (j * block_size_));
|
||||
}
|
||||
next = i->next;
|
||||
Z_Free(i->start);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue