iOS 内存警告破坏 EAGLView
当我收到 1 级内存警告时,我的 EAGLView 开始吐出 OpenGL 错误行(502 和 506),并且应用程序不会崩溃,但 EAGLView 变得无响应。这些错误是由于 Cocos2d Director 调用draw而发出的。
这就是内存警告回调的样子:
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
[[CCDirector sharedDirector] purgeCachedData];
}
- 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
这就是几乎所有内容。看起来除了场景节点之外的所有内容都消失了。
When I get a memory warning level-1 my EAGLView starts spitting out lines of openGL errors (502 & 506) and the app doesn't crash but the EAGLView becomes unresponsive. the errors are spamming out because of the Cocos2d Director calling draw.
This is how the memory warning callback looks:
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
[[CCDirector sharedDirector] purgeCachedData];
}
- What do the 502 and 506 errors mean, and 2. should there be any effect on the opengl view from memory warnings or is it releasing something it shouldn't in my code?
[Update]
managed to get some verbose logs out of 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
So that's pretty much everything. looks like everything except the scene node is disappearing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
至于OpenGL错误是什么意思,你可以参考你的OpenGL标头,它会告诉你502是
GL_INVALID_OPERATION
,506是GL_INVALID_FRAMEBUFFER_OPERATION
。我从你的问题或提供的代码中看不到任何内容,但我假设你要么过早地释放你的帧缓冲区(你可能不应该在运行时这样做),要么Cocos2D在你调用
时释放你的帧缓冲区purgeCachedData
(后者我有点怀疑)并且无法完全重新创建它(如果有的话)。您可能需要检查 EAGLView 的实现,看看它是否设置为在需要时处理重新创建帧缓冲区(并查看是否在某些地方不必要地释放了帧缓冲区)。也就是说,如果您收到内存警告,您可能还想解决这些警告的来源。
As for what the OpenGL errors mean, you can refer to your OpenGL headers, which would tell you that 502 is
GL_INVALID_OPERATION
and 506 isGL_INVALID_FRAMEBUFFER_OPERATION
.I can't see anything from your question or provided code, but I'm assuming that either you are releasing your framebuffer prematurely (which you probably shouldn't do at runtime), or Cocos2D is releasing your framebuffer when you call
purgeCachedData
(the latter of which I'm sort of doubtful of) and failing to recreate it completely (if at all). You may want to check your implementation ofEAGLView
and see if it's set up to handle recreating the framebuffer when needed (and see if there's somewhere that you're releasing the framebuffer unnecessarily).That said, if you're getting memory warnings, you might want to address the source of those as well.