Skip to content

Commit fedf842

Browse files
authored
Merge pull request #168 from WSSDude/feature/allocator-changes
Fix Allocator issues reported by ReSharper
2 parents 929c8e0 + 855ba85 commit fedf842

File tree

1 file changed

+19
-25
lines changed

1 file changed

+19
-25
lines changed

include/RED4ext/Memory/Allocators.hpp

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
#pragma once
1+
// Disable ReSharper virtual destructor check, as the Allocators are just structs with pointers to functions which are
2+
// copied around.
3+
// ReSharper disable CppPolymorphicClassWithNonVirtualPublicDestructor
24

3-
#include <cstdint>
4-
#include <type_traits>
5+
#pragma once
56

6-
#include <RED4ext/Detail/AddressHashes.hpp>
77
#include <RED4ext/Common.hpp>
8+
#include <RED4ext/Detail/AddressHashes.hpp>
89
#include <RED4ext/Memory/Pools.hpp>
910
#include <RED4ext/Relocation.hpp>
1011

12+
#include <cstdint>
13+
#include <type_traits>
14+
1115
namespace RED4ext
1216
{
1317
namespace Memory
@@ -28,7 +32,7 @@ struct IAllocator
2832
uint32_t aAlignment) const = 0; // 16
2933
virtual void Free(AllocationResult& aAllocation) const = 0; // 20
3034
virtual void sub_28(void* a1) const = 0; // 28
31-
virtual const uint32_t GetHandle() const = 0; // 30
35+
virtual const uint32_t GetHandle() const = 0; // 30
3236

3337
[[deprecated("Use 'GetHandle()' instead.")]] const uint32_t GetId() const
3438
{
@@ -81,9 +85,9 @@ struct Allocator : IAllocator
8185
static UniversalRelocFunc<alloc_t> alloc(Detail::AddressHashes::Memory_Vault_Alloc);
8286

8387
auto pool = T::Get();
84-
auto storage = pool->storage->GetAllocatorStorage<Vault>();
88+
auto storage = pool->storage->template GetAllocatorStorage<Vault>();
8589

86-
AllocationResult result;
90+
AllocationResult result = {};
8791
alloc(storage, &result, aSize);
8892
if (!result.memory)
8993
{
@@ -99,9 +103,9 @@ struct Allocator : IAllocator
99103
static UniversalRelocFunc<alloc_t> alloc(Detail::AddressHashes::Memory_Vault_AllocAligned);
100104

101105
auto pool = T::Get();
102-
auto storage = pool->storage->GetAllocatorStorage<Vault>();
106+
auto storage = pool->storage->template GetAllocatorStorage<Vault>();
103107

104-
AllocationResult result;
108+
AllocationResult result = {};
105109
alloc(storage, &result, aSize, aAlignment);
106110
if (!result.memory)
107111
{
@@ -117,9 +121,9 @@ struct Allocator : IAllocator
117121
static UniversalRelocFunc<realloc_t> realloc(Detail::AddressHashes::Memory_Vault_Realloc);
118122

119123
auto pool = T::Get();
120-
auto storage = pool->storage->GetAllocatorStorage<Vault>();
124+
auto storage = pool->storage->template GetAllocatorStorage<Vault>();
121125

122-
AllocationResult result;
126+
AllocationResult result = {};
123127
realloc(storage, &result, aAllocation, aSize);
124128
if (!result.memory && aSize)
125129
{
@@ -136,9 +140,9 @@ struct Allocator : IAllocator
136140
static UniversalRelocFunc<realloc_t> realloc(Detail::AddressHashes::Memory_Vault_ReallocAligned);
137141

138142
auto pool = T::Get();
139-
auto storage = pool->storage->GetAllocatorStorage<Vault>();
143+
auto storage = pool->storage->template GetAllocatorStorage<Vault>();
140144

141-
AllocationResult result;
145+
AllocationResult result = {};
142146
realloc(storage, &result, aAllocation, aSize, aAlignment);
143147
if (!result.memory && aSize)
144148
{
@@ -154,7 +158,7 @@ struct Allocator : IAllocator
154158
static UniversalRelocFunc<func_t> func(Detail::AddressHashes::Memory_Vault_Free);
155159

156160
auto pool = T::Get();
157-
auto storage = pool->storage->GetAllocatorStorage<Vault>();
161+
auto storage = pool->storage->template GetAllocatorStorage<Vault>();
158162
func(storage, aAllocation);
159163
}
160164

@@ -164,7 +168,7 @@ struct Allocator : IAllocator
164168
static UniversalRelocFunc<func_t> func(Detail::AddressHashes::Memory_Vault_Unk1);
165169

166170
auto pool = T::Get();
167-
auto storage = pool->storage->GetAllocatorStorage<Vault>();
171+
auto storage = pool->storage->template GetAllocatorStorage<Vault>();
168172
func(storage, a2);
169173
}
170174

@@ -2712,14 +2716,4 @@ struct GPUM_Buffer_MorphTargetsAllocator : Allocator<GPUM_Buffer_MorphTargets>
27122716
{
27132717
};
27142718
} // namespace Memory
2715-
2716-
struct [[deprecated("Use 'Memory::IAllocator' instead.")]] IMemoryAllocator : Memory::IAllocator
2717-
{
2718-
struct [[deprecated("Use 'Memory::AllocationResult' instead.")]] Result : Memory::AllocationResult{};
2719-
};
2720-
2721-
struct [[deprecated("Use 'Memory::EngineAllocator' instead.")]] EngineAllocator : Memory::EngineAllocator{};
2722-
struct [[deprecated("Use 'Memory::RTTIAllocator' instead.")]] RTTIAllocator : Memory::RTTIAllocator{};
2723-
struct [[deprecated("Use 'Memory::RTTIFunctionAllocator' instead.")]] RTTIFunctionAllocator
2724-
: Memory::RTTIFunctionAllocator{};
27252719
} // namespace RED4ext

0 commit comments

Comments
 (0)