From 6e9a05f25d02f1b8283b85a5c60b997c08502916 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Fri, 12 Aug 2022 20:06:28 +0200 Subject: [PATCH] iOS: Fix UB in Context::create_context You can't call `init` on something more than once --- glutin/src/api/ios/mod.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/glutin/src/api/ios/mod.rs b/glutin/src/api/ios/mod.rs index cc40fc01bf..71147ad329 100644 --- a/glutin/src/api/ios/mod.rs +++ b/glutin/src/api/ios/mod.rs @@ -219,13 +219,13 @@ impl Context { unsafe fn create_context(mut version: ffi::NSUInteger) -> Result { let context_class = Class::get("EAGLContext").expect("Failed to get class `EAGLContext`"); - let eagl_context: ffi::id = msg_send![context_class, alloc]; - let mut valid_context = ffi::nil; - while valid_context == ffi::nil && version > 0 { - valid_context = msg_send![eagl_context, initWithAPI: version]; + let mut eagl_context: ffi::id = ffi::nil; + while eagl_context.is_null() && version > 0 { + eagl_context = msg_send![context_class, alloc]; + eagl_context = msg_send![eagl_context, initWithAPI: version]; version -= 1; } - if valid_context == ffi::nil { + if eagl_context.is_null() { Err(CreationError::OsError( "Failed to create an OpenGL ES context with any version".to_string(), ))