layers: Be careful about casts. ptr -> uint64_t& isnt right on 32bit.
authorChris Forbes <chrisforbes@google.com>
Mon, 3 Oct 2016 21:08:31 +0000 (10:08 +1300)
committerChris Forbes <chrisforbes@google.com>
Mon, 3 Oct 2016 21:54:45 +0000 (10:54 +1300)
Signed-off-by: Chris Forbes <chrisforbes@google.com>
layers/object_tracker.cpp

index 13e1502..0a8f7a7 100644 (file)
@@ -33,6 +33,7 @@
 #include <string.h>
 
 #include <unordered_map>
+#include <type_traits>
 
 #include "vk_layer_config.h"
 #include "vk_layer_data.h"
@@ -245,7 +246,10 @@ static void CreateSwapchainImageObject(VkDevice dispatchable_object, VkImage swa
 template <typename T1, typename T2>
 static void CreateObject(T1 dispatchable_object, T2 object, VkDebugReportObjectTypeEXT object_type, bool custom_allocator) {
     layer_data *instance_data = get_my_data_ptr(get_dispatch_key(dispatchable_object), layer_data_map);
-    auto object_handle = reinterpret_cast<uint64_t &>(object);
+
+    auto object_handle = std::is_pointer<T2>::value
+        ? reinterpret_cast<uint64_t>(object)
+        : reinterpret_cast<uint64_t &>(object);
 
     log_msg(instance_data->report_data, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, object_type, object_handle,
             __LINE__, OBJTRACK_NONE, LayerName, "OBJ[0x%" PRIxLEAST64 "] : CREATE %s object 0x%" PRIxLEAST64, object_track_index++,
@@ -264,7 +268,9 @@ template <typename T1, typename T2>
 static void DestroyObject(T1 dispatchable_object, T2 object, VkDebugReportObjectTypeEXT object_type, bool custom_allocator) {
     layer_data *device_data = get_my_data_ptr(get_dispatch_key(dispatchable_object), layer_data_map);
 
-    uint64_t object_handle = reinterpret_cast<uint64_t &>(object);
+    auto object_handle = std::is_pointer<T2>::value
+        ? reinterpret_cast<uint64_t>(object)
+        : reinterpret_cast<uint64_t &>(object);
 
     auto item = device_data->object_map[object_type].find(object_handle);
     if (item != device_data->object_map[object_type].end()) {
@@ -305,7 +311,9 @@ static bool ValidateObject(T1 dispatchable_object, T2 object, VkDebugReportObjec
     if (null_allowed && (object == VK_NULL_HANDLE)) {
         return false;
     }
-    auto object_handle = reinterpret_cast<uint64_t &>(object);
+    auto object_handle = std::is_pointer<T2>::value
+        ? reinterpret_cast<uint64_t>(object)
+        : reinterpret_cast<uint64_t &>(object);
     layer_data *device_data = get_my_data_ptr(get_dispatch_key(dispatchable_object), layer_data_map);
     if (device_data->object_map[object_type].find(object_handle) == device_data->object_map[object_type].end()) {
         // If object is an image, also look for it in the swapchain image map