【问题标题】:iOS memory warning breaking EAGLViewiOS 内存警告破坏 EAGLView
【发布时间】:2011-10-03 05:38:15
【问题描述】:

当我收到 1 级内存警告时,我的 EAGLView 开始吐出几行 openGL 错误(502 和 506),并且应用程序没有崩溃,但 EAGLView 变得无响应。由于 Cocos2d Director 调用 draw,错误正在发送。

这是内存警告回调的样子:

- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
    [[CCDirector sharedDirector] purgeCachedData];
}
  1. 502 和 506 错误是什么意思,以及 2. 内存警告是否会对 opengl 视图产生任何影响,或者它是否会在我的代码中释放不应该出现的内容?

[更新]

设法从 cocos2d 中得到一些详细的日志:

Received memory warning. Level=1
cocos2d: deallocing <CCSprite = 002657B0 | Rect = (0.00,0.00,32.00,32.00) | tag = -1 | atlasIndex = -1>
cocos2d: deallocing <CCTexture2D = 00265EA0 | Name = 4 | Dimensions = 32x32 | Coordinates = (1.00, 1.00)>
cocos2d: deallocing <CCSprite = 00265A70 | Rect = (0.00,0.00,32.00,32.00) | tag = -1 | atlasIndex = -1>
cocos2d: deallocing <CCSprite = 00266050 | Rect = (0.00,0.00,32.00,32.00) | tag = -1 | atlasIndex = -1>
cocos2d: deallocing <LineNode = 0027A630 | Tag = -1>
cocos2d: deallocing <LineNode = 0027AB90 | Tag = -1>
cocos2d: deallocing <LineNode = 0027AF50 | Tag = -1>
cocos2d: deallocing <LineNode = 0027B270 | Tag = -1>
cocos2d: deallocing <LineNode = 00204820 | Tag = -1>
cocos2d: deallocing <PaintingView = 00264970 | Tag = -1>
cocos2d: deallocing <TutorialView = 00266570 | Tag = -1>
cocos2d: deallocing <CCRenderTexture = 00266660 | Tag = -1>
cocos2d: deallocing <CCTexture2D = 00266750 | Name = 5 | Dimensions = 1024x1024 | Coordinates = (1.00, 0.75)>
cocos2d: deallocing <CCSprite = 00266960 | Rect = (0.00,0.00,1024.00,768.00) | tag = -1 | atlasIndex = -1>
cocos2d: deallocing <EAGLView: 0x24aee0; frame = (0 0; 1024 768); transform = [0, -1, 1, 0, 0, 0]; autoresize = RM+BM; layer = <CAEAGLLayer: 0x2492c0>>
cocos2d: deallocing <ES1Renderer = 0024D0E0 | size = 768x1024>
modifying layer that is being finalized - 0x2fab80

所以这几乎就是一切。看起来除了场景节点之外的所有东西都在消失。

【问题讨论】:

    标签: ios memory-management opengl-es cocos2d-iphone eaglview


    【解决方案1】:

    至于 OpenGL 错误是什么意思,您可以参考您的 OpenGL 标头,它会告诉您 502 是 GL_INVALID_OPERATION 而 506 是 GL_INVALID_FRAMEBUFFER_OPERATION

    我从您的问题或提供的代码中看不到任何内容,但我假设您正在过早释放帧缓冲区(您可能不应该在运行时这样做),或者 Cocos2D 在您调用时释放帧缓冲区purgeCachedData(我有点怀疑后者)并且未能完全重新创建它(如果有的话)。您可能需要检查 EAGLView 的实现,并查看它是否已设置为在需要时处理重新创建帧缓冲区(并查看您是否在某个地方不必要地释放了帧缓冲区)。

    也就是说,如果您收到内存警告,您可能还需要解决这些问题的根源。

    【讨论】:

    • 我刚刚发现 cocos 正在释放我正在使用的几乎所有东西,包括 EAGLView
    • 那是一些相当顽固的清除。 O_o
    • 是否有某种特定的方式我应该卸载 EAGLView 以便 OpenGL 不再使用它?
    • 好吧,你为什么要卸载EAGLView?这是一个小物件,并没有多大意义。如果您的应用程序进入后台,您可以关闭帧缓冲区,但快速启动所需的所有其他内容可能会一直保留到应用程序结束。就此而言,为什么 Cocos2D 仍在尝试绘制不应该绘制的东西?您是否忽略了结束动画/循环/您要渲染什么?
    • 发生的事情是包含 GLview 并被推送并加载视图并启动导向器的视图控制器,然后当它被卸载(返回导航堆栈)时,EAGLView 被卸载并且导向器停止。当我回到它时,有时它会触发内存警告,上面的内容被释放并导致 opengl 中的错误。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-12-24
    • 1970-01-01
    • 2012-02-20
    • 2015-03-30
    • 2012-06-20
    相关资源
    最近更新 更多