From f05d5d11e4a72e5ebae2c89461c22b5319a1afe7 Mon Sep 17 00:00:00 2001 From: Ian Elliott Date: Tue, 17 May 2016 12:03:35 -0600 Subject: demos: GH#559 fix for new Android windows On Android, treat a 1st-time new window differently from an nth-time new window. --- demos/cube.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/demos/cube.c b/demos/cube.c index bc391414..680e4245 100644 --- a/demos/cube.c +++ b/demos/cube.c @@ -3088,6 +3088,19 @@ static void processCommand(struct android_app* app, int32_t cmd) { switch(cmd) { case APP_CMD_INIT_WINDOW: { if (app->window) { + // We're getting a new window. If the app is starting up, we + // need to initialize. If the app has already been + // initialized, that means that we lost our previous window, + // which means that we have a lot of work to do. At a minimum, + // we need to destroy the swapchain and surface associated with + // the old window, and create a new surface and swapchain. + // However, since there are a lot of other objects/state that + // is tied to the swapchain, it's easiest to simply cleanup and + // start over (i.e. use a brute-force approach of re-starting + // the app) + if (demo.prepared) { + demo_cleanup(&demo); + } demo_init(&demo, 0, NULL); demo.window = (void*)app->window; demo_init_vk_swapchain(&demo); @@ -3117,6 +3130,8 @@ void android_main(struct android_app *app) return; #endif + demo.prepared = false; + app->onAppCmd = processCommand; app->onInputEvent = processInput; -- cgit v1.2.3