Ran into an issue today where I needed a simple hash of a var object. Did something like this
var testObj = var(new DynamicObject);
testObj.getDynamicObject()->setProperty("test",1);
testObj.getDynamicObject()->setProperty("test2", "Test");
testObj.getDynamicObject()->setProperty("test3", 4.1);
auto temp = DefaultHashFunctions::generateHash(testObj, INT32_MAX);
Each time I ran it I got a different hash number for the var. It seems like the function uses the var::toString() function, which I’m not sure why it wouldn’t be deterministic but alas. Maybe it has to do with the order of the properties or something?
toString on an object return the pointer value in hex, which is why you get a different value each time. You’ll probably need to write your own hash function if you need values to stay stable between runs. Or try converting object to json and hash that string?
As Roland mentioned, you need to convert this to a String, and you can use `juce::JSON::toString()` for that. You’ll need to make sure that the format options are the same each time, because an extra carriage return or decimal place will change the hash value.