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

IndexOutOfRangeException thrown if Tileset is switched on painted Tilemap #763

Open
cowmanjoe opened this issue Nov 7, 2019 · 3 comments
Labels
Bug It's broken and should be fixed Good First Issue Good opportunity for new contributors Help Wanted Contributions especially appreciated Tilemaps Area: Tilemaps core / editor plugins
Milestone

Comments

@cowmanjoe
Copy link
Contributor

Summary

An IndexOutOfRange exception is thrown if the selected Tilemap's Tileset is switched. This exception only occurs if the Tileset has been painted on with Tiles that have a higher index than the new Tileset's maximum index. I also noticed that sometimes the tile pallette is not updated with the new Tileset.

How to reproduce

  • Create two Tilesets, one with more tiles than the other
  • Create a Tilemap with the larger Tileset
  • Paint on the Tilemap with the highest index Tile in the Tileset
  • Set the Tilemap's Tileset to the smaller one by dragging it into the Tileset section of the Tilemap in the object inspector
  • Try painting on the earlier painted tile

Workaround

  • Don't switch the Tileset on a Tilemap that has already been painted on (this is probably a rare case anyway)
  • If you want to switch the Tileset but don't care about the painted tiles, Set them all to the zero index tile (top left corner) before switching the Tileset

Analysis

  • Exception is thrown at Tile.cs:291 when in the UpdateAutoTileCon method
  • Problem seems to be that the Tilemap has tiles with invalid indexes on them
  • Maybe there needs to be a check for these invalid tiles before executing any paint action on them to reset them to normal
@ilexp ilexp added this to the General milestone Nov 11, 2019
@ilexp ilexp added Bug It's broken and should be fixed Tilemaps Area: Tilemaps core / editor plugins Good First Issue Good opportunity for new contributors Help Wanted Contributions especially appreciated labels Nov 11, 2019
@ilexp
Copy link
Member

ilexp commented Nov 11, 2019

Tagging this as Help Wanted and Good First Issue, since I'm suspecting this might be an easy fix, once the location and root cause of the error are identified.

@SirePi
Copy link
Member

SirePi commented May 16, 2020

Tried to reproduce, but can't trigger the error.

Some dirty, non-existing tiles can be observed when changing to a different tileset with a different number of tiles, but I believe it can be considered in the realm of "expected behavior", given the operation that is being performed.

@AdamsLair/duality-core can any of you try to see if they can reproduce this? otherwise I'd be considering closing the issue.

@streepje8
Copy link

Reproduced the issue, the error only occurs when editing after the swap (causing the update function to be called).

I added in a simple bounds check and created a pull request
This is my first time helping an opensource project so I hope I did everything properly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug It's broken and should be fixed Good First Issue Good opportunity for new contributors Help Wanted Contributions especially appreciated Tilemaps Area: Tilemaps core / editor plugins
Development

No branches or pull requests

4 participants