pub fn new<F>(instance: &Arc<Instance>, filter : MessageFilter, user_callback: F)
                  -> Result<DebugCallback, DebugCallbackCreationError>
        where F: Fn(&Message) + 'static + Send + panic::RefUnwindSafe
    {
        if !instance.loaded_extensions().ext_debug_utils {
            return Err(DebugCallbackCreationError::MissingExtension);
        }

        // Note that we need to double-box the callback, because a `*const Fn()` is a fat pointer
        // that can't be cast to a `*const c_void`.
        let user_callback = Box::new(Box::new(user_callback) as Box<_>);

        extern "system" fn callback(message_severity: vk::DebugUtilsMessageSeverityFlagBitsEXT, ty : vk::DebugUtilsMessageTypeFlagsEXT,
                                    callback_data : *const vk::DebugUtilsMessengerCallbackDataEXT, user_data : *mut c_void)
                                    -> u32 {
            unsafe {
                let user_callback = user_data as *mut Box<Fn()> as *const _;
                let user_callback: &Box<Fn(&Message)> = &*user_callback;

                let message_id_name = CStr::from_ptr((*callback_data).pMessageIdName)
                    .to_str()
                    .expect("debug callback message not utf-8");

                let message_id_number = (*callback_data).messageIdNumber;

                let description = CStr::from_ptr((*callback_data).pMessage)
                    .to_str()
                    .expect("debug callback message not utf-8");

                let command_buffer_labels : Vec<MessageLabel> = slice::from_raw_parts((*callback_data).pCmdBufLabels, (*callback_data).cmdBufLabelCount as usize)
                        .iter().map(|e| {
                            MessageLabel::from_raw(e)
                        }).collect();

                let queue_labels = slice::from_raw_parts((*callback_data).pQueueLabels, (*callback_data).queueLabelCount as usize)
                    .iter().map(|e|{
                        MessageLabel::from_raw(e)
                    }).collect();

                let objects = slice::from_raw_parts((*callback_data).pObjects, (*callback_data).objectCount as usize)
                    .iter().map(|e|{ 
                        ObjectNameInfo::from_raw(e)
                    }).collect();


                let flags = vk::DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT | vk::DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT;
                let message = Message {
                    severity: MessageSeverity(message_severity),
                    ty: MessageType(ty),
                    id_number: message_id_number,
                    id_name: &message_id_name,
                    description: &description,
                    queue_labels: queue_labels,
                    command_buffer_labels: command_buffer_labels,
                    objects: objects,
                };

                // Since we box the closure, the type system doesn't detect that the `UnwindSafe`
                // bound is enforced. Therefore we enforce it manually.
                let _ = panic::catch_unwind(panic::AssertUnwindSafe(move || {
                                                                        user_callback(&message);
                                                                    }));

                vk::FALSE
            }
        }

        let infos = vk::DebugUtilsMessengerCreateInfoEXT {
            sType: vk::STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT,
            pNext: ptr::null(),
            flags: 0, // Placeholder
            messageSeverity: filter.severity.0,
            messageType: filter.types.0,
            pfnUserCallback: callback,
            pUserData: &*user_callback as &Box<_> as *const Box<_> as *const c_void as *mut _,
        };

        let vk = instance.pointers();

        let debug_utils_messenger = unsafe {
            let mut output = mem::uninitialized();
            check_errors(vk.CreateDebugUtilsMessengerEXT(instance.internal_object(),
                                                         &infos,
                                                         ptr::null(),
                                                         &mut output))?;
            output
        };

        Ok(DebugCallback {
               instance: instance.clone(),
               debug_utils_messenger: debug_utils_messenger,
               user_callback: user_callback,
           })
    }
/// Initializes a debug callback.
///
/// Panics generated by calling `user_callback` are ignored.
Initializes a debug callback.
Panics generated by calling `user_callback` are ignored.
Initializes a debug callback . Panics generated by calling ` user_callback ` are ignored .
pub fn new<F>(instance: &Arc<Instance>, filter : MessageFilter, user_callback: F)
                  -> Result<DebugCallback, DebugCallbackCreationError>
        where F: Fn(&Message) + 'static + Send + panic::RefUnwindSafe
    {
        if !instance.loaded_extensions().ext_debug_utils {
            return Err(DebugCallbackCreationError::MissingExtension);
        }
        // Note that we need to double-box the callback, because a `*const Fn()` is a fat pointer
        // that can't be cast to a `*const c_void`.
        let user_callback = Box::new(Box::new(user_callback) as Box<_>);
        extern "system" fn callback(message_severity: vk::DebugUtilsMessageSeverityFlagBitsEXT, ty : vk::DebugUtilsMessageTypeFlagsEXT,
                                    callback_data : *const vk::DebugUtilsMessengerCallbackDataEXT, user_data : *mut c_void)
                                    -> u32 {
            unsafe {
                let user_callback = user_data as *mut Box<Fn()> as *const _;
                let user_callback: &Box<Fn(&Message)> = &*user_callback;
                let message_id_name = CStr::from_ptr((*callback_data).pMessageIdName)
                    .to_str()
                    .expect("debug callback message not utf-8");
                let message_id_number = (*callback_data).messageIdNumber;
                let description = CStr::from_ptr((*callback_data).pMessage)
                    .to_str()
                    .expect("debug callback message not utf-8");
                let command_buffer_labels : Vec<MessageLabel> = slice::from_raw_parts((*callback_data).pCmdBufLabels, (*callback_data).cmdBufLabelCount as usize)
                        .iter().map(|e| {
                            MessageLabel::from_raw(e)
                        }).collect();
                let queue_labels = slice::from_raw_parts((*callback_data).pQueueLabels, (*callback_data).queueLabelCount as usize)
                    .iter().map(|e|{
                        MessageLabel::from_raw(e)
                    }).collect();
                let objects = slice::from_raw_parts((*callback_data).pObjects, (*callback_data).objectCount as usize)
                    .iter().map(|e|{ 
                        ObjectNameInfo::from_raw(e)
                    }).collect();
                let flags = vk::DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT | vk::DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT;
                let message = Message {
                    severity: MessageSeverity(message_severity),
                    ty: MessageType(ty),
                    id_number: message_id_number,
                    id_name: &message_id_name,
                    description: &description,
                    queue_labels: queue_labels,
                    command_buffer_labels: command_buffer_labels,
                    objects: objects,
                };
                // Since we box the closure, the type system doesn't detect that the `UnwindSafe`
                // bound is enforced. Therefore we enforce it manually.
                let _ = panic::catch_unwind(panic::AssertUnwindSafe(move || {
                                                                        user_callback(&message);
                                                                    }));
                vk::FALSE
            }
        }
        let infos = vk::DebugUtilsMessengerCreateInfoEXT {
            sType: vk::STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT,
            pNext: ptr::null(),
            flags: 0, // Placeholder
            messageSeverity: filter.severity.0,
            messageType: filter.types.0,
            pfnUserCallback: callback,
            pUserData: &*user_callback as &Box<_> as *const Box<_> as *const c_void as *mut _,
        };
        let vk = instance.pointers();
        let debug_utils_messenger = unsafe {
            let mut output = mem::uninitialized();
            check_errors(vk.CreateDebugUtilsMessengerEXT(instance.internal_object(),
                                                         &infos,
                                                         ptr::null(),
                                                         &mut output))?;
            output
        };
        Ok(DebugCallback {
               instance: instance.clone(),
               debug_utils_messenger: debug_utils_messenger,
               user_callback: user_callback,
           })
    }
pub fn new < F > ( instance : & Arc < Instance > , filter : MessageFilter , user_callback : F ) -> Result < DebugCallback , DebugCallbackCreationError > where F : Fn ( & Message ) + ' static + Send + panic :: RefUnwindSafe { if ! instance . loaded_extensions ( ) . ext_debug_utils { return Err ( DebugCallbackCreationError :: MissingExtension ) ; } // Note that we need to double-box the callback, because a `*const Fn()` is a fat pointer // that can't be cast to a `*const c_void`. let user_callback = Box :: new ( Box :: new ( user_callback ) as Box < _ > ) ; extern " " fn callback ( message_severity : vk :: DebugUtilsMessageSeverityFlagBitsEXT , ty : vk :: DebugUtilsMessageTypeFlagsEXT , callback_data : * const vk :: DebugUtilsMessengerCallbackDataEXT , user_data : * mut c_void ) -> u32 { unsafe { let user_callback = user_data as * mut Box < Fn ( ) > as * const _ ; let user_callback : & Box < Fn ( & Message ) > = & * user_callback ; let message_id_name = CStr :: from_ptr ( ( * callback_data ) . pMessageIdName ) . to_str ( ) . expect ( " " ) ; let message_id_number = ( * callback_data ) . messageIdNumber ; let description = CStr :: from_ptr ( ( * callback_data ) . pMessage ) . to_str ( ) . expect ( " " ) ; let command_buffer_labels : Vec < MessageLabel > = slice :: from_raw_parts ( ( * callback_data ) . pCmdBufLabels , ( * callback_data ) . cmdBufLabelCount as usize ) . iter ( ) . map ( | e | { MessageLabel :: from_raw ( e ) } ) . collect ( ) ; let queue_labels = slice :: from_raw_parts ( ( * callback_data ) . pQueueLabels , ( * callback_data ) . queueLabelCount as usize ) . iter ( ) . map ( | e | { MessageLabel :: from_raw ( e ) } ) . collect ( ) ; let objects = slice :: from_raw_parts ( ( * callback_data ) . pObjects , ( * callback_data ) . objectCount as usize ) . iter ( ) . map ( | e | { ObjectNameInfo :: from_raw ( e ) } ) . collect ( ) ; let flags = vk :: DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT | vk :: DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT ; let message = Message { severity : MessageSeverity ( message_severity ) , ty : MessageType ( ty ) , id_number : message_id_number , id_name : & message_id_name , description : & description , queue_labels : queue_labels , command_buffer_labels : command_buffer_labels , objects : objects , } ; // Since we box the closure, the type system doesn't detect that the `UnwindSafe` // bound is enforced. Therefore we enforce it manually. let _ = panic :: catch_unwind ( panic :: AssertUnwindSafe ( move | | { user_callback ( & message ) ; } ) ) ; vk :: FALSE } } let infos = vk :: DebugUtilsMessengerCreateInfoEXT { sType : vk :: STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT , pNext : ptr :: null ( ) , flags : 0 , // Placeholder messageSeverity : filter . severity . 0 , messageType : filter . types . 0 , pfnUserCallback : callback , pUserData : & * user_callback as & Box < _ > as * const Box < _ > as * const c_void as * mut _ , } ; let vk = instance . pointers ( ) ; let debug_utils_messenger = unsafe { let mut output = mem :: uninitialized ( ) ; check_errors ( vk . CreateDebugUtilsMessengerEXT ( instance . internal_object ( ) , & infos , ptr :: null ( ) , & mut output ) ) ? ; output } ; Ok ( DebugCallback { instance : instance . clone ( ) , debug_utils_messenger : debug_utils_messenger , user_callback : user_callback , } ) }
Initializes a debug callback.
Initializes a debug callback .
instance
&Arc<Instance>
filter
MessageFilter
user_callback
F
instance
&Arc<Instance>
filter
MessageFilter
user_callback
F