[Scummvm-git-logs] scummvm master -> 36c12ec472f8048980e6d3e9cc4505994bc77277

lephilousophe noreply at scummvm.org
Sun Aug 3 06:56:39 UTC 2025


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

Summary:
36c12ec472 AGS: When unloading game, reinitialize the game structures in-place


Commit: 36c12ec472f8048980e6d3e9cc4505994bc77277
    https://github.com/scummvm/scummvm/commit/36c12ec472f8048980e6d3e9cc4505994bc77277
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2025-08-03T08:50:52+02:00

Commit Message:
AGS: When unloading game, reinitialize the game structures in-place

This avoids changing the memory locations as other objects hold a
reference to them.
Still avoid using a stack allocated instance to initialize it.

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


diff --git a/engines/ags/engine/ac/game.cpp b/engines/ags/engine/ac/game.cpp
index 1ce17e4ffdf..b97d7d03a30 100644
--- a/engines/ags/engine/ac/game.cpp
+++ b/engines/ags/engine/ac/game.cpp
@@ -400,10 +400,13 @@ void unload_game() {
 	_GP(thisroom).Free();
 
 	// Free game state and game struct
-	delete _G(play);
-	_G(play) = new GameState();
-	delete _G(game);
-	_G(game) = new GameSetupStruct();
+	// Use placement new to keep the same memory locations
+	// as these structures are still referenced and may be reused
+	// in some games
+	_G(play)->~GameState();
+	new(_G(play)) GameState();
+	_G(game)->~GameSetupStruct();
+	new(_G(game)) GameSetupStruct();
 
 	// Reset all resource caches
 	// IMPORTANT: this is hard reset, including locked items




More information about the Scummvm-git-logs mailing list