From 23ed01fffe780960c425dd9a91fee06f5db36de5 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Sat, 4 Jun 2005 23:16:27 +0000 Subject: [PATCH] deep copy to fix crash reverting in editor --- stepmania/src/Song.cpp | 12 ++++-------- stepmania/src/song.h | 7 +++++-- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/stepmania/src/Song.cpp b/stepmania/src/Song.cpp index b24e20e67e..9448d4d110 100644 --- a/stepmania/src/Song.cpp +++ b/stepmania/src/Song.cpp @@ -51,8 +51,8 @@ const float DEFAULT_MUSIC_SAMPLE_LENGTH = 12.f; Song::Song() { FOREACH_BackgroundLayer( i ) - m_BackgroundChanges[i] = new vector; - m_ForegroundChanges = new vector; + m_BackgroundChanges[i] = AutoPtrCopyOnWrite(new VBackgroundChange); + m_ForegroundChanges = AutoPtrCopyOnWrite(new VBackgroundChange); m_LoadedFromProfile = PROFILE_SLOT_INVALID; @@ -72,10 +72,6 @@ Song::Song() Song::~Song() { - FOREACH_BackgroundLayer( i ) - SAFE_DELETE( m_BackgroundChanges[i] ); - SAFE_DELETE( m_ForegroundChanges ); - FOREACH( Steps*, m_vpSteps, s ) SAFE_DELETE( *s ); m_vpSteps.clear(); @@ -1223,7 +1219,7 @@ const vector &Song::GetBackgroundChanges( BackgroundLayer bl ) } vector &Song::GetBackgroundChanges( BackgroundLayer bl ) { - return *(m_BackgroundChanges[bl]); + return *(m_BackgroundChanges[bl].Get()); } const vector &Song::GetForegroundChanges() const @@ -1232,7 +1228,7 @@ const vector &Song::GetForegroundChanges() const } vector &Song::GetForegroundChanges() { - return *m_ForegroundChanges; + return *m_ForegroundChanges.Get(); } diff --git a/stepmania/src/song.h b/stepmania/src/song.h index 66937bca76..3da399d9f0 100644 --- a/stepmania/src/song.h +++ b/stepmania/src/song.h @@ -6,6 +6,7 @@ #include "TimingData.h" #include "Difficulty.h" #include "EnumHelper.h" +#include "RageUtil_AutoPtr.h" class Steps; class Style; @@ -147,9 +148,11 @@ public: TimingData m_Timing; + typedef vector VBackgroundChange; private: - vector *m_BackgroundChanges[NUM_BackgroundLayer]; // these must be sorted before gameplay - vector *m_ForegroundChanges; // this must be sorted before gameplay + // AutoPtr instead of raw pointer so that the auto gen'd copy constructor works correctly. + AutoPtrCopyOnWrite m_BackgroundChanges[NUM_BackgroundLayer]; // these must be sorted before gameplay + AutoPtrCopyOnWrite m_ForegroundChanges; // this must be sorted before gameplay public: const vector &GetBackgroundChanges( BackgroundLayer bl ) const; vector &GetBackgroundChanges( BackgroundLayer bl );