From 8163f912d3bff83906db8fa283e310bee68c4bd1 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Sat, 28 Nov 2020 12:24:38 +0100 Subject: [PATCH] Bug fix: stop using AHasher for Id:s AHasher does not produce same hashes efter e.g. restarting an app --- egui/src/id.rs | 8 ++++++-- egui/src/paint/fonts.rs | 3 ++- egui/src/util/cache.rs | 3 ++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/egui/src/id.rs b/egui/src/id.rs index 2b82b1d1..51656188 100644 --- a/egui/src/id.rs +++ b/egui/src/id.rs @@ -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()) diff --git a/egui/src/paint/fonts.rs b/egui/src/paint/fonts.rs index 4a982629..eeeb6d82 100644 --- a/egui/src/paint/fonts.rs +++ b/egui/src/paint/fonts.rs @@ -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(); } diff --git a/egui/src/util/cache.rs b/egui/src/util/cache.rs index abf40728..575ee0b6 100644 --- a/egui/src/util/cache.rs +++ b/egui/src/util/cache.rs @@ -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() }