Return a ref instead of pointer, it must not be null
parent
ab5d3a22d3
commit
259a914cbf
|
@ -287,7 +287,7 @@ Error VoxelVoxMeshImporter::import(const String &p_source_file, const String &p_
|
|||
// Deallocate large temporary memory to free space.
|
||||
// This is a workaround because VoxelBuffer uses this by default, however it doesn't fit the present use case.
|
||||
// Eventually we should avoid using this pool here.
|
||||
VoxelMemoryPool::get_singleton()->clear_unused_blocks();
|
||||
VoxelMemoryPool::get_singleton().clear_unused_blocks();
|
||||
}
|
||||
|
||||
if (mesh.is_null()) {
|
||||
|
|
|
@ -202,7 +202,7 @@ void unregister_voxel_types() {
|
|||
VoxelServer::destroy_singleton();
|
||||
|
||||
// Do this last as VoxelServer might still be holding some refs to voxel blocks
|
||||
unsigned int used_blocks = VoxelMemoryPool::get_singleton()->debug_get_used_blocks();
|
||||
const unsigned int used_blocks = VoxelMemoryPool::get_singleton().debug_get_used_blocks();
|
||||
if (used_blocks > 0) {
|
||||
ERR_PRINT(String("VoxelMemoryPool: "
|
||||
"{0} memory blocks are still used when unregistering the module. Recycling leak?")
|
||||
|
|
|
@ -582,9 +582,9 @@ Dictionary VoxelServer::Stats::to_dict() {
|
|||
|
||||
// This part is additional for scripts because VoxelMemoryPool is not exposed
|
||||
Dictionary mem;
|
||||
mem["voxel_total"] = ZN_SIZE_T_TO_VARIANT(VoxelMemoryPool::get_singleton()->debug_get_total_memory());
|
||||
mem["voxel_used"] = ZN_SIZE_T_TO_VARIANT(VoxelMemoryPool::get_singleton()->debug_get_used_memory());
|
||||
mem["block_count"] = VoxelMemoryPool::get_singleton()->debug_get_used_blocks();
|
||||
mem["voxel_total"] = ZN_SIZE_T_TO_VARIANT(VoxelMemoryPool::get_singleton().debug_get_total_memory());
|
||||
mem["voxel_used"] = ZN_SIZE_T_TO_VARIANT(VoxelMemoryPool::get_singleton().debug_get_used_memory());
|
||||
mem["block_count"] = VoxelMemoryPool::get_singleton().debug_get_used_blocks();
|
||||
|
||||
Dictionary d;
|
||||
d["thread_pools"] = pools;
|
||||
|
|
|
@ -17,7 +17,7 @@ namespace zylann::voxel {
|
|||
|
||||
inline uint8_t *allocate_channel_data(size_t size) {
|
||||
#ifdef VOXEL_BUFFER_USE_MEMORY_POOL
|
||||
return VoxelMemoryPool::get_singleton()->allocate(size);
|
||||
return VoxelMemoryPool::get_singleton().allocate(size);
|
||||
#else
|
||||
return (uint8_t *)memalloc(size * sizeof(uint8_t));
|
||||
#endif
|
||||
|
@ -25,7 +25,7 @@ inline uint8_t *allocate_channel_data(size_t size) {
|
|||
|
||||
inline void free_channel_data(uint8_t *data, uint32_t size) {
|
||||
#ifdef VOXEL_BUFFER_USE_MEMORY_POOL
|
||||
VoxelMemoryPool::get_singleton()->recycle(data, size);
|
||||
VoxelMemoryPool::get_singleton().recycle(data, size);
|
||||
#else
|
||||
memfree(data);
|
||||
#endif
|
||||
|
|
|
@ -24,9 +24,9 @@ void VoxelMemoryPool::destroy_singleton() {
|
|||
memdelete(pool);
|
||||
}
|
||||
|
||||
VoxelMemoryPool *VoxelMemoryPool::get_singleton() {
|
||||
VoxelMemoryPool &VoxelMemoryPool::get_singleton() {
|
||||
CRASH_COND(g_memory_pool == nullptr);
|
||||
return g_memory_pool;
|
||||
return *g_memory_pool;
|
||||
}
|
||||
|
||||
VoxelMemoryPool::VoxelMemoryPool() {}
|
||||
|
|
|
@ -53,8 +53,7 @@ private:
|
|||
public:
|
||||
static void create_singleton();
|
||||
static void destroy_singleton();
|
||||
// TODO Return a reference, it must not be null when called
|
||||
static VoxelMemoryPool *get_singleton();
|
||||
static VoxelMemoryPool &get_singleton();
|
||||
|
||||
VoxelMemoryPool();
|
||||
~VoxelMemoryPool();
|
||||
|
|
Loading…
Reference in New Issue