[Scummvm-git-logs] scummvm master -> 261e37a3400e55e1229f3b60dac51524cca88cd8

somaen noreply at scummvm.org
Fri Jul 19 22:37:40 UTC 2024


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:
261e37a340 WATCHMAKER: Add copy/move constructors to t3dMESH


Commit: 261e37a3400e55e1229f3b60dac51524cca88cd8
    https://github.com/scummvm/scummvm/commit/261e37a3400e55e1229f3b60dac51524cca88cd8
Author: Einar Johan Trøan Sømåen (somaen at scummvm.org)
Date: 2024-07-20T00:37:24+02:00

Commit Message:
WATCHMAKER: Add copy/move constructors to t3dMESH

The old shallow-copying led to double-free, this hopefully fixes that.

For now, the move-constructor doesn't end up actually being used, as
Common::Array doesn't make us of it in push_back(), but if that's fixed
it should.

Changed paths:
    engines/watchmaker/3d/t3d_body.cpp
    engines/watchmaker/3d/t3d_mesh.cpp
    engines/watchmaker/3d/t3d_mesh.h
    engines/watchmaker/t3d.h


diff --git a/engines/watchmaker/3d/t3d_body.cpp b/engines/watchmaker/3d/t3d_body.cpp
index 8391fd305bd..0912e462c15 100644
--- a/engines/watchmaker/3d/t3d_body.cpp
+++ b/engines/watchmaker/3d/t3d_body.cpp
@@ -108,8 +108,9 @@ void t3dLoadMaterials(WGame &game, t3dBODY *b, Common::SeekableReadStream &strea
 
 void t3dLoadMeshes(t3dBODY *b, uint32 numMeshes, t3dMESH *&ReceiveRipples, uint8 &Mirror, Common::SeekableReadStream &stream) {
 	b->MeshTable.clear();
+	b->MeshTable.reserve(numMeshes);
 	for (uint32 mesh = 0; mesh < numMeshes; mesh++) {
-		b->MeshTable.push_back(t3dMESH(b, stream, ReceiveRipples, Mirror));
+		b->MeshTable.push_back(Common::move(t3dMESH(b, stream, ReceiveRipples, Mirror)));
 	}
 }
 
diff --git a/engines/watchmaker/3d/t3d_mesh.cpp b/engines/watchmaker/3d/t3d_mesh.cpp
index 3b859f569ec..fe14ba26fc8 100644
--- a/engines/watchmaker/3d/t3d_mesh.cpp
+++ b/engines/watchmaker/3d/t3d_mesh.cpp
@@ -187,6 +187,170 @@ t3dMESH::t3dMESH(t3dBODY *b, Common::SeekableReadStream &stream, t3dMESH *&Recei
 	}
 }
 
+t3dMESH &t3dMESH::operator=(t3dMESH rhs) {
+	SWAP(name, rhs.name);
+	SWAP(portalName, rhs.portalName);
+	SWAP(NumVerts, rhs.NumVerts);
+	SWAP(NumNormals, rhs.NumNormals);
+	SWAP(NumVerticesNormals, rhs.NumVerticesNormals);
+	SWAP(SavedVertexBuffer, rhs.SavedVertexBuffer);
+	SWAP(VertexBuffer, rhs.VertexBuffer);
+	SWAP(OldVertexBuffer, rhs.OldVertexBuffer);
+	SWAP(VertsInterpolants, rhs.VertsInterpolants);
+	SWAP(VBptr, rhs.VBptr);
+	SWAP(MorphFrames, rhs.MorphFrames);
+	SWAP(FList, rhs.FList);
+	SWAP(NList, rhs.NList);
+	SWAP(Pos, rhs.Pos);
+	SWAP(Trasl, rhs.Trasl);
+	SWAP(Radius, rhs.Radius);
+	SWAP(BBoxAverageZ, rhs.BBoxAverageZ);
+	SWAP(Intersection, rhs.Intersection);
+	SWAP(Matrix, rhs.Matrix);
+	SWAP(LightmapDim, rhs.LightmapDim);
+	SWAP(ModVertices, rhs.ModVertices);
+	SWAP(CurFrame, rhs.CurFrame);
+	SWAP(LastFrame, rhs.LastFrame);
+	SWAP(BlendPercent, rhs.BlendPercent);
+	SWAP(LastBlendPercent, rhs.LastBlendPercent);
+	SWAP(ExpressionFrame, rhs.ExpressionFrame);
+	SWAP(LastExpressionFrame, rhs.LastExpressionFrame);
+	SWAP(DefaultAnim, rhs.DefaultAnim);
+	SWAP(Anim, rhs.Anim);
+	SWAP(WaterBuffer1, rhs.WaterBuffer1);
+	SWAP(WaterBuffer2, rhs.WaterBuffer2);
+	SWAP(WavesSpeed, rhs.WavesSpeed);
+	SWAP(YSpeed, rhs.YSpeed);
+	SWAP(XInc, rhs.XInc);
+	SWAP(YInc, rhs.YInc);
+	SWAP(Flags, rhs.Flags);
+	SWAP(PortalList, rhs.PortalList);
+	SWAP(RejectedMeshes, rhs.RejectedMeshes);
+
+	Common::copy(rhs.BBox, rhs.BBox + 8, BBox);
+	Common::copy(rhs.BBoxNormal, rhs.BBoxNormal + 6, BBoxNormal);
+	Common::copy(rhs.SolarRGBVar, rhs.SolarRGBVar + 4, SolarRGBVar);
+
+	return *this;
+}
+
+t3dMESH::t3dMESH(const t3dMESH &other) :
+	name(other.name),
+	portalName(other.portalName),
+	NumVerts(other.NumVerts),
+	NumNormals(other.NumNormals),
+	NumVerticesNormals(other.NumVerticesNormals),
+	SavedVertexBuffer(nullptr),
+	VertexBuffer(new gVertex[other.NumVerts]()),
+	OldVertexBuffer(nullptr),
+	VertsInterpolants(nullptr),
+	VBptr(other.VBptr),
+	MorphFrames(other.MorphFrames),
+	FList(other.FList),
+	NList(other.NList),
+	Pos(other.Pos),
+	Trasl(other.Trasl),
+	Radius(other.Radius),
+	BBoxAverageZ(other.BBoxAverageZ),
+	Intersection(other.Intersection),
+	Matrix(other.Matrix),
+	LightmapDim(other.LightmapDim),
+	ModVertices(other.ModVertices),
+	CurFrame(other.CurFrame),
+	LastFrame(other.LastFrame),
+	BlendPercent(other.BlendPercent),
+	LastBlendPercent(other.LastBlendPercent),
+	ExpressionFrame(other.ExpressionFrame),
+	LastExpressionFrame(other.LastExpressionFrame),
+	DefaultAnim(other.DefaultAnim),
+	Anim(other.Anim),
+	WaterBuffer1(other.WaterBuffer1),
+	WaterBuffer2(other.WaterBuffer2),
+	WavesSpeed(other.WavesSpeed),
+	YSpeed(other.YSpeed),
+	XInc(other.XInc),
+	YInc(other.YInc),
+	Flags(other.Flags),
+	PortalList(other.PortalList),
+	RejectedMeshes(other.RejectedMeshes) {
+
+	Common::copy(other.VertexBuffer, other.VertexBuffer + NumVerts, VertexBuffer);
+	if (other.SavedVertexBuffer) {
+		SavedVertexBuffer = new gVertex[other.NumVerts]();
+		Common::copy(other.SavedVertexBuffer, other.SavedVertexBuffer + NumVerts, SavedVertexBuffer);
+	}
+	if (other.OldVertexBuffer) {
+		OldVertexBuffer = new gVertex[other.NumVerts]();
+		Common::copy(other.OldVertexBuffer, other.OldVertexBuffer + NumVerts, OldVertexBuffer);
+	}
+	if (other.VertsInterpolants) {
+		VertsInterpolants = t3dCalloc<t3dV3F>(NumVerts);
+		Common::copy(other.VertsInterpolants, other.VertsInterpolants + NumVerts, VertsInterpolants);
+	}
+	Common::copy(other.BBox, other.BBox + 8, BBox);
+	Common::copy(other.BBoxNormal, other.BBoxNormal + 6, BBoxNormal);
+	Common::copy(other.SolarRGBVar, other.SolarRGBVar + 4, SolarRGBVar);
+}
+
+
+t3dMESH::t3dMESH(t3dMESH &&old) :
+	name(Common::move(old.name)),
+	portalName(Common::move(old.portalName)),
+	NumVerts(old.NumVerts),
+	NumNormals(old.NumNormals),
+	NumVerticesNormals(old.NumVerticesNormals),
+	SavedVertexBuffer(old.SavedVertexBuffer),
+	VertexBuffer(old.VertexBuffer),
+	OldVertexBuffer(old.OldVertexBuffer),
+	VertsInterpolants(old.VertsInterpolants),
+	VBptr(old.VBptr),
+	MorphFrames(Common::move(old.MorphFrames)),
+	FList(Common::move(old.FList)),
+	NList(Common::move(old.NList)),
+	Pos(Common::move(old.Pos)),
+	Trasl(Common::move(old.Trasl)),
+	Radius(old.Radius),
+	BBoxAverageZ(old.BBoxAverageZ),
+	Intersection(Common::move(old.Intersection)),
+	Matrix(Common::move(old.Matrix)),
+	LightmapDim(old.LightmapDim),
+	ModVertices(Common::move(old.ModVertices)),
+	CurFrame(old.CurFrame),
+	LastFrame(old.LastFrame),
+	BlendPercent(old.BlendPercent),
+	LastBlendPercent(old.LastBlendPercent),
+	ExpressionFrame(old.ExpressionFrame),
+	LastExpressionFrame(old.LastExpressionFrame),
+	DefaultAnim(Common::move(old.DefaultAnim)),
+	Anim(Common::move(old.Anim)),
+	WaterBuffer1(old.WaterBuffer1),
+	WaterBuffer2(old.WaterBuffer2),
+	WavesSpeed(old.WavesSpeed),
+	YSpeed(old.YSpeed),
+	XInc(old.XInc),
+	YInc(old.YInc),
+	Flags(old.Flags),
+	PortalList(old.PortalList),
+	RejectedMeshes(Common::move(old.RejectedMeshes)) {
+
+	old.SavedVertexBuffer = nullptr;
+	old.VertexBuffer = nullptr;
+	old.OldVertexBuffer = nullptr;
+	old.VertsInterpolants = nullptr;
+	old.VBptr = nullptr;
+	for (int i = 0; i < 8; i++) {
+		BBox[i] = Common::move(old.BBox[i]);
+	}
+	for (int i = 0; i < 6; i++) {
+		BBoxNormal[i] = Common::move(old.BBoxNormal[i]);
+	}
+	old.WaterBuffer1 = nullptr;
+	old.WaterBuffer2 = nullptr;
+	for (int i = 0; i < 4; i++) {
+		SolarRGBVar[i] = Common::move(old.SolarRGBVar[i]);
+	}
+}
+
 t3dMESH::~t3dMESH() {
 	release();
 }
diff --git a/engines/watchmaker/3d/t3d_mesh.h b/engines/watchmaker/3d/t3d_mesh.h
index 0d433c1bbcb..f7c002e67c1 100644
--- a/engines/watchmaker/3d/t3d_mesh.h
+++ b/engines/watchmaker/3d/t3d_mesh.h
@@ -141,6 +141,9 @@ struct t3dMESH {
 
 	t3dMESH() = default;
 	t3dMESH(t3dBODY *b, Common::SeekableReadStream &stream, t3dMESH *&ReceiveRipples, uint8 &Mirror);
+	t3dMESH(const t3dMESH &other);
+	t3dMESH(t3dMESH &&old);
+	t3dMESH& operator=(t3dMESH rhs);
 	~t3dMESH();
 	void loadFaces(t3dBODY *b, Common::SeekableReadStream &stream, int numFaces);
 	void release();
diff --git a/engines/watchmaker/t3d.h b/engines/watchmaker/t3d.h
index c960311fa04..7ee819d406e 100644
--- a/engines/watchmaker/t3d.h
+++ b/engines/watchmaker/t3d.h
@@ -130,6 +130,21 @@ struct t3dBONEANIM {
 	t3dF32      *Dist = nullptr;                // distanca form start frame (for walk and default)
 	uint16      NumBones = 0;                   // num bones
 	uint16      NumFrames = 0;                  // num frames
+
+	t3dBONEANIM() = default;
+	t3dBONEANIM(const t3dBONEANIM &other) = default;
+	t3dBONEANIM& operator=(const t3dBONEANIM &rhs) = default;
+	t3dBONEANIM(t3dBONEANIM &&old) :
+		BoneTable(old.BoneTable),
+		Dist(old.Dist),
+		NumBones(old.NumBones),
+		NumFrames(old.NumFrames) {
+
+		old.BoneTable = nullptr;
+		old.Dist = nullptr;
+		old.NumBones = 0;
+		old.NumFrames = 0;
+	}
 };
 
 struct t3dMODVERTS {




More information about the Scummvm-git-logs mailing list