Skip to content

Commit 58afc41

Browse files
authored
examples: Reuse not_current_context in resumed() handler
When testing the `glutin` example on Android, after suspending and resuming the app no triangle appears. As it turns out the `winit 0.30` bump in #1678 never reuses the `not_current_context` that was set apart in `suspend()`, but creates a new one, without re-running initialization code such as creating the `Renderer`. Partially restore original code before the `winit 0.30` bump, which never created a context in `resume()` because it was already available before the loop started (and moved back in place in `suspend()`). Note also that more initialization code that now (unnecessarily) lives in `resume()` used to be outside of the loop.
1 parent 3296c9a commit 58afc41

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

glutin_examples/src/lib.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,10 @@ impl ApplicationHandler for App {
9292
.with_context_api(ContextApi::OpenGl(Some(Version::new(2, 1))))
9393
.build(raw_window_handle);
9494

95-
self.not_current_gl_context.replace(unsafe {
95+
// Reuse the uncurrented context from a suspended() call if it exists, otherwise
96+
// this is the first time resumed() is called, where the context still
97+
// has to be created.
98+
let not_current_gl_context = self.not_current_gl_context.take().unwrap_or_else(|| unsafe {
9699
gl_display.create_context(&gl_config, &context_attributes).unwrap_or_else(|_| {
97100
gl_display.create_context(&gl_config, &fallback_context_attributes).unwrap_or_else(
98101
|_| {
@@ -121,8 +124,7 @@ impl ApplicationHandler for App {
121124
unsafe { gl_config.display().create_window_surface(&gl_config, &attrs).unwrap() };
122125

123126
// Make it current.
124-
let gl_context =
125-
self.not_current_gl_context.take().unwrap().make_current(&gl_surface).unwrap();
127+
let gl_context = not_current_gl_context.make_current(&gl_surface).unwrap();
126128

127129
// The context needs to be current for the Renderer to set up shaders and
128130
// buffers. It also performs function loading, which needs a current context on

0 commit comments

Comments
 (0)