summary refs log tree commit diff
diff options
context:
space:
mode:
authorIrene Knapp <ireneista@irenes.space>2026-07-03 13:42:55 -0700
committerIrene Knapp <ireneista@irenes.space>2026-07-03 13:42:55 -0700
commit842565c5def7b446a509f13c31d98d6735ff6777 (patch)
tree393a8b6d93422183e78ed2b3a0f416512580a352
parent7749604e56cd95d3620a8bf800f9c565b90f136e (diff)
better managing of state
Force-Push: yes
Change-Id: I5a6982e0f8d06ff173fd31948dbd0f579b3d38ba
-rw-r--r--flake.nix4
-rw-r--r--src/main.rs12
2 files changed, 12 insertions, 4 deletions
diff --git a/flake.nix b/flake.nix
index 5a6b93f..702c355 100644
--- a/flake.nix
+++ b/flake.nix
@@ -25,8 +25,6 @@
         libxcursor
         libxi
         libxkbcommon
-        # mesa
-        # wayland
         vulkan-loader
       ];
   in {
@@ -38,6 +36,8 @@
 
         nativeBuildInputs = with pkgs; [ autoPatchelfHook ];
       }).overrideAttrs {
+        # This needs to apply only to the top-level derivation, not to the
+        # dependencies.
         preFixup = ''
           patchelf --add-needed libxkbcommon-x11.so \
                    --add-needed libvulkan.so.1 \
diff --git a/src/main.rs b/src/main.rs
index 4fcb01c..e45e49f 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -95,17 +95,17 @@ fn ignore_errors(mut body: impl FnMut() -> Result<()>) -> () {
 
 
 struct Surreality {
+  window: OnceCell<Window>,
   entry: OnceCell<Entry>,
   instance: OnceCell<Instance>,
-  window: OnceCell<Window>,
 }
 
 impl Surreality {
   fn new() -> Self {
     Surreality {
+      window: OnceCell::new(),
       entry: OnceCell::new(),
       instance: OnceCell::new(),
-      window: OnceCell::new(),
     }
   }
 
@@ -116,12 +116,17 @@ impl Surreality {
               .with_inner_size(LogicalSize::new(1024, 768));
       let window: Window = event_loop.create_window(window_attributes)?;
       let _ = self.window.set(window);
+    }
 
+    if self.entry.get().is_none() {
       #[allow(unsafe_code)]
       let loader = unsafe { LibloadingLoader::new(LIBRARY)? };
       #[allow(unsafe_code)]
       let entry = unsafe { Entry::new(loader)? };
+      let _ = self.entry.set(entry);
+    }
 
+    if self.instance.get().is_none() {
       let application_info = ApplicationInfo::builder()
         .application_name(b"Surreality\0")
         .application_version(vk::make_version(1, 0, 0))
@@ -139,8 +144,11 @@ impl Surreality {
 
       #[allow(unsafe_code)]
       let instance = unsafe {
+        let entry = self.entry.get().unwrap();
         entry.create_instance(&instance_create_info, None)?
       };
+
+      let _ = self.instance.set(instance);
     }
 
     Ok(())