Fix JsonEncode treating tables with index 0 as arrays - #454
Conversation
Tables with index 0 should be encoded as JSON objects, not arrays. Lua arrays start at index 1, so any table with keys outside 1-N range should be treated as an object. Added IsLuaArray() helper that checks all keys are integers >= 1. Closes BeamMP#348
|
The issue also mentions this related behaviour:
Would you mind attempting to fix this as well in this pr? |
Yes, I can. I'll look at this tomorrow. |
…(shutdown hang), the latter guarded for combined-host mode BeamMP#454 -- Util.JsonEncode treated ANY numeric key as an array index, so a plugin table like {[0]="a",[1]=true} encoded as the bare array ["a",true] and the 0 key vanished silently: the array branch push_back()es values and drops keys. Zero, negative and fractional keys all hit it. A table is now an array only when every key is an integer >= 1 (IsLuaArray), applied at both call sites. BeamMP#501 -- GracefullyShutdown could run every subsystem handler and then hang forever on a lingering thread or a static destructor, leaving a server that had "shut down" but never exited. It now _Exit(0)s once the handlers have run (_Exit deliberately skips atexit/static destructors -- that is what makes it immune to those hangs). FORK GUARD on BeamMP#501: only for the STANDALONE server. In combined-host mode the server is a library inside the launcher process, so exiting there would kill the launcher and the host's own game session with it. Same reasoning as the existing hard-shutdown guard a few lines above, which already checks IsEmbedded(). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Summary
Util.JsonEncodeincorrectly encoding Lua tables with index 0 as JSON arraysIsLuaArray()helper function that validates all keys are integers >= 1Closes #348
Before
After