Вопрос

I have a MainMenuScene and a GameScene...

In the MainMenu I have the button start that goes to the GameScene, in the middle of the game I want to restart or just quit the game, which ever of those 2 that I do, when I replace the GameScene with another GameScene or just go back to the mainmenu and then back to a new GameScene again, the FPS starts dropping and dropping, if I do that cycle 1 time the FPS drops from 60 to 30, if I do it once again the FPS drops to 15, and so on and so on...

I believed that the problem was the memory leak because I left the scene alive... but its not I have checked and checked, and there is no strong reference to that scene anywhere, and also its ARC enabled, I checked with Instruments profile and nothing there is no memory leak according to instruments from Xcode.

Has anyone has had this issue... or anyone has any idea what might I be doing wrong? according to what I have read in ReplaceScene method from CCDirector that scene is destroyed and replaced with the new one, so there shouldn't be a problem.

== Forgot to mention: I have a weak reference of the GameLayer and the GameScene in a Singleton, However when I replace the scene, immediately after that I set those 2 nil, even though I shouldn't because they are weak reference but I do it just in case.

Adding Image for more context: Dealloc Debug

With the image above you can see that every time that ReplaceScene from CCDirector is called, the scenes, specifically the GameScenes, are getting deallocated. So memory leaks its not the problem, but it seems like the scenes are not getting destroyed, or thats my thinking, because the FPS just keeps dropping and dropping everytime.

1st GameScene scene will be replaced with Main Menu

MainMenuScene After ReplaceScene from GameScene

2nd GameScene Scene Replaced from MainMenuScene

2nd MainMenuScene after ReplaceScene from GameScene ... Few replacescenes later...

7th GameScene scene replaced from MainMenuScene

The strange thing here is that the MainMenu is not being affected AT ALL, the rendering time is the same... the draw calls are the same(that is understandable, even in the GameScene the drawCalls stay the same.) but in the GameScene the FPS keeps dropping, and the Rendering time is becoming HUGE, which is why the game becomes incredibly slow.

Will keep checking.

Это было полезно?

Решение

The solution was very simple... everything gets deallocated correctly except for a batchnode, a specific batchnode that was handling the background was killing my apps performance.

So for anyone out there, please remember to check your CCBatchNodes and any other strong references are connected to the scene when the moment of replacing the scene. The deallocation occurs almost immediately, but it helps to set to nil child objects of the parent object being deallocated. But in my case the SpriteBatchnode was the one affecting heavily my FPS, rendering time performance.

Thanks LearnCocos2D your help is greatly appreciated.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top