Closed b0ktai closed 13 years ago
yes, it is a bug, and we have to save bmp without recycling it to restore when the app is back and we have to load everything for it.
Thanks, Weikuan Zhou
2011/4/12 b0ktai < reply@reply.github.com>
I had been banging my head to the wall with this error when loading multiple sprites. I solved it by recycling the bitmap after it was used:
bmp.recycle(); bmp = null; is = null;
The modified function was the following, in CCTextureCache class:
private static CCTexture2D createTextureFromFilePath(final String path) {
final CCTexture2D tex = new CCTexture2D(); tex.setLoader(new GLResourceHelper.GLResourceLoader() { public void load() { try { InputStream is =
CCDirector.sharedDirector().getActivity().getAssets().open(path); Bitmap bmp = BitmapFactory.decodeStream(is); is.close(); tex.initWithImage(bmp); bmp.recycle(); bmp = null; is = null; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } });
return tex;
}
Can you confirm this bug, or if there is another workaround I am not aware off.
This error seems to happen because GC doesnt free memory at the needed rate...
Reply to this email directly or view it on GitHub: https://github.com/ZhouWeikuan/cocos2d/issues/5
recycle is called in loadTexture method of CCTexture2D now.
I may be confusing something here, but I don't understand the load thing. If the load you're mentioning is the onStart() event of the activity, then there is no need to load the layer again. If the activity enters an onStop() state there is no need to call CCDirector.sharedDirector().end(); so when the activity comes back up there's no need to load anything again...
In my understanding I only call CCDirector.sharedDirector().end(); at the onDestroy event and nowhere else...
Sorry didn't see you're last post.
Thank you.
I had been banging my head to the wall with this error when loading multiple sprites. I solved it by recycling the bitmap after it was used:
bmp.recycle(); bmp = null; is = null;
The modified function was the following, in CCTextureCache class:
private static CCTexture2D createTextureFromFilePath(final String path) {
Can you confirm this bug, or if there is another workaround I am not aware off.
This error seems to happen because GC doesn´t free memory at the needed rate...