Skip to content

Prevent UInt16 overflow when deleting WadTool state changes#1204

Open
Copilot wants to merge 4 commits into
developfrom
copilot/fix-delete-state-changes-error
Open

Prevent UInt16 overflow when deleting WadTool state changes#1204
Copilot wants to merge 4 commits into
developfrom
copilot/fix-delete-state-changes-error

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 19, 2026

Deleting the first row in WadTool's Animation Editor state change grid could throw a System.OverflowException from DataGridView while rebinding cell values. The failure was caused by unsigned row-bound properties receiving transient invalid values during grid row removal.

  • Use signed editing state in the grid

    • Changed FormStateChangesEditor's WadStateChangeRow numeric fields from ushort to int.
    • This keeps DataGridView editing/deletion in a signed domain and avoids the WinForms conversion path that overflowed on row deletion.
  • Clamp only at persistence boundaries

    • Added centralized clamping when converting edited row values back into WadStateChange / WadAnimDispatch.
    • Stored wad data remains ushort-based; only the editor's in-memory row model changed.
  • Keep related editor paths consistent

    • Updated blend field assignments and validation comments to match the new signed row model.
    • No behavior change to saved animation/state-change data beyond preventing the delete-time exception.
private class WadStateChangeRow
{
    public int StateId { get; set; }
    public int LowFrame { get; set; }
    public int HighFrame { get; set; }
    public int NextAnimation { get; set; }
    public int NextFrame { get; set; }
}

private static ushort ClampRowValue(int value)
{
    return (ushort)Math.Clamp(value, ushort.MinValue, ushort.MaxValue);
}

Copilot AI and others added 3 commits April 19, 2026 21:40
Copilot AI changed the title [WIP] Fix error message when trying to delete state changes Prevent UInt16 overflow when deleting WadTool state changes Apr 19, 2026
Copilot AI requested a review from Nickelony April 19, 2026 21:42
@Nickelony Nickelony requested review from Lwmte and Stranger1992 April 19, 2026 21:46
@Nickelony Nickelony added bug Something isn't working as intended. ready for review The Pull Request is finished and ready for review. labels Apr 19, 2026
@Nickelony Nickelony marked this pull request as ready for review April 19, 2026 21:46
@Nickelony
Copy link
Copy Markdown
Collaborator

WinForms back at it again...

@Nickelony Nickelony added this to the Version 2.0 milestone Apr 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working as intended. ready for review The Pull Request is finished and ready for review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WT: Error Message when trying to delete state changes

2 participants