Fixed the hat_map to avoid segmentation fault (cherry picked from commit 57e78f4cf53b0fc84900a047120263c3c71e721c)