bitser icon indicating copy to clipboard operation
bitser copied to clipboard

a strange behaviour

Open rostok opened this issue 11 months ago • 1 comments

I am saving my game state into structure local saveData = { game = game:serializeTab(), view = view:serializeTab(), actors = {} } then actors table is filled in a loop using table.insert()

It seems then actors table, being pure integer based, continous array should be iterable using both pairs and ipairs.

However after I use bitser.loads() I encounter non deterministic errors when iterating over this unserialized table using pairs(). For some reason values are sometimes duplicated with same data and different table addresses. The solution here is to iterate over actors with ipairs. This way no duplicated values are found.

Frankly I don't know if bitser is to blame. I have added duplicate checks right after unserialization and even after duplicates are found to check table integrity. Both to no avail. So my only suspicion is that the deserialized table is somehow faulty.

rostok avatar Mar 01 '25 20:03 rostok

Unfortunately, I cannot help you further without a reproducible example. See "How to create a Minimal, Reproducible Example" on Stack Overflow for guidance on how to write such a thing.

pairs iteration order is unfortunately not something Lua can guarantee and therefore bitser cannot do so either. If an order is desired, you're going to have to use other data structures, for example: a sequence of single key/value pair tables, or an index field in the values (assuming they are tables).

bitser should not generate duplicate entries, that is very concerning.

gvx avatar Jul 26 '25 19:07 gvx