libpag icon indicating copy to clipboard operation
libpag copied to clipboard

iOS libpag 使用libpag开屏动画,第一次安装系统弹权限弹窗导致开屏动画不播放

Open coder-xiaolong opened this issue 3 years ago • 1 comments

问的不是弹不弹窗的问题,而是弹窗之后PAG动画不播放;

系统层级弹窗会使 App ResignActive;导致 GLDevice 返回的是 nullptr;这块儿能否改为监听 UIApplicationDidEnterBackgroundNotification 和 UIApplicationWillEnterForegroundNotification ?

static bool RegisterNotifications() {
  [[NSNotificationCenter defaultCenter] addObserver:[PAGAppMonitor class]
                                           selector:@selector(applicationWillResignActive:)
                                               name:UIApplicationWillResignActiveNotification
                                             object:nil];
  [[NSNotificationCenter defaultCenter] addObserver:[PAGAppMonitor class]
                                           selector:@selector(applicationDidBecomeActive:)
                                               name:UIApplicationDidBecomeActiveNotification
                                             object:nil];
  return true;
}
std::shared_ptr<GLDevice> GLDevice::Current() {
  if (appInBackground) {
    return nullptr;
  }
  return EAGLDevice::Wrap([EAGLContext currentContext], true);
}

std::shared_ptr<GLDevice> GLDevice::Make(void* sharedContext) {
  if (appInBackground) {
    return nullptr;
  }
  EAGLContext* eaglContext = nil;
  EAGLContext* eaglShareContext = reinterpret_cast<EAGLContext*>(sharedContext);
  if (eaglShareContext != nil) {
    eaglContext = [[EAGLContext alloc] initWithAPI:[eaglShareContext API]
                                        sharegroup:[eaglShareContext sharegroup]];
  } else {
    eaglContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3];
    if (eaglContext == nil) {
      eaglContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
    }
  }
  if (eaglContext == nil) {
    return nullptr;
  }
  auto device = EAGLDevice::Wrap(eaglContext, false);
  [eaglContext release];
  return device;
}

Which Version of libpag are you using?

libpag 4.2.88

What Platform are you on?

iOS 12, Android 10, macOS 10.15.3, Chrome 87.0 ...

Expected Behavior

Actual Behavior

Code Example

PAG File

coder-xiaolong avatar Jun 15 '23 14:06 coder-xiaolong

这个没法这么改,因为只有在UIApplicationWillResignActiveNotification时监听才有机会把还没刷新的GL命令提交到GPU,如果UIApplicationDidEnterBackgroundNotification的时候已经来不及了,再执行任何glFinish指令会导致crash。这也是苹果官网推荐的兼容处理方式。

domchen avatar Sep 19 '23 03:09 domchen