diff options
| -rw-r--r-- | flake.nix | 4 | ||||
| -rw-r--r-- | src/main.rs | 12 |
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(()) |