diff --git a/src/json.cpp b/src/json.cpp index 7dd969daa..3c455d52c 100644 --- a/src/json.cpp +++ b/src/json.cpp @@ -220,7 +220,7 @@ FSerializer &Serialize(FSerializer &arc, const char *key, subsector_t *&ss, subs { if (hasglnodes) { - TArray encoded((numsubsectors + 5) / 6); + TArray encoded(1 + (numsubsectors + 5) / 6); int p = 0; for (int i = 0; i < numsubsectors; i += 6) { diff --git a/src/serializer.cpp b/src/serializer.cpp index 9f85da9b6..db467c21a 100644 --- a/src/serializer.cpp +++ b/src/serializer.cpp @@ -71,9 +71,12 @@ struct FWriter TArray mDObjects; TMap mObjectMap; + FWriter() : mWriter(mOutString) + {} + bool inObject() const { - return mInObject.Size() > 0 && inObject(); + return mInObject.Size() > 0 && mInObject.Last(); } }; @@ -127,7 +130,7 @@ struct FReader bool FSerializer::OpenWriter() { - if (w != nullptr || r == nullptr) return false; + if (w != nullptr || r != nullptr) return false; w = new FWriter; return true; @@ -141,7 +144,7 @@ bool FSerializer::OpenWriter() bool FSerializer::OpenReader(const char *buffer, size_t length) { - if (w != nullptr || r == nullptr) return false; + if (w != nullptr || r != nullptr) return false; r = new FReader(buffer, length); return true; } @@ -321,7 +324,7 @@ void FSerializer::EndArray() { if (isWriting()) { - if (w->inObject()) + if (!w->inObject()) { w->mWriter.EndArray(); w->mInObject.Pop(); @@ -859,7 +862,7 @@ FSerializer &Serialize(FSerializer &arc, const char *key, FTextureID &value, FTe arc.w->mWriter.StartArray(); arc.w->mWriter.String(name); arc.w->mWriter.Int(pic->UseType); - arc.w->mWriter.EndObject(); + arc.w->mWriter.EndArray(); } } else