Skip to content

Commit 43daba3

Browse files
committed
Fix vertex hash oob/unaligned issues
1 parent ad40cb1 commit 43daba3

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/engine/renderer/GeometryOptimiser.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,18 @@ struct TriIndex {
6868

6969
struct MapVertHasher {
7070
size_t operator()( const srfVert_t& vert ) const {
71-
size_t hash = ~( *( ( size_t* ) &vert.xyz[0] ) << 15 );
72-
hash ^= ( *( ( size_t* ) &vert.xyz[0] ) >> 10 );
73-
hash += ( *( ( size_t* ) &vert.xyz[1] ) << 3 );
74-
hash ^= ( *( ( size_t* ) &vert.xyz[1] ) >> 6 );
75-
hash += ~( *( ( size_t* ) &vert.xyz[2] ) << 11 );
76-
hash ^= ( *( ( size_t* ) &vert.xyz[2] ) >> 16 );
77-
78-
hash ^= ( *( ( size_t* ) &vert.st[0] ) << 7 );
79-
hash += ( *( ( size_t* ) &vert.st[0] ) >> 12 );
80-
81-
hash ^= ( *( ( size_t* ) &vert.st[1] ) << 13 );
82-
hash += ( *( ( size_t* ) &vert.st[1] ) >> 8 );
71+
uint32_t hash = ~( Util::bit_cast<uint32_t, float>( vert.xyz[0] ) << 15 );
72+
hash ^= ( Util::bit_cast<uint32_t, float>( vert.xyz[0] ) >> 10 );
73+
hash += ( Util::bit_cast<uint32_t, float>( vert.xyz[1] ) << 3 );
74+
hash ^= ( Util::bit_cast<uint32_t, float>( vert.xyz[1] ) >> 6 );
75+
hash += ( Util::bit_cast<uint32_t, float>( vert.xyz[2] ) << 11 );
76+
hash ^= ( Util::bit_cast<uint32_t, float>( vert.xyz[2] ) >> 16 );
77+
78+
hash += ( Util::bit_cast<uint32_t, float>( vert.st[0] ) << 7 );
79+
hash ^= ( Util::bit_cast<uint32_t, float>( vert.st[0] ) >> 12 );
80+
81+
hash += ( Util::bit_cast<uint32_t, float>( vert.st[1] ) << 13 );
82+
hash ^= ( Util::bit_cast<uint32_t, float>( vert.st[1] ) >> 8 );
8383

8484
return hash;
8585
}

0 commit comments

Comments
 (0)