MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / UpgradeAsset

Method UpgradeAsset

Source/Engine/Content/Factories/BinaryAssetFactory.cpp:114–214  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

112#if USE_EDITOR
113
114bool BinaryAssetFactoryBase::UpgradeAsset(const AssetInfo& info, FlaxStorage* storage, AssetMigrationContext& context)
115{
116 // Load all asset chunks
117 for (int32 chunkIndex = 0; chunkIndex < ASSET_FILE_DATA_CHUNKS; chunkIndex++)
118 {
119 auto chunk = context.Input.Header.Chunks[chunkIndex];
120 if (chunk && storage->LoadAssetChunk(chunk))
121 {
122 LOG(Warning, "Failed to load asset chunk {0}.", chunkIndex);
123 return true;
124 }
125 }
126
127 // Init output header
128 context.Output.Header = context.Input.Header;
129
130 // Start upgrading chain
131 const auto upgrader = static_cast<BinaryAssetUpgrader*>(GetUpgrader());
132 int32 step = 0;
133 do
134 {
135 // Unlink chunks in output (won't be used)
136 context.Output.Header.UnlinkChunks();
137
138 // Perform conversion
139 // Note: on failed conversion there may be some memory leaks but we don't care in that case very much
140 if (upgrader->Upgrade(context.Input.SerializedVersion, context))
141 return true;
142
143 // Swap input with output (remember to delete old input chunks if they were allocated by upgrader not by the storage)
144 if (step++ > 1)
145 context.Input.Header.DeleteChunks();
146 context.Input = context.Output;
147 } while (upgrader->ShouldUpgrade(context.Input.SerializedVersion));
148
149 // Prevent other threads from loading the storage when it is upgrading
150 // It works because CriticalSection allows recursion
151 ScopeLock upgradeLock(storage->_loadLocker);
152
153 // Release storage internal data (should also close file handles)
154 {
155 // HACK: file is locked by some tasks: the current one that called asset data upgrade (LoadAssetTask)
156 // and by asset data loading tasks which are waiting for the start after init task
157 // Let's hide these locks just for the upgrade
158 const auto locks = storage->_chunksLock;
159 storage->_chunksLock = 0;
160 storage->Dispose();
161 storage->_chunksLock = locks;
162 }
163
164 // Serialize conversion result data
165#if USE_EDITOR
166 if (FlaxFile::Create(storage->GetPath(), context.Output))
167#endif
168 {
169 LOG(Warning, "Cannot serialize converted data.");
170 return true;
171 }

Callers

nothing calls this directly

Calls 11

GetUpgraderFunction · 0.85
LoadAssetChunkMethod · 0.80
UnlinkChunksMethod · 0.80
DeleteChunksMethod · 0.80
LoadAssetHeaderMethod · 0.80
CreateFunction · 0.50
DisposeMethod · 0.45
GetPathMethod · 0.45
ClearMethod · 0.45
ReleaseMethod · 0.45
LoadMethod · 0.45

Tested by

no test coverage detected