Skip to content

Commit c28ee69

Browse files
committed
Fix Allocator issues reported by ReSharper
- no public virtual destructor inside Allocator (required for the rest of the classes, simply removed protected destructor as one is already present in IAllocator and it was defaulted) - missing template keyword calling dependent function name - missing default initialization for AllocationResult - reformat
1 parent 929c8e0 commit c28ee69

File tree

1 file changed

+28
-16
lines changed

1 file changed

+28
-16
lines changed

include/RED4ext/Memory/Allocators.hpp

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
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
4+
15
#pragma once
26

37
#include <cstdint>
48
#include <type_traits>
59

6-
#include <RED4ext/Detail/AddressHashes.hpp>
710
#include <RED4ext/Common.hpp>
11+
#include <RED4ext/Detail/AddressHashes.hpp>
812
#include <RED4ext/Memory/Pools.hpp>
913
#include <RED4ext/Relocation.hpp>
1014

@@ -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

@@ -2715,11 +2719,19 @@ struct GPUM_Buffer_MorphTargetsAllocator : Allocator<GPUM_Buffer_MorphTargets>
27152719

27162720
struct [[deprecated("Use 'Memory::IAllocator' instead.")]] IMemoryAllocator : Memory::IAllocator
27172721
{
2718-
struct [[deprecated("Use 'Memory::AllocationResult' instead.")]] Result : Memory::AllocationResult{};
2722+
struct [[deprecated("Use 'Memory::AllocationResult' instead.")]] Result : Memory::AllocationResult
2723+
{
2724+
};
27192725
};
27202726

2721-
struct [[deprecated("Use 'Memory::EngineAllocator' instead.")]] EngineAllocator : Memory::EngineAllocator{};
2722-
struct [[deprecated("Use 'Memory::RTTIAllocator' instead.")]] RTTIAllocator : Memory::RTTIAllocator{};
2727+
struct [[deprecated("Use 'Memory::EngineAllocator' instead.")]] EngineAllocator : Memory::EngineAllocator
2728+
{
2729+
};
2730+
struct [[deprecated("Use 'Memory::RTTIAllocator' instead.")]] RTTIAllocator : Memory::RTTIAllocator
2731+
{
2732+
};
27232733
struct [[deprecated("Use 'Memory::RTTIFunctionAllocator' instead.")]] RTTIFunctionAllocator
2724-
: Memory::RTTIFunctionAllocator{};
2734+
: Memory::RTTIFunctionAllocator
2735+
{
2736+
};
27252737
} // namespace RED4ext

0 commit comments

Comments
 (0)