Skip to content

Commit 779dd38

Browse files
committed
Fix to handle currentDrawable being nullable
1 parent ce4b5ee commit 779dd38

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

crates/icrate/examples/metal.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,13 @@ declare_class!(
152152
#[method(drawInMTKView:)]
153153
#[allow(non_snake_case)]
154154
unsafe fn drawInMTKView(&self, _view: &MTKView) {
155+
// FIXME: icrate `MTKView` doesn't have a generated binding for `currentDrawable` yet
156+
// (because it needs a definition of `CAMetalDrawable`, which we don't support yet) so
157+
// we have to use a raw `msg_send_id` call here instead.
158+
let current_drawable: Option<Id<ProtocolObject<dyn MTLDrawable>>> =
159+
msg_send_id![&*self.mtk_view, currentDrawable];
160+
161+
let Some(current_drawable) = current_drawable else { return; };
155162
let Some(command_buffer) = self.command_queue.commandBuffer() else { return; };
156163
let Some(pass_descriptor) = (unsafe { self.mtk_view.currentRenderPassDescriptor() }) else { return; };
157164
let Some(encoder) = command_buffer.renderCommandEncoderWithDescriptor(&pass_descriptor) else { return; };
@@ -179,12 +186,6 @@ declare_class!(
179186
};
180187
encoder.endEncoding();
181188

182-
// FIXME: icrate `MTKView` doesn't have a generated binding for `currentDrawable` yet
183-
// (because it needs a definition of `CAMetalDrawable`, which we don't support yet) so
184-
// we have to use a raw `msg_send_id` call here instead.
185-
let current_drawable: Id<ProtocolObject<dyn MTLDrawable>> =
186-
msg_send_id![&*self.mtk_view, currentDrawable];
187-
188189
command_buffer.presentDrawable(&current_drawable);
189190

190191
command_buffer.commit();

0 commit comments

Comments
 (0)