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

scemino noreply at scummvm.org
Sun Mar 17 20:20:09 UTC 2024


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

Summary:
b77f44380a TWP: Fix array overrun in audio. PVS-Studio V557
c4961f7aa9 TWP: Fix AudioSlot not initialized in audio. PVS-Studio V730
96f90c8ff5 TWP: Fix slot was unnecessarily verified against nullptr in dialog. PVS-Studio V595
435f2f5fc1 TWP: Fix Not all members of DialogContext are initialized. PVS-Studio V730
53d90fecb7 TWP: Fix potential buffer overflow in font. PVS-Studio V576
bce268e920 TWP: Fix not all members of XorKey are initialized. PVS-Studio V730
fffeb8d472 TWP: Fix not all members of Object are initialized. PVS-Studio V730
2830f1b917 TWP: Fix not all members of ShaderParams are initialized. PVS-Studio V730
8ea7be4710 TWP: Fix not all members of Thread are initialized. PVS-Studio V730
220978d4ea TWP: Fix invalid expression in YackTokenReader. PVS-Studio V593
a7be536609 TWP: Fix not all members of YackToken are initialized. PVS-Studio V730
f3e512c34f TWP: Use explicit cast in AudioSystem. PVS-Studio V636
c93c448af3 TWP: The 'thAlign' variable was assigned the same value. PVS-Studio V1048
8f64a85b2b TWP: The 'effect' variable was assigned the same value. PVS-Studio V1048
0d0f85b55f TWP: Use explicit cast in Inventory. PVS-Studio V636
15566ca54b TWP: The function was exited without releasing the 'jActorValue' pointer. PVS-Studio V773
fa30bcd1eb TWP: Fix warning, declaration requires a global destructor in debugtools.


Commit: b77f44380a51078c63e5c2d07639f37a2fb41dc3
    https://github.com/scummvm/scummvm/commit/b77f44380a51078c63e5c2d07639f37a2fb41dc3
Author: scemino (scemino74 at gmail.com)
Date: 2024-03-17T20:50:05+01:00

Commit Message:
TWP: Fix array overrun in audio. PVS-Studio V557

Changed paths:
    engines/twp/audio.cpp


diff --git a/engines/twp/audio.cpp b/engines/twp/audio.cpp
index aa3f129677c..d8b2d625537 100644
--- a/engines/twp/audio.cpp
+++ b/engines/twp/audio.cpp
@@ -74,9 +74,9 @@ void SoundDefinition::load() {
 bool AudioSystem::playing(int id) const {
 	// channel ID ?
 	if (id >= 1 && id <= NUM_AUDIO_SLOTS) {
-		if (!_slots[id].busy)
+		if (!_slots[id - 1].busy)
 			return false;
-		id = g_twp->_mixer->getSoundID(_slots[id].handle);
+		id = g_twp->_mixer->getSoundID(_slots[id - 1].handle);
 	}
 	// sound definition ID ?
 	for (const auto &_slot : _slots) {
@@ -112,11 +112,11 @@ void AudioSystem::fadeOut(int id, float fadeTime) {
 void AudioSystem::stop(int id) {
 	// channel ID ?
 	if (id >= 1 && id <= NUM_AUDIO_SLOTS) {
-		if (!_slots[id].busy)
+		if (!_slots[id - 1].busy)
 			return;
-		_slots[id].loopTimes = 0;
-		_slots[id].busy = false;
-		g_twp->_mixer->stopHandle(_slots[id].handle);
+		_slots[id - 1].loopTimes = 0;
+		_slots[id - 1].busy = false;
+		g_twp->_mixer->stopHandle(_slots[id - 1].handle);
 		return;
 	}
 	// sound ID or sound definition ID ?
@@ -190,9 +190,9 @@ void AudioSystem::updateVolume(AudioSlot *slot) {
 void AudioSystem::setVolume(int id, float vol) {
 	// channel ID ?
 	if (id >= 1 && id <= NUM_AUDIO_SLOTS) {
-		if (!_slots[id].busy)
+		if (!_slots[id - 1].busy)
 			return;
-		id = g_twp->_mixer->getSoundID(_slots[id].handle);
+		id = g_twp->_mixer->getSoundID(_slots[id - 1].handle);
 	}
 	// sound definition ID or sound ID ?
 	for (auto &_slot : _slots) {


Commit: c4961f7aa9e213bd8eef16c80d09729c022d52e9
    https://github.com/scummvm/scummvm/commit/c4961f7aa9e213bd8eef16c80d09729c022d52e9
Author: scemino (scemino74 at gmail.com)
Date: 2024-03-17T20:50:05+01:00

Commit Message:
TWP: Fix AudioSlot not initialized in audio. PVS-Studio V730

Changed paths:
    engines/twp/audio.h


diff --git a/engines/twp/audio.h b/engines/twp/audio.h
index a9bc14f00be..411efc3c2ff 100644
--- a/engines/twp/audio.h
+++ b/engines/twp/audio.h
@@ -77,18 +77,18 @@ private:
 };
 
 struct AudioSlot {
-	Audio::SoundHandle handle;                 // handle returned when this sound has been played
-	Common::SharedPtr<SoundDefinition> sndDef; // sound definition associated to this slot
-	SoundStream stream;                        // audio stream
-	bool busy = false;                         // is sound active
-	float volume = 1.f;                        // actual volume for this slot
-	float fadeInTimeMs = 0.f;                  // fade-in time in milliseconds
-	float fadeOutTimeMs = 0.f;                 // fade-out time in milliseconds
-	int total = 0;
-	int id = 0;                        // unique sound ID
-	int objId = 0;                     // object ID or 0 if none
-	int loopTimes = 0;                 //
-	Audio::Mixer::SoundType soundType; //
+	Audio::SoundHandle handle;                                         // handle returned when this sound has been played
+	Common::SharedPtr<SoundDefinition> sndDef;                         // sound definition associated to this slot
+	SoundStream stream;                                                // audio stream
+	bool busy = false;                                                 // is sound active
+	float volume = 1.f;                                                // actual volume for this slot
+	float fadeInTimeMs = 0.f;                                          // fade-in time in milliseconds
+	float fadeOutTimeMs = 0.f;                                         // fade-out time in milliseconds
+	int total = 0;                                                     // duration of the sound in milliseconds
+	int id = 0;                                                        // unique sound ID
+	int objId = 0;                                                     // object ID or 0 if none
+	int loopTimes = 0;                                                 // specified number of times to loop
+	Audio::Mixer::SoundType soundType = Audio::Mixer::kPlainSoundType; // sound type: plain, music, sfx, speech
 };
 
 class AudioSystem {


Commit: 96f90c8ff53ae86ea40c3458b6ec3f06a107a0df
    https://github.com/scummvm/scummvm/commit/96f90c8ff53ae86ea40c3458b6ec3f06a107a0df
Author: scemino (scemino74 at gmail.com)
Date: 2024-03-17T20:50:05+01:00

Commit Message:
TWP: Fix slot was unnecessarily verified against nullptr in dialog. PVS-Studio V595

Changed paths:
    engines/twp/dialog.cpp


diff --git a/engines/twp/dialog.cpp b/engines/twp/dialog.cpp
index 7cd0146bf9e..913df715a88 100644
--- a/engines/twp/dialog.cpp
+++ b/engines/twp/dialog.cpp
@@ -246,7 +246,7 @@ void Dialog::update(float dt) {
 			DialogSlot *slot = &_slots[i];
 			if (slot->_isValid) {
 				Rectf rect = Rectf::fromPosAndSize(slot->getPos() - Math::Vector2d(0.f, -slot->_text.getBounds().getY()/2.f), slot->_text.getBounds());
-				bool over = slot && rect.contains(_mousePos);
+				bool over = rect.contains(_mousePos);
 				if (rect.r.w > (SCREEN_WIDTH - SLOTMARGIN)) {
 					if (over) {
 						if ((rect.r.w + slot->getPos().getX()) > (SCREEN_WIDTH - SLOTMARGIN)) {


Commit: 435f2f5fc1948cb7330c95b650509012bfd2da07
    https://github.com/scummvm/scummvm/commit/435f2f5fc1948cb7330c95b650509012bfd2da07
Author: scemino (scemino74 at gmail.com)
Date: 2024-03-17T20:50:05+01:00

Commit Message:
TWP: Fix Not all members of DialogContext are initialized. PVS-Studio V730

Changed paths:
    engines/twp/dialog.h


diff --git a/engines/twp/dialog.h b/engines/twp/dialog.h
index 7a0db5a0731..f8dbe6b0542 100644
--- a/engines/twp/dialog.h
+++ b/engines/twp/dialog.h
@@ -52,8 +52,8 @@ public:
 struct DialogContext {
 	Common::String actor;
 	Common::String dialogName;
-	bool parrot;
-	int limit;
+	bool parrot = true;
+	int limit = MAXDIALOGSLOTS;
 };
 
 enum DialogState {


Commit: 53d90fecb7a3e9c6fdc290322801cc914b690c4c
    https://github.com/scummvm/scummvm/commit/53d90fecb7a3e9c6fdc290322801cc914b690c4c
Author: scemino (scemino74 at gmail.com)
Date: 2024-03-17T20:50:05+01:00

Commit Message:
TWP: Fix potential buffer overflow in font. PVS-Studio V576

Changed paths:
    engines/twp/font.cpp


diff --git a/engines/twp/font.cpp b/engines/twp/font.cpp
index 17d764be306..75c717761be 100644
--- a/engines/twp/font.cpp
+++ b/engines/twp/font.cpp
@@ -214,7 +214,7 @@ void BmFont::load(const Common::String &name) {
 		} else if (line.hasPrefix("chars")) {
 		} else if (line.hasPrefix("char")) {
 			Char c;
-			sscanf(line.c_str(), "char id=%d\tx=%d\ty=%d\twidth=%d\theight=%d\txoffset=%d\tyoffset=%d\txadvance=%d\tpage=%d\tchnl=%d\tletter=\"%s\"", &c.id, &c.x, &c.y, &c.w, &c.h, &c.xoff, &c.yoff, &c.xadv, &c.page, &c.chnl, tmp);
+			sscanf(line.c_str(), "char id=%d\tx=%d\ty=%d\twidth=%d\theight=%d\txoffset=%d\tyoffset=%d\txadvance=%d\tpage=%d\tchnl=%d\tletter=\"%79s\"", &c.id, &c.x, &c.y, &c.w, &c.h, &c.xoff, &c.yoff, &c.xadv, &c.page, &c.chnl, tmp);
 			_glyphs[c.id] = Glyph{c.xadv,
 								  Common::Rect(c.xoff, _lnHeight - c.yoff - c.h, c.xoff + c.w, _lnHeight - c.yoff),
 								  Common::Rect(c.x, c.y, c.x + c.w, c.y + c.h)};


Commit: bce268e920bc996b81b856ad63093dd282d503a7
    https://github.com/scummvm/scummvm/commit/bce268e920bc996b81b856ad63093dd282d503a7
Author: scemino (scemino74 at gmail.com)
Date: 2024-03-17T20:50:05+01:00

Commit Message:
TWP: Fix not all members of XorKey are initialized. PVS-Studio V730

Changed paths:
    engines/twp/ggpack.h


diff --git a/engines/twp/ggpack.h b/engines/twp/ggpack.h
index b087a62fceb..dfd2f88be7c 100644
--- a/engines/twp/ggpack.h
+++ b/engines/twp/ggpack.h
@@ -32,8 +32,11 @@
 namespace Twp {
 
 struct XorKey {
+	XorKey() {}
+	XorKey(const Common::Array<int> &mb, int m) : magicBytes(mb), multiplier(m) {}
+
 	Common::Array<int> magicBytes;
-	int multiplier;
+	int multiplier = 0;
 };
 
 class MemStream : public Common::SeekableReadStream {
@@ -176,7 +179,7 @@ private:
 
 class GGPackSet {
 public:
-	void init(const XorKey& key);
+	void init(const XorKey &key);
 	bool assetExists(const char *asset);
 
 	bool containsDLC() const;


Commit: fffeb8d472af67cc232b0b36661e100ec1e83cab
    https://github.com/scummvm/scummvm/commit/fffeb8d472af67cc232b0b36661e100ec1e83cab
Author: scemino (scemino74 at gmail.com)
Date: 2024-03-17T20:50:05+01:00

Commit Message:
TWP: Fix not all members of Object are initialized. PVS-Studio V730

Changed paths:
    engines/twp/object.cpp


diff --git a/engines/twp/object.cpp b/engines/twp/object.cpp
index 4df8ea1f00b..8ca225a569b 100644
--- a/engines/twp/object.cpp
+++ b/engines/twp/object.cpp
@@ -89,10 +89,14 @@ Object::Object()
 	_nodeAnim = Common::SharedPtr<Anim>(new Anim(this));
 	_node->addChild(_nodeAnim.get());
 	sq_resetobject(&_table);
+	sq_resetobject(&_enter);
+	sq_resetobject(&_leave);
 }
 
 Object::Object(HSQOBJECT o, const Common::String &key)
 	: _talkOffset(0, 90), _table(o), _key(key) {
+	sq_resetobject(&_enter);
+	sq_resetobject(&_leave);
 }
 
 Object::~Object() {


Commit: 2830f1b9173d9dfbd2b2537f1dda40c03b237821
    https://github.com/scummvm/scummvm/commit/2830f1b9173d9dfbd2b2537f1dda40c03b237821
Author: scemino (scemino74 at gmail.com)
Date: 2024-03-17T20:50:05+01:00

Commit Message:
TWP: Fix not all members of ShaderParams are initialized. PVS-Studio V730

Changed paths:
    engines/twp/shaders.h


diff --git a/engines/twp/shaders.h b/engines/twp/shaders.h
index 39fc88432e8..4156fecce6e 100644
--- a/engines/twp/shaders.h
+++ b/engines/twp/shaders.h
@@ -35,9 +35,9 @@ extern const char *sepiaShader;
 struct ShaderParams {
 	RoomEffect effect = RoomEffect::None;
 	float sepiaFlicker = 1.f;
-	float randomValue[5];
-	float timeLapse;
-	float iGlobalTime;
+	float randomValue[5] = {0.f, 0.f, 0.f, 0.f, 0.f};
+	float timeLapse = 0.f;
+	float iGlobalTime =	0.f;
 	float iNoiseThreshold = 1.f;
 	float iFade = 1.f;
 	float wobbleIntensity = 1.f;


Commit: 8ea7be47108cdabf2027655798f7f59a1c781bf1
    https://github.com/scummvm/scummvm/commit/8ea7be47108cdabf2027655798f7f59a1c781bf1
Author: scemino (scemino74 at gmail.com)
Date: 2024-03-17T20:50:05+01:00

Commit Message:
TWP: Fix not all members of Thread are initialized. PVS-Studio V730

Changed paths:
    engines/twp/thread.h


diff --git a/engines/twp/thread.h b/engines/twp/thread.h
index ee544e18436..b305afb6ccc 100644
--- a/engines/twp/thread.h
+++ b/engines/twp/thread.h
@@ -88,7 +88,7 @@ public:
 
 public:
 	bool _global = false;
-	HSQOBJECT _obj, _threadObj, _envObj, _closureObj;
+	HSQOBJECT _threadObj, _envObj, _closureObj;
 	Common::Array<HSQOBJECT> _args;
 };
 


Commit: 220978d4eaddce2fd966b573cbbee2fbf478a454
    https://github.com/scummvm/scummvm/commit/220978d4eaddce2fd966b573cbbee2fbf478a454
Author: scemino (scemino74 at gmail.com)
Date: 2024-03-17T20:50:05+01:00

Commit Message:
TWP: Fix invalid expression in YackTokenReader. PVS-Studio V593

Changed paths:
    engines/twp/yack.cpp


diff --git a/engines/twp/yack.cpp b/engines/twp/yack.cpp
index a39cb7e6f31..ce14775527d 100644
--- a/engines/twp/yack.cpp
+++ b/engines/twp/yack.cpp
@@ -107,8 +107,7 @@ byte YackTokenReader::peek() {
 
 void YackTokenReader::ignore(int64 n, int delim) {
 	int64 i = 0;
-	byte b;
-	while ((i < n) && (b = _stream->readByte() != delim)) {
+	while ((i < n) && (_stream->readByte() != delim)) {
 		i++;
 	}
 }


Commit: a7be536609e289f59b7c91014cb811e646a89fd0
    https://github.com/scummvm/scummvm/commit/a7be536609e289f59b7c91014cb811e646a89fd0
Author: scemino (scemino74 at gmail.com)
Date: 2024-03-17T20:50:05+01:00

Commit Message:
TWP: Fix not all members of YackToken are initialized. PVS-Studio V730

Changed paths:
    engines/twp/yack.cpp
    engines/twp/yack.h


diff --git a/engines/twp/yack.cpp b/engines/twp/yack.cpp
index ce14775527d..9c4206ed9f4 100644
--- a/engines/twp/yack.cpp
+++ b/engines/twp/yack.cpp
@@ -66,12 +66,12 @@ YackTokenReader::Iterator::Iterator(YackTokenReader &reader, int64 pos)
 }
 
 YackTokenReader::Iterator::Iterator(const Iterator &it)
-	: _reader(it._reader), _pos(it._pos), _YackToken(it._YackToken) {
+	: _reader(it._reader), _pos(it._pos), _token(it._token) {
 }
 
 YackTokenReader::Iterator &YackTokenReader::Iterator::operator++() {
 	_reader->_stream->seek(_pos);
-	_reader->readYackToken(_YackToken);
+	_reader->readYackToken(_token);
 	_pos = _reader->_stream->pos();
 	return *this;
 }
@@ -83,15 +83,15 @@ YackTokenReader::Iterator YackTokenReader::Iterator::operator++(int) {
 }
 
 YackToken &YackTokenReader::Iterator::operator*() {
-	return _YackToken;
+	return _token;
 }
 
 const YackToken &YackTokenReader::Iterator::operator*() const {
-	return _YackToken;
+	return _token;
 }
 
 YackToken *YackTokenReader::Iterator::operator->() {
-	return &_YackToken;
+	return &_token;
 }
 
 void YackTokenReader::open(Common::SeekableReadStream *stream) {
diff --git a/engines/twp/yack.h b/engines/twp/yack.h
index 75c235ce3de..78da7ed938c 100644
--- a/engines/twp/yack.h
+++ b/engines/twp/yack.h
@@ -309,10 +309,10 @@ public:
 };
 
 struct YackToken {
-	YackTokenId id;
-	int64 start;
-	int64 end;
-	int line;
+	YackTokenId id = YackTokenId::None;
+	int64 start = 0;
+	int64 end = 0;
+	int line = 0;
 
 	Common::String toString() const;
 };
@@ -329,7 +329,7 @@ public:
 	private:
 		YackTokenReader *_reader = nullptr;
 		int64 _pos = 0;
-		YackToken _YackToken;
+		YackToken _token;
 
 	public:
 		Iterator() {}
@@ -340,7 +340,7 @@ public:
 
 		Iterator &operator=(const Iterator &rhs) {
 			_pos = rhs._pos;
-			_YackToken = rhs._YackToken;
+			_token = rhs._token;
 			_reader = rhs._reader;
 			return *this;
 		}


Commit: f3e512c34fa4facd18576b2902a6b5d51c335dc6
    https://github.com/scummvm/scummvm/commit/f3e512c34fa4facd18576b2902a6b5d51c335dc6
Author: scemino (scemino74 at gmail.com)
Date: 2024-03-17T20:50:05+01:00

Commit Message:
TWP: Use explicit cast in AudioSystem. PVS-Studio V636

Changed paths:
    engines/twp/audio.cpp


diff --git a/engines/twp/audio.cpp b/engines/twp/audio.cpp
index d8b2d625537..bb4cf583ee9 100644
--- a/engines/twp/audio.cpp
+++ b/engines/twp/audio.cpp
@@ -147,7 +147,7 @@ float AudioSystem::getMasterVolume() const {
 void AudioSystem::updateVolume(AudioSlot *slot) {
 	float vol = _masterVolume * slot->volume;
 	if (slot->fadeInTimeMs) {
-		vol *= (g_twp->_mixer->getElapsedTime(slot->handle).msecs() / slot->total);
+		vol *= (((float)g_twp->_mixer->getElapsedTime(slot->handle).msecs()) / slot->total);
 	}
 	if (slot->fadeOutTimeMs) {
 		float startFade = slot->total - slot->fadeOutTimeMs;


Commit: c93c448af305116ed166f04ec3be520eeb3290bf
    https://github.com/scummvm/scummvm/commit/c93c448af305116ed166f04ec3be520eeb3290bf
Author: scemino (scemino74 at gmail.com)
Date: 2024-03-17T21:15:19+01:00

Commit Message:
TWP: The 'thAlign' variable was assigned the same value. PVS-Studio V1048

Changed paths:
    engines/twp/objlib.cpp


diff --git a/engines/twp/objlib.cpp b/engines/twp/objlib.cpp
index edac820a14c..ec49f1e1698 100644
--- a/engines/twp/objlib.cpp
+++ b/engines/twp/objlib.cpp
@@ -108,7 +108,6 @@ static SQInteger createTextObject(HSQUIRRELVM v) {
 			thAlign = thLeft;
 			break;
 		case 0x0000000020000000:
-			thAlign = thCenter;
 			break;
 		case 0x0000000040000000:
 			thAlign = thRight;


Commit: 8f64a85b2bbfb16bfa57b562186248afb83af9e0
    https://github.com/scummvm/scummvm/commit/8f64a85b2bbfb16bfa57b562186248afb83af9e0
Author: scemino (scemino74 at gmail.com)
Date: 2024-03-17T21:15:19+01:00

Commit Message:
TWP: The 'effect' variable was assigned the same value. PVS-Studio V1048

Changed paths:
    engines/twp/roomlib.cpp


diff --git a/engines/twp/roomlib.cpp b/engines/twp/roomlib.cpp
index e25b6042ef7..b0798b608a1 100644
--- a/engines/twp/roomlib.cpp
+++ b/engines/twp/roomlib.cpp
@@ -417,7 +417,6 @@ static SQInteger roomFade(HSQUIRRELVM v) {
 	bool sepia = false;
 	switch (fadeType) {
 	case FADE_IN:
-		effect = FadeEffect::In;
 		break;
 	case FADE_OUT:
 		effect = FadeEffect::Out;


Commit: 0d0f85b55fd5d3333ae6153a82009ba566d36c01
    https://github.com/scummvm/scummvm/commit/0d0f85b55fd5d3333ae6153a82009ba566d36c01
Author: scemino (scemino74 at gmail.com)
Date: 2024-03-17T21:15:19+01:00

Commit Message:
TWP: Use explicit cast in Inventory. PVS-Studio V636

Changed paths:
    engines/twp/scenegraph.cpp


diff --git a/engines/twp/scenegraph.cpp b/engines/twp/scenegraph.cpp
index 4e99abf9561..c59309b90af 100644
--- a/engines/twp/scenegraph.cpp
+++ b/engines/twp/scenegraph.cpp
@@ -572,7 +572,7 @@ static bool hasDownArrow(Common::SharedPtr<Object> actor) {
 Inventory::Inventory() : Node("Inventory") {
 	for (int i = 0; i < NUMOBJECTS; i++) {
 		float x = SCREEN_WIDTH / 2.f + ARROWWIDTH + MARGIN + ((i % NUMOBJECTSBYROW) * (BACKWIDTH + BACKOFFSET));
-		float y = MARGINBOTTOM + BACKHEIGHT + BACKOFFSET - ((i / NUMOBJECTSBYROW) * (BACKHEIGHT + BACKOFFSET));
+		float y = MARGINBOTTOM + BACKHEIGHT + BACKOFFSET - (((float)(i) / NUMOBJECTSBYROW) * (BACKHEIGHT + BACKOFFSET));
 		_itemRects[i] = Common::Rect(x, y, x + BACKWIDTH, y + BACKHEIGHT);
 	}
 	_arrowUpRect = Common::Rect(SCREEN_WIDTH / 2.f, ARROWHEIGHT + MARGINBOTTOM + BACKOFFSET, SCREEN_WIDTH / 2.f + ARROWWIDTH, ARROWHEIGHT + MARGINBOTTOM + BACKOFFSET + ARROWHEIGHT);


Commit: 15566ca54b6a7f4970d3da3654158a4add355296
    https://github.com/scummvm/scummvm/commit/15566ca54b6a7f4970d3da3654158a4add355296
Author: scemino (scemino74 at gmail.com)
Date: 2024-03-17T21:15:19+01:00

Commit Message:
TWP: The function was exited without releasing the 'jActorValue' pointer. PVS-Studio V773

Changed paths:
    engines/twp/savegame.cpp


diff --git a/engines/twp/savegame.cpp b/engines/twp/savegame.cpp
index 31ea5b691ee..1a250dc239c 100644
--- a/engines/twp/savegame.cpp
+++ b/engines/twp/savegame.cpp
@@ -728,8 +728,7 @@ Common::String toString(const Math::Vector2d &pos) {
 // }
 
 static Common::JSONValue *createJActor(Common::SharedPtr<Object> actor) {
-	Common::JSONValue *jActorValue = tojson(actor->_table, false);
-	Common::JSONObject jActor(jActorValue->asObject());
+	Common::JSONObject jActor(tojson(actor->_table, false)->asObject());
 	int color = actor->_node->getComputedColor().toInt();
 	if (color != Color().toInt())
 		jActor["_color"] = new Common::JSONValue((long long int)color);


Commit: fa30bcd1ebd08c46d5e37f5cfedd028e5b904ac3
    https://github.com/scummvm/scummvm/commit/fa30bcd1ebd08c46d5e37f5cfedd028e5b904ac3
Author: scemino (scemino74 at gmail.com)
Date: 2024-03-17T21:19:33+01:00

Commit Message:
TWP: Fix warning, declaration requires a global destructor in debugtools.

Changed paths:
    engines/twp/debugtools.cpp
    engines/twp/debugtools.h
    engines/twp/twp.cpp


diff --git a/engines/twp/debugtools.cpp b/engines/twp/debugtools.cpp
index ed265b2469e..fb4e1c545cc 100644
--- a/engines/twp/debugtools.cpp
+++ b/engines/twp/debugtools.cpp
@@ -38,7 +38,7 @@
 
 namespace Twp {
 
-static struct {
+typedef struct ImGuiState {
 	bool _showThreads = false;
 	bool _showObjects = false;
 	bool _showObject = false;
@@ -56,17 +56,19 @@ static struct {
 	Common::String _textureSelected;
 	int _selectedActor = 0;
 	int _selectedObject = 0;
-} state;
+} ImGuiState;
+
+ImGuiState* _state = nullptr;
 
 ImVec4 gray(0.6f, 0.6f, 0.6f, 1.f);
 
 static void drawThreads() {
-	if (!state._showThreads)
+	if (!_state->_showThreads)
 		return;
 
 	ImGui::SetNextWindowSize(ImVec2(520, 600), ImGuiCond_FirstUseEver);
 	const auto &threads = g_twp->_threads;
-	if (ImGui::Begin("Threads", &state._showThreads)) {
+	if (ImGui::Begin("Threads", &_state->_showThreads)) {
 		ImGui::Text("# threads: %u", threads.size());
 		ImGui::Separator();
 
@@ -133,17 +135,17 @@ static void drawThreads() {
 }
 
 static void drawObjects() {
-	if (!state._showObjects)
+	if (!_state->_showObjects)
 		return;
 
 	ImGui::SetNextWindowSize(ImVec2(520, 600), ImGuiCond_FirstUseEver);
-	ImGui::Begin("Objects", &state._showObjects);
-	state._objFilter.Draw();
+	ImGui::Begin("Objects", &_state->_showObjects);
+	_state->_objFilter.Draw();
 
 	// show object list
 	for (const auto &layer : g_twp->_room->_layers) {
 		for (auto &obj : layer->_objects) {
-			if (state._objFilter.PassFilter(obj->_key.c_str())) {
+			if (_state->_objFilter.PassFilter(obj->_key.c_str())) {
 				ImGui::PushID(obj->getId());
 				bool visible = obj->_node->isVisible();
 				if (ImGui::Checkbox("", &visible)) {
@@ -153,7 +155,7 @@ static void drawObjects() {
 				Common::String name = obj->_key.empty() ? obj->getName() : Common::String::format("%s(%s) %d", obj->getName().c_str(), obj->_key.c_str(), obj->getId());
 				bool selected = false;
 				if (ImGui::Selectable(name.c_str(), &selected)) {
-					state._selectedObject = obj->getId();
+					_state->_selectedObject = obj->getId();
 				}
 				ImGui::PopID();
 			}
@@ -164,16 +166,16 @@ static void drawObjects() {
 }
 
 static void drawObject() {
-	if (!state._showObject)
+	if (!_state->_showObject)
 		return;
 
-	Common::SharedPtr<Object> obj(sqobj(state._selectedObject));
+	Common::SharedPtr<Object> obj(sqobj(_state->_selectedObject));
 	if (!obj)
 		return;
 
 	Common::String name = obj->_key.empty() ? obj->getName() : Common::String::format("%s(%s) %d", obj->getName().c_str(), obj->_key.c_str(), obj->getId());
 	ImGui::SetNextWindowSize(ImVec2(520, 600), ImGuiCond_FirstUseEver);
-	ImGui::Begin("Object", &state._showObject);
+	ImGui::Begin("Object", &_state->_showObject);
 	ImGui::Text("Name: %s", name.c_str());
 	ImGui::End();
 }
@@ -207,22 +209,22 @@ static ImVec4 getCategoryColor(Audio::Mixer::SoundType type) {
 }
 
 static void drawActors() {
-	if (!state._showActor)
+	if (!_state->_showActor)
 		return;
 
 	ImGui::SetNextWindowSize(ImVec2(520, 600), ImGuiCond_FirstUseEver);
-	ImGui::Begin("Actors", &state._showActor);
-	state._actorFilter.Draw();
+	ImGui::Begin("Actors", &_state->_showActor);
+	_state->_actorFilter.Draw();
 	ImGui::BeginChild("Actor_List");
 	for (auto &actor : g_twp->_actors) {
-		bool selected = actor->getId() == state._selectedActor;
+		bool selected = actor->getId() == _state->_selectedActor;
 		Common::String key(actor->_key);
-		if (state._actorFilter.PassFilter(actor->_key.c_str())) {
+		if (_state->_actorFilter.PassFilter(actor->_key.c_str())) {
 			if (key.empty()) {
 				key = "??";
 			}
 			if (ImGui::Selectable(key.c_str(), &selected)) {
-				state._selectedActor = actor->getId();
+				_state->_selectedActor = actor->getId();
 			}
 		}
 	}
@@ -231,15 +233,15 @@ static void drawActors() {
 }
 
 static void drawActor() {
-	if (!state._showActor)
+	if (!_state->_showActor)
 		return;
 
-	Common::SharedPtr<Object> actor(sqobj(state._selectedActor));
+	Common::SharedPtr<Object> actor(sqobj(_state->_selectedActor));
 	if (!actor)
 		return;
 
 	ImGui::SetNextWindowSize(ImVec2(520, 600), ImGuiCond_FirstUseEver);
-	ImGui::Begin("Actor", &state._showStack);
+	ImGui::Begin("Actor", &_state->_showStack);
 	ImGui::Text("Name: %s", actor->_key.c_str());
 	ImGui::Text("Costume: %s (%s)", actor->_costumeName.c_str(), actor->_costumeSheet.c_str());
 	ImGui::Text("Animation: %s", actor->_animName.c_str());
@@ -253,11 +255,11 @@ static void drawActor() {
 }
 
 static void drawStack() {
-	if (!state._showStack)
+	if (!_state->_showStack)
 		return;
 
 	ImGui::SetNextWindowSize(ImVec2(520, 600), ImGuiCond_FirstUseEver);
-	ImGui::Begin("Stack", &state._showStack);
+	ImGui::Begin("Stack", &_state->_showStack);
 	ImGui::BeginChild("ScrollingRegion");
 	SQInteger size = sq_gettop(g_twp->getVm());
 	ImGui::Text("size: %lld", size);
@@ -271,11 +273,11 @@ static void drawStack() {
 }
 
 static void drawResources() {
-	if (!state._showResources)
+	if (!_state->_showResources)
 		return;
 
 	ImGui::SetNextWindowSize(ImVec2(520, 600), ImGuiCond_FirstUseEver);
-	ImGui::Begin("Resources", &state._showResources);
+	ImGui::Begin("Resources", &_state->_showResources);
 
 	if (ImGui::BeginTable("Resources", 2, ImGuiTableFlags_Borders | ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Resizable | ImGuiTableFlags_RowBg)) {
 		ImGui::TableSetupColumn("Name");
@@ -285,9 +287,9 @@ static void drawResources() {
 		for (auto &res : g_twp->_resManager->_textures) {
 			ImGui::TableNextRow();
 			ImGui::TableNextColumn();
-			bool selected = state._textureSelected == res._key;
+			bool selected = _state->_textureSelected == res._key;
 			if (ImGui::Selectable(res._key.c_str(), selected)) {
-				state._textureSelected = res._key;
+				_state->_textureSelected = res._key;
 			}
 			ImGui::TableNextColumn();
 			ImGui::Text("%s", Common::String::format("%d x %d", res._value.width, res._value.height).c_str());
@@ -302,7 +304,7 @@ static void drawResources() {
 	ImGui::Text("Preview:");
 	ImGui::BeginChild("TexturePreview", ImVec2(0, 0), ImGuiChildFlags_Border | ImGuiChildFlags_ResizeX | ImGuiChildFlags_ResizeY);
 	for (auto &res : g_twp->_resManager->_textures) {
-		if (state._textureSelected == res._key) {
+		if (_state->_textureSelected == res._key) {
 			ImGui::Image((ImTextureID)(intptr_t)res._value.id, ImVec2(res._value.width, res._value.height));
 			break;
 		}
@@ -313,7 +315,7 @@ static void drawResources() {
 }
 
 static void drawAudio() {
-	if (!state._showAudio)
+	if (!_state->_showAudio)
 		return;
 
 	// count the number of active sounds
@@ -324,7 +326,7 @@ static void drawAudio() {
 	}
 
 	ImGui::SetNextWindowSize(ImVec2(520, 600), ImGuiCond_FirstUseEver);
-	ImGui::Begin("Sounds", &state._showAudio);
+	ImGui::Begin("Sounds", &_state->_showAudio);
 	ImGui::Text("# sounds: %d/%d", count, NUM_AUDIO_SLOTS);
 	ImGui::Separator();
 
@@ -518,14 +520,14 @@ static void drawGeneral() {
 
 	// Windows
 	if (ImGui::CollapsingHeader("Windows")) {
-		ImGui::Checkbox("Threads", &state._showThreads);
-		ImGui::Checkbox("Objects", &state._showObjects);
-		ImGui::Checkbox("Object", &state._showObject);
-		ImGui::Checkbox("Actor", &state._showActor);
-		ImGui::Checkbox("Stack", &state._showStack);
-		ImGui::Checkbox("Audio", &state._showAudio);
-		ImGui::Checkbox("Resources", &state._showResources);
-		ImGui::Checkbox("Scene graph", &state._showScenegraph);
+		ImGui::Checkbox("Threads", &_state->_showThreads);
+		ImGui::Checkbox("Objects", &_state->_showObjects);
+		ImGui::Checkbox("Object", &_state->_showObject);
+		ImGui::Checkbox("Actor", &_state->_showActor);
+		ImGui::Checkbox("Stack", &_state->_showStack);
+		ImGui::Checkbox("Audio", &_state->_showAudio);
+		ImGui::Checkbox("Resources", &_state->_showResources);
+		ImGui::Checkbox("Scene graph", &_state->_showScenegraph);
 	}
 	ImGui::Separator();
 
@@ -546,13 +548,13 @@ static void drawGeneral() {
 	if (ImGui::CollapsingHeader("Fade Shader")) {
 		ImGui::Separator();
 		const char *FadeEffects = "None\0In\0Out\0Wobble\0\0";
-		ImGui::Combo("Fade effect", &state._fadeEffect, FadeEffects);
-		ImGui::DragFloat("Duration", &state._fadeDuration, 0.1f, 0.f, 10.f);
-		ImGui::Checkbox("Fade to sepia", &state._fadeToSepia);
+		ImGui::Combo("Fade effect", &_state->_fadeEffect, FadeEffects);
+		ImGui::DragFloat("Duration", &_state->_fadeDuration, 0.1f, 0.f, 10.f);
+		ImGui::Checkbox("Fade to sepia", &_state->_fadeToSepia);
 		ImGui::Text("Elapsed %f", g_twp->_fadeShader->_elapsed);
 		ImGui::Text("Fade %f", g_twp->_fadeShader->_fade);
 		if (ImGui::Button("GO")) {
-			g_twp->fadeTo((FadeEffect)state._fadeEffect, state._fadeDuration, state._fadeToSepia);
+			g_twp->fadeTo((FadeEffect)_state->_fadeEffect, _state->_fadeDuration, _state->_fadeToSepia);
 		}
 	}
 	ImGui::Separator();
@@ -563,17 +565,17 @@ static void drawGeneral() {
 
 static void drawNode(Node *node) {
 	auto children = node->getChildren();
-	bool selected = state._node == node;
+	bool selected = _state->_node == node;
 	if (children.empty()) {
 		if (ImGui::Selectable(node->getName().c_str(), &selected)) {
-			state._node = node;
+			_state->_node = node;
 		}
 	} else {
 		ImGui::PushID(node->getName().c_str());
 		if (ImGui::TreeNode("")) {
 			ImGui::SameLine();
 			if (ImGui::Selectable(node->getName().c_str(), &selected)) {
-				state._node = node;
+				_state->_node = node;
 			}
 			for (const auto &child : children) {
 				drawNode(child);
@@ -582,7 +584,7 @@ static void drawNode(Node *node) {
 		} else {
 			ImGui::SameLine();
 			if (ImGui::Selectable(node->getName().c_str(), &selected)) {
-				state._node = node;
+				_state->_node = node;
 			}
 		}
 		ImGui::PopID();
@@ -590,37 +592,41 @@ static void drawNode(Node *node) {
 }
 
 static void drawScenegraph() {
-	if (!state._showScenegraph)
+	if (!_state->_showScenegraph)
 		return;
 
 	ImGui::SetNextWindowSize(ImVec2(520, 600), ImGuiCond_FirstUseEver);
-	ImGui::Begin("Scenegraph", &state._showScenegraph);
+	ImGui::Begin("Scenegraph", &_state->_showScenegraph);
 	drawNode(g_twp->_scene.get());
 	ImGui::End();
 
 	ImGui::SetNextWindowSize(ImVec2(520, 600), ImGuiCond_FirstUseEver);
-	if (state._node != nullptr) {
+	if (_state->_node != nullptr) {
 		ImGui::Begin("Node");
-		bool visible = state._node->isVisible();
-		if (ImGui::Checkbox(state._node->getName().c_str(), &visible)) {
-			state._node->setVisible(visible);
+		bool visible = _state->_node->isVisible();
+		if (ImGui::Checkbox(_state->_node->getName().c_str(), &visible)) {
+			_state->_node->setVisible(visible);
 		}
-		int zsort = state._node->getZSort();
+		int zsort = _state->_node->getZSort();
 		if (ImGui::DragInt("Z-Sort", &zsort)) {
-			state._node->setZSort(zsort);
+			_state->_node->setZSort(zsort);
 		}
-		Math::Vector2d pos = state._node->getPos();
+		Math::Vector2d pos = _state->_node->getPos();
 		if (ImGui::DragFloat2("Pos", pos.getData())) {
-			state._node->setPos(pos);
+			_state->_node->setPos(pos);
 		}
-		Math::Vector2d offset = state._node->getOffset();
+		Math::Vector2d offset = _state->_node->getOffset();
 		if (ImGui::DragFloat2("Offset", offset.getData())) {
-			state._node->setOffset(offset);
+			_state->_node->setOffset(offset);
 		}
 		ImGui::End();
 	}
 }
 
+void onImGuiInit() {
+	_state = new ImGuiState();
+}
+
 void onImGuiRender() {
 	if (!debugChannelSet(-1, kDebugConsole)) {
 		ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange | ImGuiConfigFlags_NoMouse;
@@ -640,4 +646,8 @@ void onImGuiRender() {
 	drawActor();
 }
 
+void onImGuiCleanup() {
+	delete _state;
+	_state = nullptr;
+}
 } // namespace Twp
diff --git a/engines/twp/debugtools.h b/engines/twp/debugtools.h
index 2cb5cdc647f..89e2089fa8f 100644
--- a/engines/twp/debugtools.h
+++ b/engines/twp/debugtools.h
@@ -23,7 +23,9 @@
 #define TWP_DEBUGTOOLS_H
 
 namespace Twp {
+void onImGuiInit();
 void onImGuiRender();
+void onImGuiCleanup();
 }
 
 #endif
diff --git a/engines/twp/twp.cpp b/engines/twp/twp.cpp
index 78d5263f0e0..f0de334fa2b 100644
--- a/engines/twp/twp.cpp
+++ b/engines/twp/twp.cpp
@@ -92,6 +92,10 @@ TwpEngine::TwpEngine(OSystem *syst, const TwpGameDescription *gameDesc)
 }
 
 TwpEngine::~TwpEngine() {
+#ifdef USE_IMGUI
+	onImGuiCleanup();
+#endif
+
 	_mixer->stopAll();
 	delete _screen;
 }
@@ -840,6 +844,10 @@ Common::Error TwpEngine::run() {
 
 	updateSettingVars();
 
+#ifdef USE_IMGUI
+	onImGuiInit();
+#endif
+
 	// Simple event handling loop
 	Common::Event e;
 	uint time = _system->getMillis();




More information about the Scummvm-git-logs mailing list