SimulaVR / Simula

Linux VR Desktop
MIT License
2.95k stars 87 forks source link

ViveCompositor.hs: Why does createDebugCallbackPtr not return an IO FunPtr? #37

Closed georgewsinger closed 6 years ago

georgewsinger commented 6 years ago

From ViveCompositor.hs:

foreign import ccall "wrapper" createDebugCallbackPtr :: (VkDebugReportFlagsEXT -> VkDebugReportObjectTypeEXT -> Word64 -> CSize -> Int32 -> Ptr CChar -> Ptr CChar -> Ptr Void -> IO VkBool32) -> IO PFN_vkDebugReportCallbackEXT

Question 1: Shouldn't this function's return type be

foreign import ccall "wrapper" createDebugCallbackPtr :: (VkDebugReportFlagsEXT -> VkDebugReportObjectTypeEXT -> Word64 -> CSize -> Int32 -> Ptr CChar -> Ptr CChar -> Ptr Void -> IO VkBool32) -> IO (FunPtr PFN_vkDebugReportCallbackEXT)

per usage of the "wrapper" keyword?


Note that this function is used in newVulkanInfo to print debugging messages to the console:

newVulkanInfo :: Bool -> IO VulkanInfo
newVulkanInfo verbose = do
-- ...
callbackPtr <- createDebugCallbackPtr $ \_ _ _ _ _ _ message _ -> peekCString message >>= print >> return (VkBool32 VK_FALSE)
-- ...

Question 2: Technically, shouldn't this function pointer be freed somewhere in the program?


In case useful, here's the C++ type PFN_vkDebugReportCallbackEXT:

typedef VkBool32 (VKAPI_PTR *PFN_vkDebugReportCallbackEXT)(
    VkDebugReportFlagsEXT                       flags,
    VkDebugReportObjectTypeEXT                  objectType,
    uint64_t                                    object,
    size_t                                      location,
    int32_t                                     messageCode,
    const char*                                 pLayerPrefix,
    const char*                                 pMessage,  //<--- here's what's being using in Simula
    void*                                       pUserData);
lboklin commented 6 years ago

Issue obsolete after move to Godot.