nvs / gem

Gem TD+: A Warcraft III Tower Defense
https://discord.gg/PxNNp77
26 stars 2 forks source link

1.5.1: Save/load compatibility broken #389

Closed nvs closed 5 years ago

nvs commented 5 years ago

Not sure of the cause. But seems to have been introduced in 1.5.1. Optimization seems to play a role.

nvs commented 5 years ago

Bisecting has pointed to the following commit: 5bc45d8ad82992b61df07064771320dbd368325b. And only when optimizing. Need to figure out why.

Edit: Well, for starters, that is a pretty long string in a quest. I would image that is why. But why does optimization matter?

nvs commented 5 years ago

The exact problem is simple. A single string declared in the war3map.j will break save/load compatibility if it exceeds 1023 characters. A single string, in memory, cannot exceed 1023 bytes or it will do the same. There is a subtle difference.

Gem uses \n in changelogs. This takes two characters in the file but only one byte in memory once the war3map.j has been read. For a version of the map that was not optimized, this would create a string less than 1023 bytes by concatenating multiple smaller ones together. For an optimized version, however, the entire string is already combined within the war3map.j. The length, when counting each \n as two bytes instead of one, exceeded 1023.