diff options
| author | Léo Lam <leo@leolam.fr> | 2020-09-07 14:38:09 +0200 |
|---|---|---|
| committer | Léo Lam <leo@leolam.fr> | 2020-09-07 14:38:53 +0200 |
| commit | 02e6bb42db183e1d14aa8275e6d3f8fb727c0761 (patch) | |
| tree | 3b270c40ae8febe08ce60dd5be96163ac91e11ab /src | |
| parent | 8961c0cc6cbef392a5f3a9fd5c449e365860967a (diff) | |
ksys/Utils: Improve accuracy of HeapUtil::tryCreateDualHeap
Diffstat (limited to 'src')
| -rw-r--r-- | src/KingSystem/Utils/HeapUtil.h | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/src/KingSystem/Utils/HeapUtil.h b/src/KingSystem/Utils/HeapUtil.h index 5b7a5296..bc6730c6 100644 --- a/src/KingSystem/Utils/HeapUtil.h +++ b/src/KingSystem/Utils/HeapUtil.h @@ -84,14 +84,14 @@ KSYS_CHECK_SIZE_NX150(sead::FrameHeap, 0xf0); KSYS_CHECK_SIZE_NX150(DualFrameHeap, 0x108); sead::Heap* tryCreateDualHeap(size_t size, const sead::SafeString& name, sead::Heap* heap1, - sead::Heap* heap2, sead::Heap::HeapDirection direction); + sead::Heap* heap2, sead::Heap::HeapDirection direction, bool b); /// Creates a dual heap that is as large as possible. sead::Heap* tryCreateDualHeap(sead::Heap* parent); /// Same as tryCreateDualHeap, but asserts on failure. sead::Heap* createDualHeap(size_t size, const sead::SafeString& name, sead::Heap* heap1, - sead::Heap* heap2, sead::Heap::HeapDirection direction); + sead::Heap* heap2, sead::Heap::HeapDirection direction, bool b); /// Returns the specified heap if it is not null. Otherwise, this returns the current heap. sead::Heap* getHeapOrCurrentHeap(sead::Heap* heap); @@ -104,26 +104,24 @@ sead::Heap* getDebugHeap2(); [[gnu::always_inline]] inline sead::Heap* tryCreateDualHeap(sead::Heap* parent) { size_t size; - sead::Heap* heap2; if (const auto* parent_ex = sead::DynamicCast<DualHeap>(parent)) { - if (parent_ex->getMaxAllocatableSize(sizeof(void*)) >= sizeof(DualFrameHeap)) - size = parent_ex->getMaxAllocatableSize(sizeof(void*)); - else + if (parent_ex->getMaxAllocatableSize(sizeof(void*)) < sizeof(DualFrameHeap)) size = sizeof(DualFrameHeap); - - heap2 = parent_ex->getHeap2(); - } else { - if (parent->getMaxAllocatableSize(sizeof(void*)) >= sizeof(DualFrameHeap)) - size = parent->getMaxAllocatableSize(sizeof(void*)); else - size = sizeof(DualFrameHeap); + size = parent_ex->getMaxAllocatableSize(sizeof(void*)); - heap2 = getDebugHeap(); + return tryCreateDualHeap(size, parent->getName(), parent, parent_ex->getHeap2(), + sead::Heap::cHeapDirection_Forward, false); } - return tryCreateDualHeap(size, parent->getName(), parent, heap2, - sead::Heap::cHeapDirection_Forward); + if (parent->getMaxAllocatableSize(sizeof(void*)) < sizeof(DualFrameHeap)) + size = sizeof(DualFrameHeap); + else + size = parent->getMaxAllocatableSize(sizeof(void*)); + + return tryCreateDualHeap(size, parent->getName(), parent, getDebugHeap(), + sead::Heap::cHeapDirection_Forward, false); } } // namespace ksys::util |
