Removes ArrayDeleter

This commit is contained in:
Vladislav Belov 2026-04-10 23:03:00 +02:00
parent 6893654cfc
commit 68091177ac
No known key found for this signature in database
GPG key ID: 353545E45DB9CCB3
5 changed files with 13 additions and 91 deletions

View file

@ -1,66 +0,0 @@
/* Copyright (C) 2025 Wildfire Games.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "precompiled.h"
#include "shared_ptr.h"
#include "lib/allocators/allocator_checker.h"
#include "lib/debug.h"
#ifndef NDEBUG
static AllocatorChecker s_allocatorChecker;
#endif
class CheckedArrayDeleter
{
public:
CheckedArrayDeleter(size_t size)
: m_size(size)
{
}
void operator()(u8* p)
{
ENSURE(m_size != 0);
#ifndef NDEBUG
s_allocatorChecker.OnDeallocate(p, m_size);
#endif
delete[] p;
m_size = 0;
}
private:
size_t m_size;
};
std::shared_ptr<u8> Allocate(size_t size)
{
ENSURE(size != 0);
u8* p = new u8[size];
#ifndef NDEBUG
s_allocatorChecker.OnAllocate(p, size);
#endif
return std::shared_ptr<u8>(p, CheckedArrayDeleter(size));
}

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@ -46,19 +46,6 @@ inline std::shared_ptr<T> DummySharedPtr(T* ptr)
return std::shared_ptr<T>(ptr, DummyDeleter());
}
struct ArrayDeleter
{
template<class T>
void operator()(T* p)
{
delete[] p;
}
};
// (note: uses CheckedArrayDeleter)
std::shared_ptr<u8> Allocate(size_t size);
struct AlignedDeleter
{
template<class T>

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@ -50,7 +50,8 @@ public:
void test_img_size()
{
std::shared_ptr<u8> img(new u8[100*100*4], ArrayDeleter());
std::shared_ptr<u8> img;
TS_ASSERT_OK(AllocateAligned(img, 100 * 100 * 4));
Tex t;
TS_ASSERT_OK(t.wrap(100, 100, 32, TEX_ALPHA, img, 0));
@ -66,7 +67,8 @@ public:
{
const size_t w = 4, h = 4, bpp = 4;
const size_t size = w*h/2;
std::shared_ptr<u8> img(new u8[size], ArrayDeleter());
std::shared_ptr<u8> img;
TS_ASSERT_OK(AllocateAligned(img, size));
memcpy(img.get(), "\xFF\xFF\x00\x00\x00\xAA\xFF\x55", 8); // gradient from white to black
const u8 expected[] =
"\xFF\xFF\xFF" "\xFF\xFF\xFF" "\xFF\xFF\xFF" "\xFF\xFF\xFF"

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@ -653,11 +653,11 @@ u32 Tex::get_average_color() const
// construct a new texture based on the current one,
// but only include the last mipmap level
// do this so that we can use the general conversion methods for the pixel data
Tex basetex = *this;
uint8_t *data = new uint8_t[last_level_size];
memcpy(data, m_Data.get() + m_Ofs + size - last_level_size, last_level_size);
std::shared_ptr<uint8_t> sdata(data, ArrayDeleter());
basetex.wrap(1, 1, m_Bpp, m_Flags, sdata, 0);
Tex basetex;
std::shared_ptr<uint8_t> data;
WARN_IF_ERR(AllocateAligned(data, last_level_size));
memcpy(data.get(), m_Data.get() + m_Ofs + size - last_level_size, last_level_size);
basetex.wrap(1, 1, m_Bpp, m_Flags, data, 0);
// convert to BGRA
WARN_IF_ERR(basetex.transform_to(TEX_BGR | TEX_ALPHA));

View file

@ -24,7 +24,6 @@
#include "Profiler2.h"
#include "lib/allocators/shared_ptr.h"
#include "lib/code_generation.h"
#include "lib/os_path.h"
#include "lib/path.h"
@ -304,7 +303,7 @@ std::string CProfiler2::ThreadStorage::GetBuffer()
//
// See comments on m_BufferPos0 etc.
std::shared_ptr<u8> buffer(new u8[BUFFER_SIZE], ArrayDeleter());
std::unique_ptr<u8[]> buffer{std::make_unique<u8[]>(BUFFER_SIZE)};
u32 pos1 = m_BufferPos1;
COMPILER_FENCE; // must read m_BufferPos1 before m_Buffer