Skip to content

Conversation

@mqole
Copy link
Member

@mqole mqole commented Dec 14, 2025

About the PR

early merge of space-wizards#40668
imp comments added

Why / Balance

required to fix issues in #3721

Requirements

{
// Uses sequential indexing for ghost layers to handle cases where
// invisible layers are between visible ones in the source sprite
var visibleLayers = 0;
Copy link

@dayn-e dayn-e Dec 27, 2025

Choose a reason for hiding this comment

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

The way I'm reading this is visibleLayers is meant to be an index for the list of layers so that it applies the shade, sprite etc for every valid layer. For this reason I'd suggest renaming it to something like visibleLayerIndex.

Comment on lines +347 to +352
if (!layer.Visible || !layer.RsiState.IsValid)
continue;

var rsi = layer.Rsi ?? source.BaseRSI;
if (rsi is null || !rsi.TryGetState(layer.RsiState, out var state) || state.StateId.Name is null)
continue;
Copy link

Choose a reason for hiding this comment

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

This will cause a desync of your index counter and the layer the loop is on, meaning it might apply to an incorrect layer.

Click here for an example if you don't get what I mean.

For example say we have an item with three layers.

Layer 1 - index 0 (tracked by visibleLayers) - valid
Layer 2 - index 1 - invalid
Layer 3 - index 2 - valid

What would happen in this case is since visibleLayers is incremented at the end of the foreach, which is skipped in both these checks, means that after Layer 2, the variable will be at 1, while the loop is looking at Layer 3. If that were to happen, then the rest of the function would try to apply everything to the invalid layer.

Suggested change
if (!layer.Visible || !layer.RsiState.IsValid)
continue;
var rsi = layer.Rsi ?? source.BaseRSI;
if (rsi is null || !rsi.TryGetState(layer.RsiState, out var state) || state.StateId.Name is null)
continue;
if (!layer.Visible || !layer.RsiState.IsValid)
{
visibleLayers++;
continue;
}
var rsi = layer.Rsi ?? source.BaseRSI;
if (rsi is null || !rsi.TryGetState(layer.RsiState, out var state) || state.StateId.Name is null)
{
visibleLayers++;
continue;
}

@mqole
Copy link
Member Author

mqole commented Jan 2, 2026

closing per maints discussion

@mqole mqole closed this Jan 2, 2026
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.

3 participants