diff --git a/src/ResourceManager.h b/src/ResourceManager.h index ab8c70659..9186f00a5 100644 --- a/src/ResourceManager.h +++ b/src/ResourceManager.h @@ -453,9 +453,14 @@ template ResourceManager*& ResourceManager:: namespace Implementation { +template void safeDelete(T* data) { + static_assert(sizeof(T) > 0, "Cannot delete pointer to incomplete type"); + delete data; +} + template ResourceManagerData::~ResourceManagerData() { /* Loaders are already deleted via freeLoaders() from ResourceManager */ - delete _fallback; + safeDelete(_fallback); } template std::size_t ResourceManagerData::referenceCount(const ResourceKey key) const { @@ -509,7 +514,7 @@ template void ResourceManagerData::set(const ResourceKey key, T* con /* If nothing is referencing reference-counted resource, we're done */ if(policy == ResourcePolicy::ReferenceCounted && (it == _data.end() || it->second.referenceCount == 0)) { Warning() << "ResourceManager: Reference-counted resource with key" << key << "isn't referenced from anywhere, deleting it immediately"; - delete data; + safeDelete(data); /* Delete also already present resource (it could be here because previous policy could be other than @@ -527,7 +532,7 @@ template void ResourceManagerData::set(const ResourceKey key, T* con #endif /* Replace previous data */ - delete it->second.data; + safeDelete(it->second.data); it->second.data = data; it->second.state = state; it->second.policy = policy; @@ -535,7 +540,7 @@ template void ResourceManagerData::set(const ResourceKey key, T* con } template void ResourceManagerData::setFallback(T* const data) { - delete _fallback; + safeDelete(_fallback); _fallback = data; } @@ -595,7 +600,7 @@ template struct ResourceManagerData::Data { template inline ResourceManagerData::Data::~Data() { CORRADE_ASSERT(referenceCount == 0, "ResourceManager: cleared/destroyed while data are still referenced", ); - delete data; + safeDelete(data); } }