Bug fix: stop using AHasher for Id:s

AHasher does not produce same hashes efter e.g. restarting an app
This commit is contained in:
Emil Ernerfeldt 2020-11-28 12:24:38 +01:00
parent ac03242ec3
commit 8163f912d3
3 changed files with 10 additions and 4 deletions

View file

@ -41,15 +41,19 @@ impl Id {
}
pub fn new(source: impl Hash) -> Id {
// NOTE: AHasher is NOT suitable for this!
use std::collections::hash_map::DefaultHasher;
use std::hash::Hasher;
let mut hasher = ahash::AHasher::default();
let mut hasher = DefaultHasher::default();
source.hash(&mut hasher);
Id(hasher.finish())
}
pub fn with(self, child: impl Hash) -> Id {
// NOTE: AHasher is NOT suitable for this!
use std::collections::hash_map::DefaultHasher;
use std::hash::Hasher;
let mut hasher = ahash::AHasher::default();
let mut hasher = DefaultHasher::default();
hasher.write_u64(self.0);
child.hash(&mut hasher);
Id(hasher.finish())

View file

@ -134,7 +134,8 @@ impl Fonts {
let mut atlas = atlas.lock();
let texture = atlas.texture_mut();
// Make sure we seed the texture version with something unique based on the default characters:
let mut hasher = ahash::AHasher::default();
use std::collections::hash_map::DefaultHasher;
let mut hasher = DefaultHasher::default();
texture.pixels.hash(&mut hasher);
texture.version = hasher.finish();
}

View file

@ -41,7 +41,8 @@ where
}
fn hash(value: impl Hash) -> u64 {
let mut hasher = ahash::AHasher::default();
use std::collections::hash_map::DefaultHasher;
let mut hasher = DefaultHasher::default();
value.hash(&mut hasher);
hasher.finish()
}