Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Update Texture reload to prevent crash due to wrong type. #2251

Merged
merged 6 commits into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,18 @@ private object DeserializeObject(string initialUrl, string newUrl, Type type, ob
return result;
}

public bool TryGetLoadedAsset(string url, out object asset)
{
if (LoadedAssetUrls.TryGetValue(url, out var reference))
{
asset = reference.Object;
return true;
}

asset = null;
return false;
}

internal Reference FindDeserializedObject(string url, Type objType)
{
// Try to find already loaded object
Expand Down
15 changes: 12 additions & 3 deletions sources/engine/Stride.Graphics/Data/TextureContentSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,18 @@ internal static void Serialize(ArchiveMode mode, SerializationStream stream, Tex
{
var assetManager = services.GetService<ContentManager>();
assetManager.TryGetAssetUrl(graphicsResource, out var url);
var textureDataReloaded = assetManager.Load<Image>(url);
((Texture)graphicsResource).Recreate(textureDataReloaded.ToDataBox());
assetManager.Unload(textureDataReloaded);
var textureDataReloaded = assetManager.Load<object>(url);

if (textureDataReloaded is Image image)
{
((Texture)graphicsResource).Recreate(image.ToDataBox());
assetManager.Unload(textureDataReloaded);
}
else if (textureDataReloaded is Texture)
{
((Texture)graphicsResource).Recreate();
assetManager.Unload(textureDataReloaded);
}
};
}
}
Expand Down