[Scummvm-git-logs] scummvm branch-2-6 -> f380e3edda2f76b8618db97d559cae45d2132ba2

criezy noreply at scummvm.org
Sun Oct 9 23:16:40 UTC 2022


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:
f380e3edda AGS: fixed object cache may sometimes keep an old dynsprite ref


Commit: f380e3edda2f76b8618db97d559cae45d2132ba2
    https://github.com/scummvm/scummvm/commit/f380e3edda2f76b8618db97d559cae45d2132ba2
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2022-10-09T23:41:00+01:00

Commit Message:
AGS: fixed object cache may sometimes keep an old dynsprite ref

This may result in object texture not updating if the old sprite was deleted but a new dynamic sprite was created right after having same ID.

Was broken by upstream 9dffb04 in 3.5.1, and also some later changes in 3.6.0.

>From upstream 7ed51861898d864902b0f61b0cb7d0acadef1fe3

Changed paths:
    engines/ags/engine/ac/draw.cpp
    engines/ags/engine/ac/draw.h
    engines/ags/engine/ac/game.cpp


diff --git a/engines/ags/engine/ac/draw.cpp b/engines/ags/engine/ac/draw.cpp
index b598a3d1c82..28d82e17b70 100644
--- a/engines/ags/engine/ac/draw.cpp
+++ b/engines/ags/engine/ac/draw.cpp
@@ -603,19 +603,24 @@ void mark_object_changed(int objid) {
 	_G(objcache)[objid].y = -9999;
 }
 
-void reset_objcache_for_sprite(int sprnum) {
-	// Check if this sprite is assigned to any game object, and update them if necessary
+void reset_objcache_for_sprite(int sprnum, bool deleted) {
+	// Check if this sprite is assigned to any game object, and mark these for update;
+	// if the sprite was deleted, also dispose shared textures
 	// room objects cache
 	if (_G(croom) != nullptr) {
 		for (size_t i = 0; i < (size_t)_G(croom)->numobj; ++i) {
-			if (_G(objs)[i].num == sprnum)
+			if (_G(objcache)[i].sppic == sprnum)
 				_G(objcache)[i].sppic = -1;
+			if (deleted && (_GP(actsps)[i].SpriteID == sprnum))
+				_GP(actsps)[i] = ObjTexture();
 		}
 	}
 	// character cache
 	for (size_t i = 0; i < (size_t)_GP(game).numcharacters; ++i) {
 		if (_GP(charcache)[i].sppic == sprnum)
 			_GP(charcache)[i].sppic = -1;
+		if (deleted && (_GP(actsps)[ACTSP_OBJSOFF + i].SpriteID == sprnum))
+			_GP(actsps)[i] = ObjTexture();
 	}
 }
 
diff --git a/engines/ags/engine/ac/draw.h b/engines/ags/engine/ac/draw.h
index 6c032b51edb..9b750871e51 100644
--- a/engines/ags/engine/ac/draw.h
+++ b/engines/ags/engine/ac/draw.h
@@ -130,7 +130,7 @@ void on_roomcamera_changed(Camera *cam);
 // Marks particular object as need to update the texture
 void mark_object_changed(int objid);
 // Resets all object caches which reference this sprite
-void reset_objcache_for_sprite(int sprnum);
+void reset_objcache_for_sprite(int sprnum, bool deleted);
 
 // whether there are currently remnants of a DisplaySpeech
 void mark_screen_dirty();
diff --git a/engines/ags/engine/ac/game.cpp b/engines/ags/engine/ac/game.cpp
index 3a1908ed4ba..ec72f72a984 100644
--- a/engines/ags/engine/ac/game.cpp
+++ b/engines/ags/engine/ac/game.cpp
@@ -1336,7 +1336,7 @@ bool unserialize_audio_script_object(int index, const char *objectType, Stream *
 
 void game_sprite_updated(int sprnum) {
 	// character and object draw caches
-	reset_objcache_for_sprite(sprnum);
+	reset_objcache_for_sprite(sprnum, false);
 
 	// gui backgrounds
 	for (auto &gui : _GP(guis)) {
@@ -1365,7 +1365,7 @@ void game_sprite_updated(int sprnum) {
 
 void game_sprite_deleted(int sprnum) {
 	// character and object draw caches
-	reset_objcache_for_sprite(sprnum);
+	reset_objcache_for_sprite(sprnum, true);
 	// room object graphics
 	if (_G(croom) != nullptr) {
 		for (size_t i = 0; i < (size_t)_G(croom)->numobj; ++i) {




More information about the Scummvm-git-logs mailing list