Fix bug with missing baked SDF data on save when asset data chunk memory was freed by GC
This commit is contained in:
@@ -682,7 +682,11 @@ bool Model::GenerateSDF(float resolutionScale, int32 lodIndex, bool cacheData, f
|
|||||||
#if USE_EDITOR
|
#if USE_EDITOR
|
||||||
// Set asset data
|
// Set asset data
|
||||||
if (cacheData)
|
if (cacheData)
|
||||||
GetOrCreateChunk(15)->Data.Copy(sdfStream.GetHandle(), sdfStream.GetPosition());
|
{
|
||||||
|
auto chunk = GetOrCreateChunk(15);
|
||||||
|
chunk->Data.Copy(sdfStream.GetHandle(), sdfStream.GetPosition());
|
||||||
|
chunk->Flags |= FlaxChunkFlags::KeepInMemory; // Prevent GC-ing chunk data so it will be properly saved
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
enum class FlaxChunkFlags
|
enum class FlaxChunkFlags
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The none.
|
/// Nothing.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
None = 0,
|
None = 0,
|
||||||
|
|
||||||
@@ -19,6 +19,11 @@ enum class FlaxChunkFlags
|
|||||||
/// Compress chunk data using LZ4 algorithm.
|
/// Compress chunk data using LZ4 algorithm.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
CompressedLZ4 = 1,
|
CompressedLZ4 = 1,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Prevents chunk file data from being unloaded if unused for a certain amount of time. Runtime-only flag, not saved with the asset.
|
||||||
|
/// </summary>
|
||||||
|
KeepInMemory = 2,
|
||||||
};
|
};
|
||||||
|
|
||||||
DECLARE_ENUM_OPERATORS(FlaxChunkFlags);
|
DECLARE_ENUM_OPERATORS(FlaxChunkFlags);
|
||||||
|
|||||||
@@ -943,7 +943,8 @@ bool FlaxStorage::Create(WriteStream* stream, const AssetInitData* data, int32 d
|
|||||||
{
|
{
|
||||||
FlaxChunk* chunk = chunks[i];
|
FlaxChunk* chunk = chunks[i];
|
||||||
stream->WriteBytes(&chunk->LocationInFile, sizeof(chunk->LocationInFile));
|
stream->WriteBytes(&chunk->LocationInFile, sizeof(chunk->LocationInFile));
|
||||||
stream->WriteInt32((int32)chunk->Flags);
|
FlaxChunkFlags flags = chunk->Flags & ~(FlaxChunkFlags::KeepInMemory); // Skip saving runtime-only flags
|
||||||
|
stream->WriteInt32((int32)flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if ASSETS_LOADING_EXTRA_VERIFICATION
|
#if ASSETS_LOADING_EXTRA_VERIFICATION
|
||||||
@@ -1410,7 +1411,7 @@ void FlaxStorage::Tick(double time)
|
|||||||
{
|
{
|
||||||
auto chunk = _chunks.Get()[i];
|
auto chunk = _chunks.Get()[i];
|
||||||
const bool wasUsed = (time - chunk->LastAccessTime) < unusedDataChunksLifetime;
|
const bool wasUsed = (time - chunk->LastAccessTime) < unusedDataChunksLifetime;
|
||||||
if (!wasUsed && chunk->IsLoaded())
|
if (!wasUsed && chunk->IsLoaded() && EnumHasNoneFlags(chunk->Flags, FlaxChunkFlags::KeepInMemory))
|
||||||
{
|
{
|
||||||
chunk->Unload();
|
chunk->Unload();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user