yellowstonegames / SquidLib

Useful tools for roguelike, role-playing, strategy, and other grid-based games in Java. Feedback is welcome!
Other
448 stars 46 forks source link

ArrayIndexOutOfBoundsException in GreasedRegion during DungeonBoneGen.generate(...) #202

Closed nateroe closed 5 years ago

nateroe commented 5 years ago

Generating a small dungeon

    StatefulRNG rng = new StatefulRNG();
    int width = 18;
    int height = 18;
    DungeonGenerator generator = new DungeonGenerator(width, height, rng);
    generator.addDoors(45, true);
    char[][] generated = generator.generate();

Always throws this exception:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
    at java.lang.System.arraycopy(Native Method)
    at squidpony.squidmath.GreasedRegion.refill(GreasedRegion.java:1220)
    at squidpony.squidgrid.mapping.styled.DungeonBoneGen.generate(DungeonBoneGen.java:422)
    at squidpony.squidgrid.mapping.styled.DungeonBoneGen.generate(DungeonBoneGen.java:278)
    at squidpony.squidgrid.mapping.DungeonGenerator.generate(DungeonGenerator.java:474)
    at squidpony.squidgrid.mapping.DungeonGenerator.generate(DungeonGenerator.java:456)
    at com.nateroe.natehack.MapGenerator.generate(MapGenerator.java:32)
    at com.nateroe.natehack.Game.processInput(Game.java:170)
    at com.nateroe.natehack.client.ClientMain.run(ClientMain.java:69)
    at com.nateroe.natehack.client.ClientMain.main(ClientMain.java:277)
tommyettinger commented 5 years ago

I can reproduce this with small height and width, and there's an issue reproduction test in https://github.com/SquidPony/SquidLib/blob/master/squidlib-util/src/test/java/squidpony/issues/Issue202.java . I believe this is fixed as of the latest commit, 2ff1896877. The bug was related to very small map widths, and GreasedRegion inconsistently using the width of a tile when it should have used the smaller of the tile width and map width. It's probably better to depend on a specific commit than -SNAPSHOT, because IDEs can hang on to part of an old SNAPSHOT version in bits and pieces (they're all the same version, "-SNAPSHOT", so comparison is tricky), and if that happens builds won't make any sense.

I'll close this now because every case where the problematic code was found has now been updated.