lep / jassdoc

Document the WarCraft 3 API
52 stars 20 forks source link

Too many region cells disperse non-terrain pathing maps #164

Open WaterKnight opened 4 weeks ago

WaterKnight commented 4 weeks ago

This was discussed in the Hive Discord recently.

Creating too many regions/adding too many cells to them with CreateRegion/RegionAddCell/RegionAddRect (at least when using the same cells for multiple regions over and over again) leads to pathing maps of destructables and structures inside the region affecting pathing across the map, gradually creating various patterns.

The original pathing of the destructables/structures will also be moved at some point within the region and jump in patterns with further regions added.

The pathing of the destructables/structures can wrap around the edges of the region, and the pathing of the pathing spawned outside can wrap around the map edges.

The additional pathing can cut into the region, but will be cleared from the region every other iteration.

The destructable/structure pathing moved around can split apart in some iterations. Partially it looks like there are rounding errors responsible for that.

Killing/removing the destructable/structure with no dead version pathing map removes the moved pathing.

It seems like some overflow is happening. After the the problem appears, the game will freeze when trying to end the map session. Some iterations can also take very long or freeze the game.

There appear to be a couple of factors involved like the size and shape of the pathing maps of the destructables/structures, the size of the region, the map size, as well as other interactions. In the attached map, I visualized the pathing using an item to check each cell and images for each cell. All of this needs further testing, but it seemed to me like even the item and/or image handling affected it after the problem first sets in because the amount of iterations of creating new regions before repainting matters in terms of the increment of additional pathing (this could further indicate the memory management getting out of bounds).

https://github.com/user-attachments/assets/241e8cd4-60bd-472a-b87d-1a49432c7084

In the attached test map, press the P key to enable the pathing visualization. You will see a red square in the center of the map, which is the pathing map of a single tree. This action takes some seconds, because an image for each cell is created upfront in order to decrease interactions that may appear later if it was done lazily. Next, send 900 as a chat message to create 900 regions and adding cells making up the lighter rectangle on the minimap to each. This will take some time as well. You may already notice that the square moved. If you then send 1 as a chat message, you will see that various dots appear around the region and this will get more with each further iteration. Using this action sequence, the game freezes at about 910 total regions. Other action sequences lead to other outcomes.

region_pathingbug4.zip

This problem was observed in real maps using a number of Enter/Leave events with the playable map area. The test map is very small, so a lot of regions are required, but with larger regions/maps, this may happen with much fewer regions. Maps which use lots of Enter/Leave events with the same area can avoid the problem by re-using one region with the area.