Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stops objects from leaking into the void by marking them as free if they existed prior to the loading #1508

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Scripts/refactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@ def process(line):
line = line.replace("LOBYTE(field_6_flags) |= 4u", "field_6_flags.Set(BaseGameObject::eDead_Bit3)")

line = line.replace("1835626049", "ResourceManager::Resource_Animation")
line = line.replace("0x746C6150", "ResourceManager::Resource_Animation")
line = line.replace("0x6D696E41", "ResourceManager::Resource_Animation")
line = line.replace("'minA'", "ResourceManager::Resource_Animation")

line = line.replace("1953259856", "ResourceManager::Resource_Palt")
line = line.replace("0x6D696E41", "ResourceManager::Resource_Animation")
line = line.replace("0x746C6150", "ResourceManager::Resource_Palt")
line = line.replace("'tlaP'", "ResourceManager::Resource_Palt")


Expand Down
15 changes: 11 additions & 4 deletions Source/AliveLibAO/ResourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ void CC ResourceManager::On_Loaded_446C10(ResourceManager_FileRecord* pLoaded)

// pLoaded is done with now, remove it
ObjList_5009E0->Remove_Item(pLoaded);

if (pLoaded)
{
// And destruct/free it
Expand Down Expand Up @@ -401,7 +401,7 @@ void CC ResourceManager::LoadResourcesFromList_446E80(const char_type* pFileName
bool allResourcesLoaded = true;
for (s32 i = 0; i < pTypeAndIdList->field_0_count; i++)
{
while (!ResourceManager::GetLoadedResource_4554F0(
if (!ResourceManager::GetLoadedResource_4554F0(
pTypeAndIdList->field_4_items[i].field_0_type,
pTypeAndIdList->field_4_items[i].field_4_res_id,
0,
Expand Down Expand Up @@ -791,7 +791,7 @@ EXPORT u8** CC ResourceManager::Allocate_New_Block_454FE0(u32 sizeBytes, BlockAl
{
ResourceHeapItem* pListItem = sFirstLinkedListItem_50EE2C;
ResourceHeapItem* pHeapMem = nullptr;
const u32 size = (sizeBytes + 3) & ~3u; // Rounding ??
const u32 size = (sizeBytes + 3) & ~3u; // Align to a multiple of 4
Header* pHeaderToUse = nullptr;
while (pListItem)
{
Expand Down Expand Up @@ -934,19 +934,26 @@ s16 CC ResourceManager::Move_Resources_To_DArray_455430(u8** ppRes, DynamicArray
{
auto pItemToAdd = (ResourceHeapItem*) ppRes;
Header* pHeader = Get_Header_455620(ppRes);
u8** pFoundResourceInList = nullptr;
if (pHeader->field_8_type != Resource_End)
{
while (pHeader->field_8_type != Resource_Pend
&& pHeader->field_0_size
&& !(pHeader->field_0_size & 3))
{
if (pArray)
if (pFoundResourceInList) // If we already found it in the list already and incremented the ref count, so mark this as free
{
pHeader->field_8_type = Resource_Free;
}
else if (pArray)
{
pArray->Push_Back((u8**) pItemToAdd);
pHeader->field_4_ref_count++;
}

pHeader = (Header*) ((s8*) pHeader + pHeader->field_0_size);

pFoundResourceInList = GetLoadedResource_4554F0(pHeader->field_8_type, pHeader->field_C_id, 1, 0);

// Out of heap space
if (pHeader->field_0_size >= kResHeapSize)
Expand Down
2 changes: 2 additions & 0 deletions Source/AliveLibAO/ResourceManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class ResourceManager final
Resource_End = 0x21646E45,
Resource_Plbk = 0x6B626C50,
Resource_Play = 0x79616C50,
Resource_Indx = 0x78646E49,
Resource_Seq = 0x20716553,
};

enum ResourceHeaderFlags : s16
Expand Down
2 changes: 1 addition & 1 deletion get_sdl2_win32.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ If(!(test-path build\SDL2))
Write-Host Creating build\SDL2
New-Item -ItemType Directory -Force -Path build\SDL2
Write-Host Download ZIP
Invoke-WebRequest -Uri 'https://www.libsdl.org/release/SDL2-devel-2.0.8-VC.zip' -OutFile 'build\SDL2.zip'
Invoke-WebRequest -Uri 'https://www.libsdl.org/release/SDL2-devel-2.0.22-VC.zip' -OutFile 'build\SDL2.zip'
Write-Host Extract zip
Unzip "build\SDL2.zip" "build\SDL2"
}
Expand Down