[Scummvm-git-logs] scummvm master -> 9ee2fdc19c32e5dddc0f61a69ec117bb8b39bb02

mgerhardy martin.gerhardy at gmail.com
Wed Feb 24 19:17:52 UTC 2021


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

Summary:
e6f0a51cdc TWINE: handle invalid trajectory indices
9ee2fdc19c TWINE: fixed compiler warning in release mode


Commit: e6f0a51cdca08e03e5f73e12b90e3ccb9f847d78
    https://github.com/scummvm/scummvm/commit/e6f0a51cdca08e03e5f73e12b90e3ccb9f847d78
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2021-02-24T19:00:00+01:00

Commit Message:
TWINE: handle invalid trajectory indices

Changed paths:
    engines/twine/holomap.cpp
    engines/twine/holomap.h


diff --git a/engines/twine/holomap.cpp b/engines/twine/holomap.cpp
index 735ae1bda2..10a5af68c7 100644
--- a/engines/twine/holomap.cpp
+++ b/engines/twine/holomap.cpp
@@ -293,13 +293,16 @@ void Holomap::renderHolomapModel(const uint8 *bodyPtr, int32 x, int32 y, int32 z
 }
 
 Holomap::TrajectoryData Holomap::loadTrajectoryData(int32 trajectoryIdx) {
-	TrajectoryData data;
 	Common::MemoryReadStream stream(_engine->_resources->holomapPointAnimPtr, _engine->_resources->holomapPointAnimSize);
 	for (int32 trajIdx = 0; trajIdx < trajectoryIdx; ++trajIdx) {
+		if (stream.eos() || stream.err()) {
+			return TrajectoryData();
+		}
 		stream.skip(12);
 		const int16 animVal = stream.readSint16LE();
 		stream.skip(4 * animVal);
 	}
+	TrajectoryData data;
 	data.locationIdx = stream.readSint16LE();
 	data.trajLocationIdx = stream.readSint16LE();
 	data.vehicleIdx = stream.readSint16LE();
@@ -318,14 +321,18 @@ Holomap::TrajectoryData Holomap::loadTrajectoryData(int32 trajectoryIdx) {
 void Holomap::drawHolomapTrajectory(int32 trajectoryIndex) {
 	debug("Draw trajectory index %i", trajectoryIndex);
 
+	const Holomap::TrajectoryData &data = loadTrajectoryData(trajectoryIndex);
+	if (!data.isValid()) {
+		warning("Failed to load trajectory data for index %i", trajectoryIndex);
+		return;
+	}
+
 	_engine->exitSceneryView();
 	_engine->_interface->resetClip();
 	_engine->_screens->clearScreen();
 	_engine->setPalette(_engine->_screens->paletteRGBA);
 
 	loadHolomapGFX();
-
-	const Holomap::TrajectoryData &data = loadTrajectoryData(trajectoryIndex);
 	ScopedEngineFreeze timeFreeze(_engine);
 	_engine->_renderer->setCameraPosition(400, 240, 128, 1024, 1024);
 	_engine->_renderer->setCameraAngle(0, 0, 0, data.x, data.y, data.z, 5300);
diff --git a/engines/twine/holomap.h b/engines/twine/holomap.h
index 16db4ca05f..0e7cbde270 100644
--- a/engines/twine/holomap.h
+++ b/engines/twine/holomap.h
@@ -85,19 +85,23 @@ private:
 	int _projectedSurfaceIndex = 0;
 
 	struct TrajectoryData {
-		int16 locationIdx;
-		int16 trajLocationIdx;
-		int16 vehicleIdx;
-		int16 x;
-		int16 y;
-		int16 z;
-		int16 numAnimFrames;
+		int16 locationIdx = -1;
+		int16 trajLocationIdx = -1;
+		int16 vehicleIdx = -1;
+		int16 x = 0;
+		int16 y = 0;
+		int16 z = 0;
+		int16 numAnimFrames = 0;
 		struct TrajectoryPos {
-			int16 x;
-			int16 y;
+			int16 x = 0;
+			int16 y = 0;
 		};
 		TrajectoryPos positions[512];
 
+		bool isValid() const {
+			return locationIdx != -1;
+		}
+
 		/**
 		 * The HQR index of the vehicle model for the holomap
 		 * @note Multiplied by 2 because the model index is always followed by the corresponding animation index for that model


Commit: 9ee2fdc19c32e5dddc0f61a69ec117bb8b39bb02
    https://github.com/scummvm/scummvm/commit/9ee2fdc19c32e5dddc0f61a69ec117bb8b39bb02
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2021-02-24T19:00:00+01:00

Commit Message:
TWINE: fixed compiler warning in release mode

Changed paths:
    engines/twine/parser/body.cpp
    engines/twine/parser/body.h
    engines/twine/text.cpp


diff --git a/engines/twine/parser/body.cpp b/engines/twine/parser/body.cpp
index cfb552af62..4d3f6e98cf 100644
--- a/engines/twine/parser/body.cpp
+++ b/engines/twine/parser/body.cpp
@@ -148,7 +148,7 @@ void BodyData::loadSpheres(Common::SeekableReadStream &stream) {
 }
 
 bool BodyData::loadFromStream(Common::SeekableReadStream &stream) {
-	*(uint16 *)&bodyFlag = stream.readUint16LE();
+	bodyFlag.value = stream.readUint16LE();
 	minsx = stream.readSint16LE();
 	maxsx = stream.readSint16LE();
 	minsy = stream.readSint16LE();
diff --git a/engines/twine/parser/body.h b/engines/twine/parser/body.h
index 1666f104e7..bbc46f4f44 100644
--- a/engines/twine/parser/body.h
+++ b/engines/twine/parser/body.h
@@ -97,23 +97,26 @@ private:
 	BoneFrame _boneStates[560];
 
 public:
-	struct BodyFlags {
-		uint16 unk1 : 1;            // 1 << 0
-		uint16 animated : 1;        // 1 << 1
-		uint16 unk3 : 1;            // 1 << 2
-		uint16 unk4 : 1;            // 1 << 3
-		uint16 unk5 : 1;            // 1 << 4
-		uint16 unk6 : 1;            // 1 << 5
-		uint16 unk7 : 1;            // 1 << 6
-		uint16 alreadyPrepared : 1; // 1 << 7
-		uint16 unk9 : 1;            // 1 << 8
-		uint16 unk10 : 1;           // 1 << 9
-		uint16 unk11 : 1;           // 1 << 10
-		uint16 unk12 : 1;           // 1 << 11
-		uint16 unk13 : 1;           // 1 << 12
-		uint16 unk14 : 1;           // 1 << 13
-		uint16 unk15 : 1;           // 1 << 14
-		uint16 unk16 : 1;           // 1 << 15
+	union BodyFlags {
+		struct BitMask {
+			uint16 unk1 : 1;            // 1 << 0
+			uint16 animated : 1;        // 1 << 1
+			uint16 unk3 : 1;            // 1 << 2
+			uint16 unk4 : 1;            // 1 << 3
+			uint16 unk5 : 1;            // 1 << 4
+			uint16 unk6 : 1;            // 1 << 5
+			uint16 unk7 : 1;            // 1 << 6
+			uint16 alreadyPrepared : 1; // 1 << 7
+			uint16 unk9 : 1;            // 1 << 8
+			uint16 unk10 : 1;           // 1 << 9
+			uint16 unk11 : 1;           // 1 << 10
+			uint16 unk12 : 1;           // 1 << 11
+			uint16 unk13 : 1;           // 1 << 12
+			uint16 unk14 : 1;           // 1 << 13
+			uint16 unk15 : 1;           // 1 << 14
+			uint16 unk16 : 1;           // 1 << 15
+		} mask;
+		uint16 value;
 	} bodyFlag;
 
 	int16 minsx = 0;
@@ -125,7 +128,7 @@ public:
 	int16 offsetToData = 0;
 
 	inline bool isAnimated() const {
-		return bodyFlag.animated;
+		return bodyFlag.mask.animated;
 	}
 
 	inline uint getNumBones() const {
diff --git a/engines/twine/text.cpp b/engines/twine/text.cpp
index e1621aedd3..a6a347adb5 100644
--- a/engines/twine/text.cpp
+++ b/engines/twine/text.cpp
@@ -335,11 +335,11 @@ void Text::initText(int32 index) {
 }
 
 void Text::initProgressiveTextBuffer() {
-	Common::fill(&_progressiveTextBuffer[0], &_progressiveTextBuffer[256], ' ');
+	Common::fill(&_progressiveTextBuffer[0], &_progressiveTextBuffer[sizeof(_progressiveTextBuffer)], ' ');
 	// the end of the buffer defines how fast the next page is shown - as the
 	// whitespaces are handled in the fade in process, too. But we need at least 32 chars,
 	// to completly fade in the last characters of a full page (see TEXT_MAX_FADE_IN_CHR)
-	_progressiveTextBuffer[255] = '\0';
+	_progressiveTextBuffer[sizeof(_progressiveTextBuffer) - 1] = '\0';
 	_progressiveTextBufferPtr = _progressiveTextBuffer;
 	_dialTextBoxCurrentLine = 0;
 }




More information about the Scummvm-git-logs mailing list