[Scummvm-git-logs] scummvm branch-2-8 -> 6dfed234773480eb4815b5a4264d916568c38a3b

moralrecordings noreply at scummvm.org
Sat Dec 16 07:37:18 UTC 2023


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
6dfed23477 DIRECTOR: XOBJ: Make CueSheet in AppleCDXObject a SharedPtr


Commit: 6dfed234773480eb4815b5a4264d916568c38a3b
    https://github.com/scummvm/scummvm/commit/6dfed234773480eb4815b5a4264d916568c38a3b
Author: Scott Percival (code at moral.net.au)
Date: 2023-12-16T15:37:06+08:00

Commit Message:
DIRECTOR: XOBJ: Make CueSheet in AppleCDXObject a SharedPtr

XObjects are cloned by LC::call, which apparently has a magic copy
constructor. This means that any raw pointers inside the XObject will get
thrown into the cloned object, upsetting the fragile kayfabe of ownership
which underpins memory safety in C++.

Fixes the first movie switch in Classical Cats.

Changed paths:
    engines/director/lingo/xlibs/applecdxobj.cpp
    engines/director/lingo/xlibs/applecdxobj.h


diff --git a/engines/director/lingo/xlibs/applecdxobj.cpp b/engines/director/lingo/xlibs/applecdxobj.cpp
index 09c4db505a8..fdda01ed3fe 100644
--- a/engines/director/lingo/xlibs/applecdxobj.cpp
+++ b/engines/director/lingo/xlibs/applecdxobj.cpp
@@ -144,13 +144,12 @@ AppleCDXObject::AppleCDXObject(ObjectType ObjectType) :Object<AppleCDXObject>("A
 	_objType = ObjectType;
 	_inpoint = 0;
 	_outpoint = 0;
-	_cue = nullptr;
 
 	Common::File cuefile;
 	if (cuefile.open("disc.cue")) {
 		Common::String cuestring = cuefile.readString(0, cuefile.size());
 
-		_cue = new Common::CueSheet(cuestring.c_str());
+		_cue = Common::SharedPtr<Common::CueSheet>(new Common::CueSheet(cuestring.c_str()));
 	}
 }
 
@@ -160,9 +159,6 @@ void AppleCDXObj::m_new(int nargs) {
 
 void AppleCDXObj::m_dispose(int nargs) {
 	g_director->_system->getAudioCDManager()->stop();
-
-	AppleCDXObject *me = static_cast<AppleCDXObject *>(g_lingo->_state->me.u.obj);
-	delete me->_cue;
 }
 
 void AppleCDXObj::m_still(int nargs) {
diff --git a/engines/director/lingo/xlibs/applecdxobj.h b/engines/director/lingo/xlibs/applecdxobj.h
index b62b942328b..24f7d521a2d 100644
--- a/engines/director/lingo/xlibs/applecdxobj.h
+++ b/engines/director/lingo/xlibs/applecdxobj.h
@@ -22,6 +22,8 @@
 #ifndef DIRECTOR_LINGO_XLIBS_APPLECDXOBJ_H
 #define DIRECTOR_LINGO_XLIBS_APPLECDXOBJ_H
 
+#include "common/ptr.h"
+
 namespace Common {
 	class CueSheet;
 }
@@ -37,7 +39,7 @@ public:
 	// a value store it internally and return it via a subsequent
 	// call to mGetValue.
 	int _returnValue;
-	Common::CueSheet *_cue;
+	Common::SharedPtr<Common::CueSheet> _cue;
 };
 
 namespace AppleCDXObj {




More information about the Scummvm-git-logs mailing list