MaxEd
MaxEd

Reputation: 362

surfaceCreated called twice after onRestart/onResume

When my application is paused and then restarted, I'm noticing that I'm getting surfaceCreated callback twice. What's even more interesting, the first time it is called before my code creates the new surface. This wrecks all kinds of chaos, and I'd like to understand why is it happening, and how can I filter that spurious callback out and not react to it, or stop it from being called at all.

Here's a relevant excerpt from logcat:

10-20 11:35:21.834 24548 24548 D AllegroEGL: destroying egl_Surface
10-20 11:35:21.844 24548 24548 D AllegroEGL: destroying egl_Context
10-20 11:35:22.874 24548 24548 D AllegroSurface: surfaceDestroyed end
10-20 11:35:22.884 24548 24548 D AllegroActivity: onSaveInstanceState
10-20 11:35:22.884 24548 24548 D AllegroActivity: onStop.
// Here, the game is paused and restored
10-20 11:35:27.524 24548 24548 D AllegroActivity: onRestart.
10-20 11:35:27.524 24548 24548 D AllegroActivity: onStart.
10-20 11:35:27.524 24548 24548 D AllegroActivity: onResume
10-20 11:35:27.624 24548 24548 I allegro : android  D 24548:         android_system.c:303  Java_org_liballeg_android_AllegroActivity_nativeOnResume [  69.49768] resume activity
10-20 11:35:27.624 24548 24548 I allegro : android  D 24548:     android_system.c:316  Java_org_liballeg_android_AllegroActivity_nativeOnResume [  69.49773] got display: 0x5d55fd20
10-20 11:35:27.624 24548 24548 D AllegroActivity: postCreateSurface
10-20 11:35:27.624 24548 24548 D AllegroActivity: onResume end
10-20 11:35:33.964 24548 24548 I Choreographer: Skipped 388 frames!  The application may be doing too much work on its main thread.
10-20 11:35:33.984 24548 24548 D AllegroSurface: surfaceCreated
// Later:
10-20 11:35:48.934 24548 24548 D AllegroActivity: createSurface
// ... lots of action ...
10-20 11:36:02.044 24548 24548 D AllegroActivity: createSurface end

postCreateSurface contains looks like this:

void postCreateSurface()
{
   try {
      Log.d("AllegroActivity", "postCreateSurface");

      handler.post(new Runnable() {
         public void run() {
            createSurface();
         }
      });
   } catch (Exception x) {
      Log.d("AllegroActivity", "postCreateSurface exception: " + x.getMessage());
   }
}

As you can see, it calls "createSurface" function, which should log "createSurface" and "createSurface end" into logcat. And indeed it does - but only after "surfaceCreated" callback!

Attempts to use this first surface lead to GL_INVALID_OPERATION errors, so it's clearly a bad one.

I'm at a loss to understand what happens here, and what should I do.

Upvotes: 1

Views: 1032

Answers (1)

edwell
edwell

Reputation: 91

Some changes you do in Surface View makes it call surfaceCreated() again, for example: "yourSurfaceView.getHolder().setFormat(PixelFormat.TRANSPARENT)" will call surfaceCreated() again.

Upvotes: 2

Related Questions