HexMod icon indicating copy to clipboard operation
HexMod copied to clipboard

Stack/serialization limit is weirdly enforced

Open object-Object opened this issue 6 months ago • 2 comments

I've mentioned this a few times in Discord, but I don't think an issue has been opened.

The stack/serialization/iota limit, which is used both when serializing iotas and after each frame evaluation in the CastingVM, is checked here:

https://github.com/FallingColors/HexMod/blob/45d519d6a9e0f7c1a723d2fcc8ca59f54b9e8c0e/Common/src/main/java/at/petrak/hexcasting/api/casting/iota/IotaType.java#L79-L111

HexIotaTypes.MAX_SERIALIZATION_TOTAL is currently hardcoded to 1024. However, that's not the actual limit in practice, for two reasons:

  • isTooLargeToSerialize starts counting at 1, because its initial purpose was to check the size of lists, and we include the list itself in the count. However, this still applies when checking the size of the entire stack, reducing the actual maximum legal stack size to 1023.
  • The MAX_SERIALIZATION_TOTAL and MAX_SERIALIZATION_DEPTH checks use >=, not >, reducing the actual maximum legal stack size to 1022.

This also means that the largest possible list could only contain 1021 iotas.

I'm not sure if this counts as a bug really, but it seems weird.

object-Object avatar Aug 24 '24 16:08 object-Object