[Scummvm-git-logs] scummvm master -> 4656a75fc5956375d49830c47161e3360127fee9
criezy
criezy at scummvm.org
Thu Feb 11 22:55:20 UTC 2021
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:
4656a75fc5 AGS: Hash memory address instead of content in ManagedObjectPool
Commit: 4656a75fc5956375d49830c47161e3360127fee9
https://github.com/scummvm/scummvm/commit/4656a75fc5956375d49830c47161e3360127fee9
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2021-02-11T22:55:10Z
Commit Message:
AGS: Hash memory address instead of content in ManagedObjectPool
The ManagedObjectPool uses const char * for pointers, and unfortunately
in ScummVM by default we have a hash function on const char * that
computes the hash on the string and not the address. This caused
various issues such as accessing freed memory. This changes matches
what the original interpreter does and fixes crash and scripts errors
in many games.
This matches what the original interpreter does and
Changed paths:
engines/ags/engine/ac/dynobj/managedobjectpool.h
diff --git a/engines/ags/engine/ac/dynobj/managedobjectpool.h b/engines/ags/engine/ac/dynobj/managedobjectpool.h
index 1dee09a0da..a27034358a 100644
--- a/engines/ags/engine/ac/dynobj/managedobjectpool.h
+++ b/engines/ags/engine/ac/dynobj/managedobjectpool.h
@@ -39,6 +39,13 @@ class Stream;
using namespace AGS; // FIXME later
+struct Pointer_Hash {
+ uint operator()(const char *v) const {
+ uint x = static_cast<uint>(reinterpret_cast<uintptr>(v));
+ return x + (x >> 3);
+ }
+};
+
struct ManagedObjectPool final {
private:
// TODO: find out if we can make handle size_t
@@ -68,7 +75,7 @@ private:
int32_t nextHandle{}; // TODO: manage nextHandle's going over INT32_MAX !
std::queue<int32_t> available_ids;
std::vector<ManagedObject> objects;
- std::unordered_map<const char *, int32_t> handleByAddress;
+ std::unordered_map<const char *, int32_t, Pointer_Hash> handleByAddress;
void Init(int32_t theHandle, const char *theAddress, ICCDynamicObject *theCallback, ScriptValueType objType);
int Remove(ManagedObject &o, bool force = false);
More information about the Scummvm-git-logs
mailing list