-
-
Notifications
You must be signed in to change notification settings - Fork 964
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
Conversation
I was also debating if there should be the possibility to prevent crashing on failed Asset loading by adding a try catch but I know its best to avoid if possible. public T Load<T>(string url, ContentManagerLoaderSettings settings = null) where T : class
{
try
{
return (T)Load(typeof(T), url, settings);
}
catch(Exception ex)
{
Log.Error($"Error loading asset '{url}': {ex.Message}");
return null;
}
} instead of public T Load<T>(string url, ContentManagerLoaderSettings settings = null) where T : class
{
return (T)Load(typeof(T), url, settings);
} |
sources/core/Stride.Core.Serialization/Serialization/Contents/ContentManager.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks legit 😄
This is far more efficient: var textureDataReloaded = assetManager.Load<object>(url);
if (textureDataReloaded is Texture tex)
// ...
else if (textureDataReloaded is Image img)
// ... As for the method signature you introduced in |
Updated based on the suggestion. I agree with the documentation especially, I had no clue you could just use the base type object even though it makes perfect sense thining about it now. |
Thanks ! |
PR Details
when reloading a Texture it would try to pass in a value of type Image to the content manager for an asset that of type Texture.
Description
This adds a new method to the Content loader to check the type of an asset from the URL.
This also adds that check to the Texture class to determine how it should be treated when reloading.
Related Issue
#2008
#1493
Motivation and Context
Its the start of a fix for a seemingly larger problem with disposing of the graphics device when the game is in fullscreen.
Types of changes
Checklist