From 36bf099d54a971112eced46014e1ed78745427e5 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 23 Sep 2016 21:24:56 +0200 Subject: [PATCH] - fixed: object pointers as array members may not be skipped if they are null. - changed S_GetMusic to return a const pointer to the actual music name instead of a copy. The only thing this is used for is the savegame code and it has no use for a copy, it can work far more efficiently with a const pointer. --- src/p_saveg.cpp | 3 +-- src/s_sound.cpp | 4 ++-- src/s_sound.h | 2 +- src/serializer.cpp | 40 +++++++++++++++++++++++++++------------- 4 files changed, 31 insertions(+), 18 deletions(-) diff --git a/src/p_saveg.cpp b/src/p_saveg.cpp index 30f191e4ef..20d82f67ce 100644 --- a/src/p_saveg.cpp +++ b/src/p_saveg.cpp @@ -528,7 +528,7 @@ void P_SerializeSounds(FSerializer &arc) if (arc.isWriting()) { - order = S_GetMusic((char **)&name); + order = S_GetMusic(&name); } arc.StringPtr("musicname", name) ("musicorder", order); @@ -539,7 +539,6 @@ void P_SerializeSounds(FSerializer &arc) if (level.cdtrack == 0 || !S_ChangeCDMusic(level.cdtrack, level.cdid)) S_ChangeMusic(level.Music, level.musicorder); } - delete[] name; } //========================================================================== diff --git a/src/s_sound.cpp b/src/s_sound.cpp index 12b280a74b..866af965a1 100644 --- a/src/s_sound.cpp +++ b/src/s_sound.cpp @@ -2608,13 +2608,13 @@ void S_MIDIDeviceChanged() // //========================================================================== -int S_GetMusic (char **name) +int S_GetMusic (const char **name) { int order; if (mus_playing.name.IsNotEmpty()) { - *name = copystring (mus_playing.name); + *name = mus_playing.name; order = mus_playing.baseorder; } else diff --git a/src/s_sound.h b/src/s_sound.h index 86915ea40d..9b917e25c8 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -334,7 +334,7 @@ void S_RestartMusic (); void S_MIDIDeviceChanged(); -int S_GetMusic (char **name); +int S_GetMusic (const char **name); // Stops the music for sure. void S_StopMusic (bool force); diff --git a/src/serializer.cpp b/src/serializer.cpp index b6e05d1736..7df5bd8fd9 100644 --- a/src/serializer.cpp +++ b/src/serializer.cpp @@ -1514,6 +1514,10 @@ FSerializer &Serialize(FSerializer &arc, const char *key, DObject *&value, DObje } Serialize(arc, key, ndx, nullptr); } + else if (!arc.w->inObject()) + { + arc.w->Null(); + } } else { @@ -1524,30 +1528,40 @@ FSerializer &Serialize(FSerializer &arc, const char *key, DObject *&value, DObje I_Error("Attempt to read object reference without calling ReadObjects first"); } auto val = arc.r->FindKey(key); - if (val != nullptr && val->IsInt()) + if (val != nullptr) { - int index = val->GetInt(); - if (index == -1) + if (val->IsNull()) { - value = WP_NOCHANGE; + value = nullptr; + return arc; } - else + else if (val->IsInt()) { - assert(index >= 0 && index < (int)arc.r->mDObjects.Size()); - if (index >= 0 && index < (int)arc.r->mDObjects.Size()) + int index = val->GetInt(); + if (index == -1) { - value = arc.r->mDObjects[index]; + value = WP_NOCHANGE; } else { - assert(false && "invalid object reference"); - Printf(TEXTCOLOR_RED "Invalid object reference for '%s'", key); - value = nullptr; - arc.mErrors++; + assert(index >= 0 && index < (int)arc.r->mDObjects.Size()); + if (index >= 0 && index < (int)arc.r->mDObjects.Size()) + { + value = arc.r->mDObjects[index]; + } + else + { + assert(false && "invalid object reference"); + Printf(TEXTCOLOR_RED "Invalid object reference for '%s'", key); + value = nullptr; + arc.mErrors++; + if (retcode) *retcode = false; + } } + return arc; } } - else if (!retcode) + if (!retcode) { value = nullptr; }