Skip to content

Commit

Permalink
- cleanup resources in right order
Browse files Browse the repository at this point in the history
  • Loading branch information
kaffeewolf committed Nov 23, 2024
1 parent a8d379c commit 35d03d5
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
7 changes: 7 additions & 0 deletions code/render/graphics/graphicsserver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,13 @@ GraphicsServer::Close()
this->timer->StopTime();
this->timer = nullptr;

Resources::ResourceServer::Instance()->DeregisterStreamLoader("dds", CoreGraphics::TextureLoader::RTTI);
Resources::ResourceServer::Instance()->DeregisterStreamLoader("nax", CoreAnimation::AnimationLoader::RTTI);
Resources::ResourceServer::Instance()->DeregisterStreamLoader("nsk", Characters::SkeletonLoader::RTTI);
Resources::ResourceServer::Instance()->DeregisterStreamLoader("nvx", CoreGraphics::MeshLoader::RTTI);
Resources::ResourceServer::Instance()->DeregisterStreamLoader("sur", Materials::MaterialLoader::RTTI);
Resources::ResourceServer::Instance()->DeregisterStreamLoader("n3", Models::ModelLoader::RTTI);

if (this->graphicsDevice)
CoreGraphics::DestroyGraphicsDevice();
}
Expand Down
36 changes: 35 additions & 1 deletion code/resource/resources/resourceserver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ ResourceServer::Close()
Core::SysFunc::DebugOut("\n\n******** NEBULA RESOURCE MANAGER ********\n Beginning of resource leak report:");
for (IndexT i = 0; i < this->loaders.Size(); i++)
{
ResourceLoader* pool = this->loaders[i];
Ptr<ResourceLoader> pool = this->loaders[i];
if (!pool.isvalid())
{
continue;
}
for (auto & kvp : pool->ids)
{
const auto resource = pool->resources[kvp.Value()];
Expand Down Expand Up @@ -103,6 +107,36 @@ ResourceServer::RegisterStreamLoader(const Util::StringAtom& ext, const Core::Rt
this->typeMap.Add(&loaderClass, this->loaders.Size() - 1);
}

//------------------------------------------------------------------------------
/**
*/
void
ResourceServer::DeregisterStreamLoader(const Util::StringAtom& ext, const Core::Rtti& loaderClass)
{
n_assert(this->open);
n_assert(loaderClass.IsDerivedFrom(ResourceLoader::RTTI));
n_assert(this->extensionMap.Contains(ext));
n_assert(this->typeMap.Contains(&loaderClass));

IndexT loaderIdx = this->extensionMap[ext];
n_assert(this->typeMap[&loaderClass] == loaderIdx);
Ptr<ResourceLoader> loader = this->loaders[loaderIdx];
this->loaders[loaderIdx] = nullptr;
this->extensionMap.Erase(ext);
this->typeMap.Erase(&loaderClass);
for (auto& kvp : loader->ids)
{
const auto resource = loader->resources[kvp.Value()];
if (loader->GetUsage(kvp.Value()) != 0)
{
const Resources::ResourceName& name = kvp.Key();
Util::String msg = Util::String::Sprintf("Resource <%s> (id %d) from pool %d is not unloaded, usage is '%d'\n", name.Value(), resource.resourceId, loader->uniqueId, loader->GetUsage(kvp.Value()));
Core::SysFunc::DebugOut(msg.AsCharPtr());
}
}
loader = nullptr;
}

//------------------------------------------------------------------------------
/**
*/
Expand Down
2 changes: 2 additions & 0 deletions code/resource/resources/resourceserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ class ResourceServer : public Core::RefCounted

/// register a stream pool, which takes an extension and the RTTI of the resource type to create
void RegisterStreamLoader(const Util::StringAtom& ext, const Core::Rtti& loaderClass);
/// deregisters a stream pool
void DeregisterStreamLoader(const Util::StringAtom& ext, const Core::Rtti& loaderClass);
/// get stream pool for later use
template <class POOL_TYPE> POOL_TYPE* GetStreamLoader() const;

Expand Down

0 comments on commit 35d03d5

Please sign in to comment.