浏览代码

fix resource_context crash issue on mac

/siyaoH-1.17-PlatformMessage
xingwei.zhu 4 年前
当前提交
1a686c1e
共有 1 个文件被更改,包括 16 次插入7 次删除
  1. 23
      engine/src/shell/platform/unity/darwin/macos/unity_surface_manager.mm

23
engine/src/shell/platform/unity/darwin/macos/unity_surface_manager.mm


gl_context_ = [[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:nil];
gl_resource_context_ = [[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:gl_context_];
FML_DCHECK(gl_context_ != nullptr && gl_resource_context_ != nullptr);
FML_DCHECK(gl_context_ != nullptr);
}
UnitySurfaceManager::~UnitySurfaceManager() { ReleaseNativeRenderContext(); }

const GLuint ConstGLType = GL_UNSIGNED_INT_8_8_8_8_REV;
//render context must be available
FML_DCHECK(metal_device_ != nullptr && gl_context_ != nullptr && gl_resource_context_ != nullptr);
FML_DCHECK(metal_device_ != nullptr && gl_context_ != nullptr);
//render textures must be released already
FML_DCHECK(pixelbuffer_ref == nullptr && default_fbo_ == 0 && gl_tex_ == 0 && gl_tex_cache_ref_ == nullptr && gl_tex_ref_ == nullptr && metal_tex_ == nullptr && metal_tex_ref_ == nullptr && metal_tex_cache_ref_ == nullptr);

bool UnitySurfaceManager::MakeCurrentResourceContext()
{
[gl_resource_context_ makeCurrentContext];
if (gl_resource_context_ == nullptr)
{
[gl_context_ makeCurrentContext];
}
else
{
[gl_resource_context_ makeCurrentContext];
}
return true;
}

void UnitySurfaceManager::ReleaseNativeRenderContext()
{
FML_DCHECK(gl_resource_context_);
CGLReleaseContext(gl_resource_context_.CGLContextObj);
gl_resource_context_ = nullptr;
if (gl_resource_context_ != nullptr)
{
CGLReleaseContext(gl_resource_context_.CGLContextObj);
gl_resource_context_ = nullptr;
}
FML_DCHECK(gl_context_);
CGLReleaseContext(gl_context_.CGLContextObj);

return true;
}
} // namespace uiwidgets
} // namespace uiwidgets
正在加载...
取消
保存