Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Fix queue event lifecycle on googlevr and noapi platforms #944

Merged
merged 1 commit into from
Feb 28, 2019

Conversation

MortimerGoro
Copy link
Contributor

GLSurfaceView.queueEvent() calls dispatched before the surfaceView renderer is ready are dispatched before the activityCreated callback is notified to native. This can cause some nullptr device states (we had to add a if not null workaround) or issues when initializing some data (e.g curdved setting on the first widgets created)

Copy link
Contributor

@bluemarvin bluemarvin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but rather than locking maybe just ensure the queue code is only called on the main UI thread?

if (mSurfaceCreated) {
mView.queueEvent(aRunnable);
} else {
synchronized (mPendingEvents) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are events getting queued off of the main UI thread?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

queueRunnable is always called from the main thread. But the pendingEvents array is iterated also when the surfaceCreated callback is received to notify the pending events

@MortimerGoro
Copy link
Contributor Author

I did some tests removing the lock and adding this to onSurfaceCreated:

PlatformActivity.this.runOnUiThread(() -> {
  mSurfaceCreated = true;
  notifyPendingEvents();
});

But we hit a deadlock on Daydream. runOnUiThread is never executed because onPause is waiting for a runnable being ran in the GLThread.

@bluemarvin
Copy link
Contributor

Would it make more sense to use the same queue we use on the other platforms and just stop using the GLView’s queue?

@MortimerGoro
Copy link
Contributor Author

I think it's a good idea for consistency. I'll run some tests

@MortimerGoro
Copy link
Contributor Author

MortimerGoro commented Feb 14, 2019

I did some tests on this branch: 3af65da (adapted for Daydream only)

Found two problems:

  • We can't correctly dispatch onDestroy() using the vrb::Queue because SurfaceView is already stopped in onPause. Tried with surfaceView.queueEvent only for that method, it works because the thread underlying thread is still alive.
  • On the next run after a destroy there is a deadlock in onPause(). Not sure why yet...

Using the lock solution of this PR the life cycle seems good, onDestroy is correctly dispatched and next run after a destroy runs ok.

@MortimerGoro MortimerGoro merged commit 828cdfa into master Feb 28, 2019
@cvan cvan deleted the queue_events branch March 5, 2019 09:50
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants