[Scummvm-git-logs] scummvm master -> d930a30338ad0167eee40ce4ec7b188b00ff6bfa

OMGPizzaGuy noreply at scummvm.org
Sat Dec 10 02:27:44 UTC 2022


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:
3d06c218c9 ULTIMA8: Additional check for positive height & width on shape frames.
d930a30338 ULTIMA8: Improvements to shape viewer & fix memory leak


Commit: 3d06c218c9f30ea226094b80d5967504813465ca
    https://github.com/scummvm/scummvm/commit/3d06c218c9f30ea226094b80d5967504813465ca
Author: Matthew Jimenez (matthew.jimenez at outlook.com)
Date: 2022-12-09T20:27:18-06:00

Commit Message:
ULTIMA8: Additional check for positive height & width on shape frames.

Attempting to use the shapeviewer in Crusader on font 2 was failing this check on my install.

Changed paths:
    engines/ultima/ultima8/graphics/raw_shape_frame.cpp


diff --git a/engines/ultima/ultima8/graphics/raw_shape_frame.cpp b/engines/ultima/ultima8/graphics/raw_shape_frame.cpp
index 744b4959f62..e447cdd2989 100644
--- a/engines/ultima/ultima8/graphics/raw_shape_frame.cpp
+++ b/engines/ultima/ultima8/graphics/raw_shape_frame.cpp
@@ -112,7 +112,7 @@ void RawShapeFrame::loadGenericFormat(const uint8 *data, uint32 size, const Conv
 		return;
 
 	// Fairly arbitrary sanity check
-	if (_height > 4096 || _width > 4096 || _xoff > 4096 || _yoff > 4096) {
+	if (_height < 0 || _height > 4096 || _width < 0 || _width > 4096 || _xoff > 4096 || _yoff > 4096) {
 		warning("got some invalid data loading shape");
 		_width = _height = _xoff = _yoff = 0;
 		return;


Commit: d930a30338ad0167eee40ce4ec7b188b00ff6bfa
    https://github.com/scummvm/scummvm/commit/d930a30338ad0167eee40ce4ec7b188b00ff6bfa
Author: Matthew Jimenez (matthew.jimenez at outlook.com)
Date: 2022-12-09T20:27:18-06:00

Commit Message:
ULTIMA8: Improvements to shape viewer & fix memory leak

Changed paths:
    engines/ultima/ultima8/gumps/shape_viewer_gump.cpp
    engines/ultima/ultima8/gumps/shape_viewer_gump.h


diff --git a/engines/ultima/ultima8/gumps/shape_viewer_gump.cpp b/engines/ultima/ultima8/gumps/shape_viewer_gump.cpp
index c90ba9c6594..e475a686a33 100644
--- a/engines/ultima/ultima8/gumps/shape_viewer_gump.cpp
+++ b/engines/ultima/ultima8/gumps/shape_viewer_gump.cpp
@@ -50,21 +50,17 @@ namespace Ultima8 {
 DEFINE_RUNTIME_CLASSTYPE_CODE(ShapeViewerGump)
 
 ShapeViewerGump::ShapeViewerGump()
-	: ModalGump(), _curFlex(0), _flex(nullptr), _curShape(0), _curFrame(0),
-	  _background(0), _fontNo(0), _shapeW(0), _shapeH(0), _shapeX(0), _shapeY(0) {
+	: ModalGump(), _curArchive(0), _curShape(0), _curFrame(0),
+	  _background(0x101010), _fontNo(0), _shapeW(0), _shapeH(0), _shapeX(0), _shapeY(0) {
 
 }
 
 ShapeViewerGump::ShapeViewerGump(int x, int y, int width, int height,
-								 Std::vector<Common::Pair<Std::string, ShapeArchive *> > &flexes,
+								 Common::Array<ShapeArchiveEntry> &archives,
 								 uint32 flags, int32 layer)
-		: ModalGump(x, y, width, height, 0, flags, layer), _flexes(flexes),
-		_curFlex(0), _curShape(0), _curFrame(0), _background(0), _fontNo(0),
+		: ModalGump(x, y, width, height, 0, flags, layer), _archives(archives),
+		_curArchive(0), _curShape(0), _curFrame(0), _background(0x101010), _fontNo(0),
 		_shapeW(0), _shapeH(0), _shapeX(0), _shapeY(0) {
-	if (_flexes.size())
-		_flex = _flexes[0].second;
-	else
-		_flex = nullptr;
 
 	if (GAME_IS_CRUSADER) {
 		// Default to a decent font on Crusader
@@ -73,6 +69,11 @@ ShapeViewerGump::ShapeViewerGump(int x, int y, int width, int height,
 }
 
 ShapeViewerGump::~ShapeViewerGump() {
+	for (Common::Array<ShapeArchiveEntry>::iterator it = _archives.begin(); it != _archives.end(); it++) {
+		if (it->_disposeAfterUse == DisposeAfterUse::YES) {
+			delete it->_archive;
+		}
+	}
 }
 
 void ShapeViewerGump::InitGump(Gump *newparent, bool take_focus) {
@@ -80,7 +81,7 @@ void ShapeViewerGump::InitGump(Gump *newparent, bool take_focus) {
 }
 
 void ShapeViewerGump::PaintThis(RenderSurface *surf, int32 lerp_factor, bool /*scaled*/) {
-	if (_flexes.empty()) {
+	if (_archives.empty()) {
 		Close();
 		return;
 	}
@@ -90,7 +91,8 @@ void ShapeViewerGump::PaintThis(RenderSurface *surf, int32 lerp_factor, bool /*s
 	int32 posx = (_dims.width() - _shapeW) / 2 + _shapeX;
 	int32 posy = (_dims.height() - _shapeH) / 2 + _shapeY - 25;
 
-	const Shape *shape = _flex->getShape(_curShape);
+	ShapeArchive *archive = _archives[_curArchive]._archive;
+	const Shape *shape = archive->getShape(_curShape);
 	if (shape && _curFrame < shape->frameCount())
 		surf->Paint(shape, _curFrame, posx, posy);
 
@@ -110,10 +112,10 @@ void ShapeViewerGump::PaintThis(RenderSurface *surf, int32 lerp_factor, bool /*s
 		} else {
 			Common::sprintf_s(buf1, "Frame %d of %d", _curFrame+1, shape->frameCount());
 		}
-		Common::sprintf_s(buf2, "%s:  Shape %d, %s", _flexes[_curFlex].first.c_str(),
+		Common::sprintf_s(buf2, "%s:  Shape %d, %s", _archives[_curArchive]._name.c_str(),
 				_curShape, buf1);
 		rendtext = font->renderText(buf2, remaining);
-		rendtext->draw(surf, 20, 10);
+		rendtext->draw(surf, 8, 10);
 		delete rendtext;
 	}
 
@@ -141,7 +143,7 @@ void ShapeViewerGump::PaintThis(RenderSurface *surf, int32 lerp_factor, bool /*s
 
 				Common::sprintf_s(buf2, "px: (%d, %d)(%d, %d): %d (%d, %d, %d)", relx, rely, frame->_xoff, frame->_yoff, rawpx, px_r, px_g, px_b);
 				rendtext = font->renderText(buf2, remaining);
-				rendtext->draw(surf, 20, 25);
+				rendtext->draw(surf, 8, 25);
 				delete rendtext;
 			}
 		}
@@ -150,7 +152,7 @@ void ShapeViewerGump::PaintThis(RenderSurface *surf, int32 lerp_factor, bool /*s
 
 	{
 		// Additional shapeinfo (only in main shapes archive)
-		MainShapeArchive *mainshapes = dynamic_cast<MainShapeArchive *>(_flex);
+		MainShapeArchive *mainshapes = dynamic_cast<MainShapeArchive *>(archive);
 		if (!mainshapes || !shape) return;
 
 		char buf3[128];
@@ -168,13 +170,17 @@ void ShapeViewerGump::PaintThis(RenderSurface *surf, int32 lerp_factor, bool /*s
 			Common::sprintf_s(buf6, "ShapeInfo: %s\n%s\n%s\nUsecode: %s",
 					buf3, buf4, buf5, GameData::get_instance()->getMainUsecode()->get_class_name(_curShape));
 			rendtext = font->renderText(buf6, remaining);
-			rendtext->draw(surf, 20, _dims.height() - 58);
+
+			int x, y;
+			rendtext->getSize(x, y);
+			rendtext->draw(surf, 8, _dims.height() - y);
 			delete rendtext;
 		}
 	}
 }
 
 bool ShapeViewerGump::OnKeyDown(int key, int mod) {
+	ShapeArchive *archive = _archives[_curArchive]._archive;
 	bool shapechanged = false;
 	unsigned int delta = 1;
 	if (mod & Common::KBD_SHIFT) delta = 10;
@@ -182,9 +188,10 @@ bool ShapeViewerGump::OnKeyDown(int key, int mod) {
 	switch (key) {
 	case Common::KEYCODE_UP:
 	case Common::KEYCODE_k:
-		if (delta >= _flex->getCount()) delta = 1;
+		if (delta >= archive->getCount())
+			delta = 1;
 		if (_curShape < delta)
-			_curShape = _flex->getCount() + _curShape - delta;
+			_curShape = archive->getCount() + _curShape - delta;
 		else
 			_curShape -= delta;
 		shapechanged = true;
@@ -192,9 +199,10 @@ bool ShapeViewerGump::OnKeyDown(int key, int mod) {
 		break;
 	case Common::KEYCODE_DOWN:
 	case Common::KEYCODE_j:
-		if (delta >= _flex->getCount()) delta = 1;
-		if (_curShape + delta >= _flex->getCount())
-			_curShape = _curShape + delta - _flex->getCount();
+		if (delta >= archive->getCount())
+			delta = 1;
+		if (_curShape + delta >= archive->getCount())
+			_curShape = _curShape + delta - archive->getCount();
 		else
 			_curShape += delta;
 		_curFrame = 0;
@@ -202,7 +210,7 @@ bool ShapeViewerGump::OnKeyDown(int key, int mod) {
 		break;
 	case Common::KEYCODE_LEFT:
 	case Common::KEYCODE_h: {
-		const Shape *shape = _flex->getShape(_curShape);
+		const Shape *shape = archive->getShape(_curShape);
 		if (shape && shape->frameCount()) {
 			if (delta >= shape->frameCount()) delta = 1;
 			if (_curFrame < delta)
@@ -214,7 +222,7 @@ bool ShapeViewerGump::OnKeyDown(int key, int mod) {
 	break;
 	case Common::KEYCODE_RIGHT:
 	case Common::KEYCODE_l: {
-		const Shape *shape = _flex->getShape(_curShape);
+		const Shape *shape = archive->getShape(_curShape);
 		if (shape && shape->frameCount()) {
 			if (delta >= shape->frameCount()) delta = 1;
 			if (_curFrame + delta >= shape->frameCount())
@@ -226,12 +234,12 @@ bool ShapeViewerGump::OnKeyDown(int key, int mod) {
 	break;
 	case Common::KEYCODE_COMMA:
 	case Common::KEYCODE_PAGEUP: {
-		if (_curFlex == 0)
-			_curFlex = _flexes.size() - 1;
+		if (_curArchive == 0)
+			_curArchive = _archives.size() - 1;
 		else
-			_curFlex--;
+			_curArchive--;
 
-		_flex = _flexes[_curFlex].second;
+		archive = _archives[_curArchive]._archive;
 		shapechanged = true;
 		_curShape = 0;
 		_curFrame = 0;
@@ -239,12 +247,12 @@ bool ShapeViewerGump::OnKeyDown(int key, int mod) {
 	break;
 	case Common::KEYCODE_PERIOD:
 	case Common::KEYCODE_PAGEDOWN: {
-		if (_curFlex + 1 == _flexes.size())
-			_curFlex = 0;
+		if (_curArchive + 1 == _archives.size())
+			_curArchive = 0;
 		else
-			_curFlex++;
+			_curArchive++;
 
-		_flex = _flexes[_curFlex].second;
+		archive = _archives[_curArchive]._archive;
 		shapechanged = true;
 		_curShape = 0;
 		_curFrame = 0;
@@ -257,7 +265,11 @@ bool ShapeViewerGump::OnKeyDown(int key, int mod) {
 			_fontNo = 0;
 		}
 	}
-			break;
+	break;
+	case Common::KEYCODE_b: {
+		_background += 0x808080;
+		_background &= 0xF0F0F0;
+	} break;
 	case Common::KEYCODE_ESCAPE: {
 		Close();
 	}
@@ -267,7 +279,7 @@ bool ShapeViewerGump::OnKeyDown(int key, int mod) {
 	}
 
 	if (shapechanged) {
-		const Shape *shape = _flex->getShape(_curShape);
+		const Shape *shape = archive->getShape(_curShape);
 		if (shape)
 			shape->getTotalDimensions(_shapeW, _shapeH, _shapeX, _shapeY);
 	}
@@ -275,45 +287,22 @@ bool ShapeViewerGump::OnKeyDown(int key, int mod) {
 	return true;
 }
 
-bool ShapeViewerGump::OnTextInput(int unicode) {
-	switch (unicode) {
-	case 'b':
-		_background += 0x808080;
-		_background &= 0xF0F0F0;
-		break;
-	default:
-		break;
-	}
-
-	return true;
-}
-
-
 //static
 void ShapeViewerGump::U8ShapeViewer() {
 	GameData *gamedata = GameData::get_instance();
 
-	Std::vector<Common::Pair<Std::string, ShapeArchive *> > _flexes;
-	Common::Pair<Std::string, ShapeArchive *> _flex;
-	_flex.first = "shapes";
-	_flex.second = gamedata->getMainShapes();
-	_flexes.push_back(_flex);
-	_flex.first = "gumps";
-	_flex.second = gamedata->getGumps();
-	_flexes.push_back(_flex);
-	_flex.first = "fonts";
-	_flex.second = gamedata->getFonts();
-	_flexes.push_back(_flex);
+	Common::Array<ShapeArchiveEntry> archives;
+	archives.push_back(ShapeArchiveEntry("shapes", gamedata->getMainShapes()));
+	archives.push_back(ShapeArchiveEntry("gumps", gamedata->getGumps()));
+	archives.push_back(ShapeArchiveEntry("fonts", gamedata->getFonts()));
+
 	FileSystem *filesys = FileSystem::get_instance();
 	Common::SeekableReadStream *eintro = filesys->ReadFile("static/eintro.skf");
 	if (eintro) {
 		ShapeArchive *eintroshapes = new ShapeArchive(eintro, GameData::OTHER,
 		        PaletteManager::get_instance()->getPalette(PaletteManager::Pal_Game),
 		        &U8SKFShapeFormat);
-		_flex.first = "eintro";
-		_flex.second = eintroshapes;
-		_flexes.push_back(_flex);
-		// !! memory leak
+		archives.push_back(ShapeArchiveEntry("eintro", eintroshapes, DisposeAfterUse::YES));
 	}
 
 	Common::SeekableReadStream *endgame = filesys->ReadFile("static/endgame.skf");
@@ -321,22 +310,28 @@ void ShapeViewerGump::U8ShapeViewer() {
 		ShapeArchive *endgameshapes = new ShapeArchive(endgame, GameData::OTHER,
 		        PaletteManager::get_instance()->getPalette(PaletteManager::Pal_Game),
 		        &U8SKFShapeFormat);
-		_flex.first = "endgame";
-		_flex.second = endgameshapes;
-		_flexes.push_back(_flex);
-		// !! memory leak
+		archives.push_back(ShapeArchiveEntry("endgame", endgameshapes, DisposeAfterUse::YES));
 	}
 
 	Gump *desktopGump = Ultima8Engine::get_instance()->getDesktopGump();
 	Rect res;
 	desktopGump->GetDims(res);
 
-	int width = (res.width() * 4) / 5;
-	int height = (res.height() * 5) / 6;
-	int xoff = res.width() / 10;
-	int yoff = res.height() / 12;
+	int xoff, yoff, width, height;
+
+	if (res.height() > 240) {
+		width = (res.width() * 4) / 5;
+		height = (res.height() * 5) / 6;
+		xoff = res.width() / 10;
+		yoff = res.height() / 12;
+	} else {
+		width = (res.width() * 9) / 10;
+		height = (res.height() * 11) / 12;
+		xoff = res.width() / 20;
+		yoff = res.height() / 24;
+	}
 
-	ModalGump *gump = new ShapeViewerGump(xoff, yoff, width, height, _flexes);
+	ModalGump *gump = new ShapeViewerGump(xoff, yoff, width, height, archives);
 	gump->InitGump(0);
 }
 
diff --git a/engines/ultima/ultima8/gumps/shape_viewer_gump.h b/engines/ultima/ultima8/gumps/shape_viewer_gump.h
index 021a8c94729..4dfb36bf7b5 100644
--- a/engines/ultima/ultima8/gumps/shape_viewer_gump.h
+++ b/engines/ultima/ultima8/gumps/shape_viewer_gump.h
@@ -37,18 +37,26 @@ class ShapeArchive;
  */
 class ShapeViewerGump : public ModalGump {
 public:
+	struct ShapeArchiveEntry {
+		Common::String _name;
+		ShapeArchive *_archive;
+		DisposeAfterUse::Flag _disposeAfterUse;
+
+		ShapeArchiveEntry(const char *name, ShapeArchive *archive, DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::NO)
+			: _name(name), _archive(archive), _disposeAfterUse(disposeAfterUse) {}
+	};
+
 	ENABLE_RUNTIME_CLASSTYPE()
 
 	ShapeViewerGump();
 	ShapeViewerGump(int x, int y, int width, int height,
-	                Std::vector<Common::Pair<Std::string, ShapeArchive *> > &flexes,
-	                uint32 flags = FLAG_PREVENT_SAVE, int32 layer = LAYER_MODAL);
+					Common::Array<ShapeArchiveEntry> &archives,
+					uint32 flags = FLAG_PREVENT_SAVE, int32 layer = LAYER_MODAL);
 	~ShapeViewerGump() override;
 
 	void PaintThis(RenderSurface *, int32 lerp_factor, bool scaled) override;
 
 	bool OnKeyDown(int key, int mod) override;
-	bool OnTextInput(int unicode) override;
 
 	// Init the gump, call after construction
 	void InitGump(Gump *newparent, bool take_focus = true) override;
@@ -59,9 +67,8 @@ public:
 	void saveData(Common::WriteStream *ws) override;
 
 protected:
-	Std::vector<Common::Pair<Std::string, ShapeArchive *> > _flexes;
-	unsigned int _curFlex;
-	ShapeArchive *_flex;
+	Common::Array<ShapeArchiveEntry> _archives;
+	unsigned int _curArchive;
 	uint32 _curShape;
 	uint32 _curFrame;
 




More information about the Scummvm-git-logs mailing list