Skip to content

Commit c156f8a

Browse files
committed
fix: setting the target with canvas now waits for valid dimensions
This fixes drawing and it waits up to 5000ms
1 parent ba924f3 commit c156f8a

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/shared/memory.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
use lazy_static::lazy_static;
2-
use std::sync::Mutex;
2+
use std::{
3+
sync::Mutex,
4+
thread::sleep,
5+
time::{Duration, Instant},
6+
};
37
use windows::{
48
core::PCSTR,
59
Win32::{
@@ -121,6 +125,24 @@ impl MemoryManager {
121125
(*self.ptr).width = width;
122126
(*self.ptr).height = height;
123127
}
128+
129+
pub unsafe fn wait_dimensions(&self, time: u64) -> (i32, i32) {
130+
let start = Instant::now();
131+
let timeout = Duration::from_millis(time);
132+
133+
loop {
134+
let (w, h) = self.get_dimensions();
135+
if w > 0 && h > 0 {
136+
return (w, h);
137+
}
138+
139+
if start.elapsed() >= timeout {
140+
panic!("[WaspInput]: Timeout waiting for valid dimensions!\r\n");
141+
}
142+
143+
sleep(Duration::from_millis(100));
144+
}
145+
}
124146
}
125147

126148
lazy_static! {

src/simba/target.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ pub extern "C" fn SimbaPluginTarget_RequestWithDebugImage(
9797
.external_image_set_memory
9898
.expect("external_image_set_memory function pointer is null");
9999

100-
let (w, h) = mem_manager.get_dimensions();
100+
let (w, h) = mem_manager.wait_dimensions(5000);
101101

102102
let img = external_image_create(true);
103103
*overlay = img;

0 commit comments

Comments
 (0)