summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorIrene Knapp <ireneista@irenes.space>2026-07-03 17:10:26 -0700
committerIrene Knapp <ireneista@irenes.space>2026-07-03 17:10:26 -0700
commitf0bd299429ec950a4c9e05ae7c22d98c0cd6cbac (patch)
treebd22e5c9a03b276aef152801a939bc65298ecf80 /src
parentd548bdcc43a947a1fbafe3d509668ca6f0e6d195 (diff)
okay, we get debug messages for instance creation/destruction now
Force-Push: yes
Change-Id: If47236337d13a1c565fb2a5423761f5896bfef45
Diffstat (limited to 'src')
-rw-r--r--src/main.rs49
1 files changed, 36 insertions, 13 deletions
diff --git a/src/main.rs b/src/main.rs
index 0312eb3..5bdce3b 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -238,8 +238,9 @@ impl Surreality {
       }
     }
 
-    //   Request the debug extension. This cooperates with code below, which
-    // runs after the instance is created.
+    //   Request the debug extension. This is the first of three bits of code
+    // that deal with this, and has the resonsibility of making sure the
+    // extension is in the list we ask for.
     let debug_extension_name = vk::EXT_DEBUG_UTILS_EXTENSION.name;
     if available_extensions.contains(&debug_extension_name) {
       extensions.push(debug_extension_name.as_ptr());
@@ -255,29 +256,51 @@ impl Surreality {
             .engine_version(vk::make_version(1, 0, 0))
             .api_version(vk::make_version(1, 0, 0));
 
-    let instance_create_info = InstanceCreateInfo::builder()
+    let mut instance_create_info = InstanceCreateInfo::builder()
             .application_info(&application_info)
             .flags(flags)
             .enabled_extension_names(&extensions)
             .enabled_layer_names(&layers);
 
+    //   Configure the debug extension. This is the middle of three bits of
+    // code that deal with this, and has the responsibility of making sure
+    // the callback will be available during instance creation and
+    // destruction, which is done in a special way that doesn't rely on having
+    // a messager, since there can't be one for those steps.
+    let debug_info = if available_extensions.contains(&debug_extension_name) {
+      let mut debug_info = vk::DebugUtilsMessengerCreateInfoEXT::builder()
+              .message_severity(vk::DebugUtilsMessageSeverityFlagsEXT::all())
+              .message_type(vk::DebugUtilsMessageTypeFlagsEXT::GENERAL
+                            | vk::DebugUtilsMessageTypeFlagsEXT::VALIDATION
+                            | vk::DebugUtilsMessageTypeFlagsEXT::PERFORMANCE)
+              .user_callback(Some(debug_messager_callback));
+
+      //   Please notice that the reference we pass here will escape Rust's
+      // lifetime checking, since push_next() casts it to a pointer. We don't
+      // get nearly as strong a safety guarantee as one might hope (and as [1]
+      // naively reassures us we do). If we did, the thing we're doing would
+      // actually be forbidden!
+      //
+      // [1] https://kylemayes.github.io/vulkanalia/
+      instance_create_info.push_next(&mut debug_info);
+
+      Some(debug_info)
+    } else { None };
+
     #[allow(unsafe_code)]
     let instance = unsafe {
+      //   We're promising that every struct referenced here is still alive.
+      // Since it's all pointers, that's... not a thing we statically know. Be
+      // aware. Only you can prevent segfaults.
       entry.create_instance(&instance_create_info, None)
     }?;
 
-    //   Configure the debug extension. This cooperates with code above, which
-    // requests the extension.
-    if available_extensions.contains(&debug_extension_name)
+    //   Configure the debug extension. This is the last of three bits of code
+    // that deal with this, and has the responsibility of asking the instance,
+    // which now exists, to create the debug messager.
+    if let Some(debug_info) = debug_info
        && self.debug_messager.get().is_none()
     {
-      let debug_info = vk::DebugUtilsMessengerCreateInfoEXT::builder()
-              .message_severity(vk::DebugUtilsMessageSeverityFlagsEXT::all())
-              .message_type(vk::DebugUtilsMessageTypeFlagsEXT::GENERAL
-                            | vk::DebugUtilsMessageTypeFlagsEXT::VALIDATION
-                            | vk::DebugUtilsMessageTypeFlagsEXT::PERFORMANCE)
-              .user_callback(Some(debug_messager_callback));
-
       #[allow(unsafe_code)]
       let debug_messager = unsafe {
         instance.create_debug_utils_messenger_ext(&debug_info, None)