浏览代码

fix occasional mac editor crash when play/stop the game multiple times

/siyaoH-1.17-PlatformMessage
Xingwei Zhu 3 年前
当前提交
38a08fc3
共有 4 个文件被更改,包括 30 次插入25 次删除
  1. 6
      engine/src/shell/platform/unity/darwin/ios/unity_surface_manager.h
  2. 14
      engine/src/shell/platform/unity/darwin/ios/unity_surface_manager.mm
  3. 6
      engine/src/shell/platform/unity/darwin/macos/unity_surface_manager.h
  4. 29
      engine/src/shell/platform/unity/darwin/macos/unity_surface_manager.mm

6
engine/src/shell/platform/unity/darwin/ios/unity_surface_manager.h


UnitySurfaceManager(IUnityInterfaces* unity_interfaces);
~UnitySurfaceManager();
//openGLES contexts
static EAGLContext *gl_context_;
static EAGLContext *gl_resource_context_;
void* CreateRenderTexture(size_t width, size_t height);
void ReleaseNativeRenderContext();

CVPixelBufferRef pixelbuffer_ref = nullptr;
//gl handlers
EAGLContext *gl_context_ = NULL;
EAGLContext *gl_resource_context_ = NULL;
GLuint default_fbo_ = 0;
GLuint gl_tex_ = 0;
CVOpenGLESTextureCacheRef gl_tex_cache_ref_ = nullptr;

14
engine/src/shell/platform/unity/darwin/ios/unity_surface_manager.mm


#define GL_UNSIGNED_INT_8_8_8_8_REV 0x8367
namespace uiwidgets {
EAGLContext* UnitySurfaceManager::gl_context_ = nullptr;
EAGLContext* UnitySurfaceManager::gl_resource_context_ = nullptr;
UnitySurfaceManager::UnitySurfaceManager(IUnityInterfaces* unity_interfaces)
{
FML_DCHECK(metal_device_ == nullptr);

metal_device_ = metalGraphics->MetalDevice();
//create opengl context
FML_DCHECK(!gl_context_);
FML_DCHECK(!gl_resource_context_);
if (gl_context_ == nullptr && gl_resource_context_ == nullptr) {
gl_context_ = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
gl_resource_context_ = [[EAGLContext alloc] initWithAPI:[gl_context_ API] sharegroup: [gl_context_ sharegroup]];
}
gl_context_ = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
gl_resource_context_ = [[EAGLContext alloc] initWithAPI:[gl_context_ API] sharegroup: [gl_context_ sharegroup]];
FML_DCHECK(gl_context_ != nullptr && gl_resource_context_ != nullptr);
}

void UnitySurfaceManager::ReleaseNativeRenderContext()
{
FML_DCHECK(gl_resource_context_);
gl_resource_context_ = nullptr;
gl_context_ = nullptr;
[EAGLContext setCurrentContext:nil];

6
engine/src/shell/platform/unity/darwin/macos/unity_surface_manager.h


UnitySurfaceManager(IUnityInterfaces* unity_interfaces);
~UnitySurfaceManager();
//openGL contexts
static NSOpenGLContext *gl_context_;
static NSOpenGLContext *gl_resource_context_;
void* CreateRenderTexture(size_t width, size_t height);
void ReleaseNativeRenderContext();

//pixel buffer handles
CVPixelBufferRef pixelbuffer_ref = nullptr;
//openGL handlers
NSOpenGLContext *gl_context_ = NULL;
NSOpenGLContext *gl_resource_context_ = NULL;
GLuint default_fbo_ = 0;
GLuint gl_tex_ = 0;
CVOpenGLTextureCacheRef gl_tex_cache_ref_ = nullptr;

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


#include "Unity/IUnityGraphicsMetal.h"
namespace uiwidgets {
NSOpenGLContext* UnitySurfaceManager::gl_context_ = nullptr;
NSOpenGLContext* UnitySurfaceManager::gl_resource_context_ = nullptr;
UnitySurfaceManager::UnitySurfaceManager(IUnityInterfaces* unity_interfaces)
{
FML_DCHECK(metal_device_ == nullptr);

metal_device_ = metalGraphics->MetalDevice();
//create opengl context
FML_DCHECK(!gl_context_);
FML_DCHECK(!gl_resource_context_);
NSOpenGLPixelFormatAttribute attrs[] =
if (gl_context_ == nullptr && gl_resource_context_ == nullptr) {
NSOpenGLPixelFormatAttribute attrs[] =
NSOpenGLPixelFormat *pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs];
NSOpenGLPixelFormat *pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs];
//gl_context_ may be created unproperly, we can check this using the relevant gl_resource_context_
//loop until the created gl_context_ is ok, otherwise the program will crash anyway
while(gl_resource_context_ == nil) {
gl_context_ = [[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:nil];
gl_resource_context_ = [[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:gl_context_];
//gl_context_ may be created unproperly, we can check this using the relevant gl_resource_context_
//loop until the created gl_context_ is ok, otherwise the program will crash anyway
while(gl_resource_context_ == nil) {
gl_context_ = [[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:nil];
gl_resource_context_ = [[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:gl_context_];
if (gl_resource_context_ == nil) {
if (gl_resource_context_ == nil) {
}
}
}

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

正在加载...
取消
保存