Move piece lifetime bookkeeping into lcPieceManager

Piece registrations were centralized but creation, reference bookkeeping and
cleanup still lived in the library. Move creation/model reuse, normalization,
metadata renaming, reference operations, temporary cleanup, project transfer and
ordered identity teardown into the manager. Keep registration/deletion helpers
private and remove the temporary local-registry enumeration APIs.

The library remains the acquisition facade and coordinates source resolution,
loading, invalidation and cancellation after unlocking. Handles still bind to
the library. Clear sparse errors from lcPieceData::Unload before resource teardown
so manager deletion does not require a library pointer or callback. Sparse error
storage and the existing synchronization remain library-side.

Use one project-aware manager lookup, passing nullptr for shared-only searches.
Remove the maximum-size name reservation so short names can use inline storage.
Replace remaining bounded C-string copy/terminator pairs with lcstrcpy and record
the helper convention in common/AGENTS.md. Update the asset lifetime documentation.

Validation: macOS Qt 6.10 Debug build, whitespace checks and 40 offscreen lifecycle
checks, including already-zero release, last-owner cancellation, model reuse,
project detach/transfer cleanup, sparse errors, archive/directory caches and forced
nested external-project teardown. Successful GPU rendering is not covered by the
offscreen checks.
This commit is contained in:
Leonardo Zide committed 2026-10-19 11:48:21 -07:00
1 parent 41e5432395
commit b38a1ce0fa
9 files changed
+302 -274

No files matched your search

+8 -10
View File
@@ -4,6 +4,7 @@
#include "lc_colors.h"
#include "lc_texture.h"
#include "lc_piecedata.h"
#include "lc_string.h"
#include "lc_library.h"
#include "lc_application.h"
#include "lc_model.h"
@@ -90,8 +91,7 @@ void lcPieceData::DetachContainer()
mType = Type::Part;
mModel = nullptr;
mProject = nullptr;
strncpy(m_strDescription, mFileName, sizeof(m_strDescription) - 1);
m_strDescription[sizeof(m_strDescription) - 1] = 0;
lcstrcpy(m_strDescription, mFileName);
delete PreviousProject;
ReleaseMesh();
@@ -132,10 +132,8 @@ void lcPieceData::CreateProject(Project* NewProject, const char* PieceName)
delete PreviousProject;
}
strncpy(mFileName, PieceName, sizeof(mFileName) - 1);
mFileName[sizeof(mFileName) - 1] = 0;
strncpy(m_strDescription, NewProject->GetFileName().toLatin1().data(), sizeof(m_strDescription) - 1);
m_strDescription[sizeof(m_strDescription) - 1] = 0;
lcstrcpy(mFileName, PieceName);
lcstrcpy(m_strDescription, NewProject->GetFileName().toLatin1().data());
}
bool lcPieceData::IsProjectPiece() const
@@ -168,10 +166,8 @@ bool lcPieceData::IncludesModel(const lcModel* Model) const
void lcPieceData::CreatePart(const char* Name)
{
strncpy(mFileName, Name, sizeof(mFileName));
mFileName[sizeof(mFileName) - 1] = 0;
strncpy(m_strDescription, Name, sizeof(m_strDescription));
m_strDescription[sizeof(m_strDescription) - 1] = 0;
lcstrcpy(mFileName, Name);
lcstrcpy(m_strDescription, Name);
}
void lcPieceData::ReleaseMesh()
@@ -185,6 +181,8 @@ void lcPieceData::ReleaseMesh()
void lcPieceData::Unload()
{
lcGetPiecesLibrary()->ClearPieceDataLoadError(this);
ReleaseMesh();
mState = lcAssetState::Unloaded;
SetLoadingBoundingBox();