Terminate the application

When the user closes the Falling Blocks application, we need to do some cleaning up to make sure the application shuts down properly. When an application receives a NAVIGATOR_EXIT event, the system directs the application to start shutting down. The application then has a certain amount of time (about 500 ms) to save its state and perform any additional cleanup operations. After this time has elapsed, if the application hasn't terminated yet, the system terminates it.

  1. Stop requesting events from the screen.

    screen_stop_events(screen_cxt);

  2. Shut down the BPS library, because we no longer need any BPS functions for the application. It's important to remember that after you perform this step, your application shouldn't call any other BPS functions.

    bps_shutdown();

  3. Free the memory that was allocated for the blocks. Because we used malloc() to allocate the memory, we should free it manually to make sure that we don't create a memory leak. The system should deallocate this memory anyways, but it's good practice to do it explicitly when we're done using it.

    free(boxes);

  4. Invoke bbutil_terminate(). This function cleans up the EGL setup by performing tasks such as destroying the EGL surface, context, and libscreen window.

    bbutil_terminate();

  5. Destroy the screen context, and exit the application.

    screen_destroy_context(screen_cxt);
    return 0;