diff options
| author | Irene Knapp <ireneista@irenes.space> | 2026-07-03 13:42:55 -0700 |
|---|---|---|
| committer | Irene Knapp <ireneista@irenes.space> | 2026-07-03 13:42:55 -0700 |
| commit | 842565c5def7b446a509f13c31d98d6735ff6777 (patch) | |
| tree | 393a8b6d93422183e78ed2b3a0f416512580a352 /src/main.rs | |
| parent | 7749604e56cd95d3620a8bf800f9c565b90f136e (diff) | |
better managing of state
Force-Push: yes Change-Id: I5a6982e0f8d06ff173fd31948dbd0f579b3d38ba
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 12 |
1 files changed, 10 insertions, 2 deletions
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(()) |