Skip to content

Commit

Permalink
Merge branch 'main' into simplify-safety-reasoning
Browse files Browse the repository at this point in the history
  • Loading branch information
ecton committed Dec 19, 2023
2 parents 7af2d31 + 6541704 commit 8b6b3d9
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,11 +341,10 @@ where
let app = PendingApp::new_with_event_callback(
|request: CreateSurfaceRequest<WindowEvent>, windows: &appit::Windows<WindowEvent>| {
let window = windows.get(request.window).expect("window not found");
// SAFETY: This callback is only invoked by the winit event
// loop, where the window will already be removed from the
// collection if it is closed. Additionally, because this
// callback is only invoked from the winit event loop, we are
// guaranteed that we are on the original thread winit began on.
// SAFETY: The winit window is valid and open when it is
// contained in the windows collection. The surface being
// created is stored on the KludgineWindow, which is dropped
// prior to the appit/winit window closing.
unsafe {
shared_wgpu()
.create_surface(&*window)
Expand Down Expand Up @@ -608,7 +607,6 @@ struct KludgineWindow<Behavior> {
queue: wgpu::Queue,
msaa_texture: Option<wgpu::Texture>,
_adapter: wgpu::Adapter,
wgpu: Arc<wgpu::Instance>,
}

impl<T, User> appit::WindowBehavior<CreateSurfaceRequest<User>> for KludgineWindow<T>
Expand Down Expand Up @@ -689,7 +687,6 @@ where
surface.configure(&device, &config);

Self {
wgpu,
kludgine: state,
last_render,
last_render_duration: Duration::ZERO,
Expand All @@ -703,8 +700,7 @@ where
}
}

#[allow(unsafe_code)]
unsafe fn redraw(&mut self, window: &mut RunningWindow<CreateSurfaceRequest<User>>) {
fn redraw(&mut self, window: &mut RunningWindow<CreateSurfaceRequest<User>>) {
let surface = loop {
match self.surface.get_current_texture() {
Ok(frame) => break frame,
Expand All @@ -717,11 +713,12 @@ where
return;
}
wgpu::SurfaceError::Lost => {
// SAFETY: redraw is only called while the event loop
// and window are still alive. The caller guarantees that this
// `KlugineWindow` and therefore the `surface`, is dropped
// before the window is dropped.
self.surface = unsafe { self.wgpu.create_surface(window.winit()).unwrap() };
self.surface = window
.send(CreateSurfaceRequest {
window: window.winit().id(),
data: PhantomData,
})
.expect("app not running");
self.surface.configure(&self.device, &self.config);
}
wgpu::SurfaceError::OutOfMemory => {
Expand Down

0 comments on commit 8b6b3d9

Please sign in to comment.