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

Add a more helpful crash on missing frames #21390

Open
wants to merge 1 commit into
base: bleed
Choose a base branch
from

Conversation

PunkPun
Copy link
Member

@PunkPun PunkPun commented Apr 6, 2024

Currently it crashes with: exception of type System.IndexOutOfRangeException: Index was outside the bounds of the array.

With no hint to where the issue resides
This is hot code though it runs only once on game / map start

Copy link
Contributor

@anvilvapre anvilvapre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

untested.

OpenRA.Game/Graphics/SpriteCache.cs Outdated Show resolved Hide resolved
@abcdefg30
Copy link
Member

From @pchote on Discord:

https://github.com/OpenRA/OpenRA/blob/bleed/OpenRA.Mods.Common/Graphics/DefaultSpriteSequence.cs#L544 is where it is supposed to be handled
i suspect we should be ignoring out of index frames in the cache and then letting that line throw the error
or have some other mechanism for SpriteCache to allow the SpriteSequence to do validation and throw

Would be checking if resolved[f] is in bounds work here?

resolved = r.Frames.Select(f => resolved[f]).ToArray();

And then just if (i >= loadedFrames.Length) continue; in the loop in SpriteCache.

This would have the advantage of being able to report {image}.{Name} in the exception.

@PunkPun
Copy link
Member Author

PunkPun commented Apr 25, 2024

That doesn't catch all errors. For example setting an invalid ShadowStart still crashes with out of index, just in a different place

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants