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

Fix Allocator issues reported by ReSharper #168

Merged
merged 1 commit into from
Jan 14, 2025
Merged
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
44 changes: 19 additions & 25 deletions include/RED4ext/Memory/Allocators.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
#pragma once
// Disable ReSharper virtual destructor check, as the Allocators are just structs with pointers to functions which are
// copied around.
// ReSharper disable CppPolymorphicClassWithNonVirtualPublicDestructor

#include <cstdint>
#include <type_traits>
#pragma once

#include <RED4ext/Detail/AddressHashes.hpp>
#include <RED4ext/Common.hpp>
#include <RED4ext/Detail/AddressHashes.hpp>
#include <RED4ext/Memory/Pools.hpp>
#include <RED4ext/Relocation.hpp>

#include <cstdint>
#include <type_traits>

namespace RED4ext
{
namespace Memory
Expand All @@ -28,7 +32,7 @@ struct IAllocator
uint32_t aAlignment) const = 0; // 16
virtual void Free(AllocationResult& aAllocation) const = 0; // 20
virtual void sub_28(void* a1) const = 0; // 28
virtual const uint32_t GetHandle() const = 0; // 30
virtual const uint32_t GetHandle() const = 0; // 30

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

auto pool = T::Get();
auto storage = pool->storage->GetAllocatorStorage<Vault>();
auto storage = pool->storage->template GetAllocatorStorage<Vault>();

AllocationResult result;
AllocationResult result = {};
alloc(storage, &result, aSize);
if (!result.memory)
{
Expand All @@ -99,9 +103,9 @@ struct Allocator : IAllocator
static UniversalRelocFunc<alloc_t> alloc(Detail::AddressHashes::Memory_Vault_AllocAligned);

auto pool = T::Get();
auto storage = pool->storage->GetAllocatorStorage<Vault>();
auto storage = pool->storage->template GetAllocatorStorage<Vault>();

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

auto pool = T::Get();
auto storage = pool->storage->GetAllocatorStorage<Vault>();
auto storage = pool->storage->template GetAllocatorStorage<Vault>();

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

auto pool = T::Get();
auto storage = pool->storage->GetAllocatorStorage<Vault>();
auto storage = pool->storage->template GetAllocatorStorage<Vault>();

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

auto pool = T::Get();
auto storage = pool->storage->GetAllocatorStorage<Vault>();
auto storage = pool->storage->template GetAllocatorStorage<Vault>();
func(storage, aAllocation);
}

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

auto pool = T::Get();
auto storage = pool->storage->GetAllocatorStorage<Vault>();
auto storage = pool->storage->template GetAllocatorStorage<Vault>();
func(storage, a2);
}

Expand Down Expand Up @@ -2712,14 +2716,4 @@ struct GPUM_Buffer_MorphTargetsAllocator : Allocator<GPUM_Buffer_MorphTargets>
{
};
} // namespace Memory

struct [[deprecated("Use 'Memory::IAllocator' instead.")]] IMemoryAllocator : Memory::IAllocator
{
struct [[deprecated("Use 'Memory::AllocationResult' instead.")]] Result : Memory::AllocationResult{};
};

struct [[deprecated("Use 'Memory::EngineAllocator' instead.")]] EngineAllocator : Memory::EngineAllocator{};
struct [[deprecated("Use 'Memory::RTTIAllocator' instead.")]] RTTIAllocator : Memory::RTTIAllocator{};
struct [[deprecated("Use 'Memory::RTTIFunctionAllocator' instead.")]] RTTIFunctionAllocator
: Memory::RTTIFunctionAllocator{};
} // namespace RED4ext