From b696beea65bbffd31edac169ccf9708f46ab9652 Mon Sep 17 00:00:00 2001 From: Hein-Pieter van Braam Date: Wed, 15 Feb 2017 14:41:16 +0100 Subject: Correct hash behavior for floating point numbers This fixes HashMap where a key or part of a key is a floating point number. To fix this the following has been done: * HashMap now takes an extra template argument Comparator. This class gets used to compare keys. The default Comperator now works correctly for common types and floating point numbets. * Variant implements ::hash_compare() now. This function implements nan-safe comparison for all types with components that contain floating point numbers. * Variant now has a VariantComparator which uses Variant::hash_compare() safely compare floating point components of variant's types. * The hash functions for floating point numbers will now normalize NaN values so that all floating point numbers that are NaN hash to the same value. C++ module writers that want to use HashMap internally in their modules can now also safeguard against this crash by defining their on Comperator class that safely compares their types. GDScript users, or writers of modules that don't use HashMap internally in their modules don't need to do anything. This fixes #7354 and fixes #6947. --- tools/editor/plugins/baked_light_baker.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tools/editor') diff --git a/tools/editor/plugins/baked_light_baker.cpp b/tools/editor/plugins/baked_light_baker.cpp index 52220839d9..4219e791d1 100644 --- a/tools/editor/plugins/baked_light_baker.cpp +++ b/tools/editor/plugins/baked_light_baker.cpp @@ -1334,7 +1334,7 @@ void BakedLightBaker::_make_octree_texture() { base<<=16; base|=int((pos.z+cell_size*0.5)/cell_size); - uint32_t hash = HashMapHahserDefault::hash(base); + uint32_t hash = HashMapHasherDefault::hash(base); uint32_t idx = hash % hash_table_size; octhashptr[oct_idx].next=hashptr[idx]; octhashptr[oct_idx].hash=hash; @@ -1362,7 +1362,7 @@ void BakedLightBaker::_make_octree_texture() { base<<=16; base|=int((pos.z+cell_size*0.5)/cell_size); - uint32_t hash = HashMapHahserDefault::hash(base); + uint32_t hash = HashMapHasherDefault::hash(base); uint32_t idx = hash % hash_table_size; uint32_t bucket = hashptr[idx]; -- cgit v1.2.3