[Scummvm-git-logs] scummvm master -> 6c33b126702b740a0f1e69ee159274bb4b1d15f2

mduggan noreply at scummvm.org
Tue Jan 24 11:00:59 UTC 2023


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

Summary:
3b94c065e7 TETRAEDGE: Add simple corrupt save checks
f18533bb05 TETRAEDGE: Slight cleanup for light directions
6c33b12670 TETRAEDGE: Fix suspicious use of pointers as integers


Commit: 3b94c065e7fdcafc318335af97603a34ac3ad74f
    https://github.com/scummvm/scummvm/commit/3b94c065e7fdcafc318335af97603a34ac3ad74f
Author: Matthew Duggan (mgithub at guarana.org)
Date: 2023-01-24T19:24:59+09:00

Commit Message:
TETRAEDGE: Add simple corrupt save checks

Changed paths:
    engines/tetraedge/game/cellphone.cpp
    engines/tetraedge/game/inventory.cpp


diff --git a/engines/tetraedge/game/cellphone.cpp b/engines/tetraedge/game/cellphone.cpp
index bcfeb661b2e..c49253d0297 100644
--- a/engines/tetraedge/game/cellphone.cpp
+++ b/engines/tetraedge/game/cellphone.cpp
@@ -159,6 +159,8 @@ Common::Error Cellphone::syncState(Common::Serializer &s) {
 	Common::Array<Common::String> numbers = _addedNumbers;
 	uint numElems = numbers.size();
 	s.syncAsUint32LE(numElems);
+	if (numElems > 1000)
+		error("Unexpected number of elems syncing cellphone");
 	numbers.resize(numElems);
 	for (uint i = 0; i < numElems; i++) {
 		s.syncString(numbers[i]);
@@ -166,6 +168,7 @@ Common::Error Cellphone::syncState(Common::Serializer &s) {
 	if (s.isLoading()) {
 		if (!_addedNumbers.empty())
 			leave();
+
 		for (auto num : numbers)
 			addNumber(num);
 	}
diff --git a/engines/tetraedge/game/inventory.cpp b/engines/tetraedge/game/inventory.cpp
index dcf5fb990ad..8e48c1b0b45 100644
--- a/engines/tetraedge/game/inventory.cpp
+++ b/engines/tetraedge/game/inventory.cpp
@@ -500,6 +500,9 @@ bool Inventory::updateLayout() {
 Common::Error Inventory::syncState(Common::Serializer &s) {
 	uint nitems = _invObjects.size();
 	s.syncAsUint32LE(nitems);
+	if (nitems > 1000)
+		error("Unexpected number of elems syncing inventory");
+
 	if (s.isLoading()) {
 #ifdef TETRAEDGE_DEBUG_SAVELOAD
 		debug("Inventory::syncState: --- Loading %d inventory items: ---", nitems);


Commit: f18533bb055108c53d8cb57063f2c308f6d5ca9a
    https://github.com/scummvm/scummvm/commit/f18533bb055108c53d8cb57063f2c308f6d5ca9a
Author: Matthew Duggan (mgithub at guarana.org)
Date: 2023-01-24T19:27:49+09:00

Commit Message:
TETRAEDGE: Slight cleanup for light directions

Changed paths:
    engines/tetraedge/te/te_light.cpp
    engines/tetraedge/te/te_light_opengl.cpp
    engines/tetraedge/te/te_light_tinygl.cpp


diff --git a/engines/tetraedge/te/te_light.cpp b/engines/tetraedge/te/te_light.cpp
index fc47f6b319a..d8e8b2f584c 100644
--- a/engines/tetraedge/te/te_light.cpp
+++ b/engines/tetraedge/te/te_light.cpp
@@ -34,11 +34,11 @@
 namespace Tetraedge {
 
 /*static*/
-uint32 TeLight::_globalAmbientColor;
+uint32 TeLight::_globalAmbientColor = 0xffffffff;
 
 TeLight::TeLight() : _colAmbient(0, 0, 0, 0xff), _colDiffuse(0, 0, 0, 0xff), _colSpecular(0xff, 0xff, 0xff, 0xff),
 _constAtten(1.0f), _linearAtten(0.0f), _quadraticAtten(0.0f), _cutoff(0.0f), _exponent(0.0f), _type(LightTypePoint),
-_displaySize(3.0)
+_displaySize(3.0f)
 {
 }
 
diff --git a/engines/tetraedge/te/te_light_opengl.cpp b/engines/tetraedge/te/te_light_opengl.cpp
index 2ea36871092..4d94992fa1e 100644
--- a/engines/tetraedge/te/te_light_opengl.cpp
+++ b/engines/tetraedge/te/te_light_opengl.cpp
@@ -42,6 +42,7 @@ void TeLightOpenGL::disable(uint lightno) {
 }
 
 void TeLightOpenGL::enable(uint lightno) {
+	// Note: original casts to float and compares to 0.01, but that's the same?
 	if (_colDiffuse.r() == 0 && _colDiffuse.g() == 0 && _colDiffuse.b() == 0)
 		glDisable(_toGlLight(lightno));
 	else
@@ -95,21 +96,15 @@ void TeLightOpenGL::update(uint lightno) {
 	}
 
 	if (_type == LightTypeDirectional) {
-		float cosx = cosf(_positionRadial.getX());
-		float cosy = cosf(_positionRadial.getY());
-		float sinx = sinf(_positionRadial.getX());
-		float siny = sinf(_positionRadial.getY());
-		const float pos[4] = {cosx * cosy, siny, sinx * cosy, 0.0f};
-		glLightfv(glLight, GL_POSITION, pos);
+		const TeVector3f32 dirv = directionVector();
+		const float dir[4] = {dirv.x(), dirv.y(), dirv.z(), 0.0f};
+		glLightfv(glLight, GL_POSITION, dir);
 	}
 
 	if (_type == LightTypeSpot) {
-		float cosx = cosf(_positionRadial.getX());
-		float cosy = cosf(_positionRadial.getY());
-		float sinx = sinf(_positionRadial.getX());
-		float siny = sinf(_positionRadial.getY());
-		const float pos[4] = {cosx * cosy, siny, sinx * cosy, 0.0f};
-		glLightfv(glLight, GL_SPOT_DIRECTION, pos);
+		const TeVector3f32 dirv = directionVector();
+		const float dir[4] = {dirv.x(), dirv.y(), dirv.z(), 0.0f};
+		glLightfv(glLight, GL_SPOT_DIRECTION, dir);
 		glLightf(glLight, GL_SPOT_CUTOFF, (_cutoff * 180.0) / M_PI);
 		glLightf(glLight, GL_SPOT_EXPONENT, _exponent);
 	} else {
diff --git a/engines/tetraedge/te/te_light_tinygl.cpp b/engines/tetraedge/te/te_light_tinygl.cpp
index 64ebaafcb2f..b4cedd1f472 100644
--- a/engines/tetraedge/te/te_light_tinygl.cpp
+++ b/engines/tetraedge/te/te_light_tinygl.cpp
@@ -95,21 +95,15 @@ void TeLightTinyGL::update(uint lightno) {
 	}
 
 	if (_type == LightTypeDirectional) {
-		float cosx = cosf(_positionRadial.getX());
-		float cosy = cosf(_positionRadial.getY());
-		float sinx = sinf(_positionRadial.getX());
-		float siny = sinf(_positionRadial.getY());
-		const float pos[4] = {cosx * cosy, siny, sinx * cosy, 0.0f};
-		tglLightfv(glLight, TGL_POSITION, pos);
+		const TeVector3f32 dirv = directionVector();
+		const float dir[4] = {dirv.x(), dirv.y(), dirv.z(), 0.0f};
+		tglLightfv(glLight, TGL_POSITION, dir);
 	}
 
 	if (_type == LightTypeSpot) {
-		float cosx = cosf(_positionRadial.getX());
-		float cosy = cosf(_positionRadial.getY());
-		float sinx = sinf(_positionRadial.getX());
-		float siny = sinf(_positionRadial.getY());
-		const float pos[4] = {cosx * cosy, siny, sinx * cosy, 0.0f};
-		tglLightfv(glLight, TGL_SPOT_DIRECTION, pos);
+		const TeVector3f32 dirv = directionVector();
+		const float dir[4] = {dirv.x(), dirv.y(), dirv.z(), 0.0f};
+		tglLightfv(glLight, TGL_SPOT_DIRECTION, dir);
 		tglLightf(glLight, TGL_SPOT_CUTOFF, (_cutoff * 180.0) / M_PI);
 		tglLightf(glLight, TGL_SPOT_EXPONENT, _exponent);
 	} else {


Commit: 6c33b126702b740a0f1e69ee159274bb4b1d15f2
    https://github.com/scummvm/scummvm/commit/6c33b126702b740a0f1e69ee159274bb4b1d15f2
Author: Matthew Duggan (mgithub at guarana.org)
Date: 2023-01-24T19:43:13+09:00

Commit Message:
TETRAEDGE: Fix suspicious use of pointers as integers

This is not a perfect fix as it still might create pointers outside the range
of the graph, but it's guaranteed not to use them.

Also fixed a memory leak in this class.

Changed paths:
    engines/tetraedge/te/te_free_move_zone.cpp


diff --git a/engines/tetraedge/te/te_free_move_zone.cpp b/engines/tetraedge/te/te_free_move_zone.cpp
index e4043dfa5b4..a9dee0ddc7c 100644
--- a/engines/tetraedge/te/te_free_move_zone.cpp
+++ b/engines/tetraedge/te/te_free_move_zone.cpp
@@ -71,10 +71,11 @@ _loadedFromBin(false), _gridWorldY(0.0), _gridOffsetSomething(5.0f, 5.0f), _grid
 }
 
 TeFreeMoveZone::~TeFreeMoveZone() {
-	if (_camera) {
+	if (_camera)
 		_camera->onViewportChangedSignal().remove(this, &TeFreeMoveZone::onViewportChanged);
-	}
+
 	delete _micropather;
+	delete _graph;
 }
 
 float TeFreeMoveZone::bordersDistance() const {
@@ -194,10 +195,12 @@ TeIntrusivePtr<TeBezierCurve> TeFreeMoveZone::curve(const TeVector3f32 &startpt,
 	const TeVector2s32 projectedStart = projectOnAStarGrid(startpt);
 	const TeVector2s32 projectedEnd = projectOnAStarGrid(endpt);
 	const int xsize = _graph->_size._x;
+	char *graphData = _graph->_flags.data();
 	float cost = 0;
 	// Passing an int to void*, yuck? but it's what the original does..
 	Common::Array<void *> path;
-	int pathResult = _micropather->Solve((void *)(xsize * projectedStart._y + projectedStart._x), (void *)(xsize * projectedEnd._y + projectedEnd._x), &path, &cost);
+	int pathResult = _micropather->Solve(graphData + xsize * projectedStart._y + projectedStart._x,
+			graphData + xsize * projectedEnd._y + projectedEnd._x, &path, &cost);
 
 	TeIntrusivePtr<TeBezierCurve> retval;
 
@@ -208,7 +211,7 @@ TeIntrusivePtr<TeBezierCurve> TeFreeMoveZone::curve(const TeVector3f32 &startpt,
 		int i = 1;
 		for (auto pathpt : path) {
 			// each path point is an array offset
-			int offset = static_cast<int>(reinterpret_cast<size_t>(pathpt));
+			int offset = (char *)pathpt - graphData;
 			points[i] = TeVector2s32(offset % xsize, offset / xsize);
 			i++;
 		}
@@ -422,9 +425,8 @@ void TeFreeMoveZone::preUpdateGrid() {
 	updateTransformedVertices();
 	updatePickMesh();
 	updateBorders();
-	if (_loadedFromBin) {
+	if (_loadedFromBin)
 		calcGridMatrix();
-	}
 
 	TeMatrix4x4 gridInverse = _gridMatrix;
 	gridInverse.inverse();
@@ -433,11 +435,11 @@ void TeFreeMoveZone::preUpdateGrid() {
 	if (_transformedVerticies.empty() || _pickMesh.empty()) {
 		debug("[TeFreeMoveZone::buildAStar] %s have no mesh or is entierly occluded", name().c_str());
 	} else {
-		if (!_loadedFromBin) {
+		if (!_loadedFromBin)
 			newVec = _transformedVerticies[_pickMesh[0]];
-		} else {
+		else
 			newVec = gridInverse * _freeMoveZoneVerticies[_pickMesh[0]];
-		}
+
 		_someGridVec1.setX(newVec.x());
 		_someGridVec1.setY(newVec.z());
 
@@ -709,8 +711,9 @@ void TeFreeMoveZone::updateTransformedVertices() {
 /*========*/
 
 float TeFreeMoveZoneGraph::LeastCostEstimate(void *stateStart, void *stateEnd) {
-	int startInt = static_cast<int>(reinterpret_cast<size_t>(stateStart));
-	int endInt = static_cast<int>(reinterpret_cast<size_t>(stateEnd));
+	char *dataStart = _flags.data();
+	int startInt = (char *)stateStart - dataStart;
+	int endInt = (char *)stateEnd - dataStart;
 	int starty = startInt / _size._x;
 	int endy = endInt / _size._x;
 	TeVector2s32 start(startInt - starty * _size._x, starty);
@@ -719,7 +722,8 @@ float TeFreeMoveZoneGraph::LeastCostEstimate(void *stateStart, void *stateEnd) {
 }
 
 void TeFreeMoveZoneGraph::AdjacentCost(void *state, Common::Array<micropather::StateCost> *adjacent) {
-	int stateInt = static_cast<int>(reinterpret_cast<size_t>(state));
+	char *flagStart = _flags.data();
+	int stateInt = (char *)state - flagStart;
 	int stateY = stateInt / _size._x;
 	const TeVector2s32 statept(stateInt - stateY * _size._x, stateY);
 
@@ -727,42 +731,42 @@ void TeFreeMoveZoneGraph::AdjacentCost(void *state, Common::Array<micropather::S
 	TeVector2s32 pt;
 
 	pt = TeVector2s32(statept._x - 1, statept._y);
-	cost.state = reinterpret_cast<void *>(_size._x * pt._y + pt._x);
+	cost.state = flagStart + _size._x * pt._y + pt._x;
 	cost.cost = costForPoint(pt);
 	adjacent->push_back(cost);
 
 	pt = TeVector2s32(statept._x - 1, statept._y + 1);
-	cost.state = reinterpret_cast<void *>(_size._x * pt._y + pt._x);
+	cost.state = flagStart + _size._x * pt._y + pt._x;
 	cost.cost = costForPoint(pt);
 	adjacent->push_back(cost);
 
 	pt = TeVector2s32(statept._x, statept._y + 1);
-	cost.state = reinterpret_cast<void *>(_size._x * pt._y + pt._x);
+	cost.state = flagStart + _size._x * pt._y + pt._x;
 	cost.cost = costForPoint(pt);
 	adjacent->push_back(cost);
 
 	pt = TeVector2s32(statept._x + 1, statept._y + 1);
-	cost.state = reinterpret_cast<void *>(_size._x * pt._y + pt._x);
+	cost.state = flagStart + _size._x * pt._y + pt._x;
 	cost.cost = costForPoint(pt);
 	adjacent->push_back(cost);
 
 	pt = TeVector2s32(statept._x + 1, statept._y);
-	cost.state = reinterpret_cast<void *>(_size._x * pt._y + pt._x);
+	cost.state = flagStart + _size._x * pt._y + pt._x;
 	cost.cost = costForPoint(pt);
 	adjacent->push_back(cost);
 
 	pt = TeVector2s32(statept._x + 1, statept._y - 1);
-	cost.state = reinterpret_cast<void *>(_size._x * pt._y + pt._x);
+	cost.state = flagStart + _size._x * pt._y + pt._x;
 	cost.cost = costForPoint(pt);
 	adjacent->push_back(cost);
 
 	pt = TeVector2s32(statept._x, statept._y - 1);
-	cost.state = reinterpret_cast<void *>(_size._x * pt._y + pt._x);
+	cost.state = flagStart + _size._x * pt._y + pt._x;
 	cost.cost = costForPoint(pt);
 	adjacent->push_back(cost);
 
 	pt = TeVector2s32(statept._x - 1, statept._y - 1);
-	cost.state = reinterpret_cast<void *>(_size._x * pt._y + pt._x);
+	cost.state = flagStart + _size._x * pt._y + pt._x;
 	cost.cost = costForPoint(pt);
 	adjacent->push_back(cost);
 }




More information about the Scummvm-git-logs mailing list