sourcemars / cocos2d-android-1

Automatically exported from code.google.com/p/cocos2d-android-1
0 stars 0 forks source link

java.lang.OutOfMemoryError: bitmap size exceeds VM budget #26

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
There is no problem with below [Process 1], but [Process 2] is not working.

If I try to perform Process 2, the equipment is shutdown.
I've been doing it many times. But the results were failure because of 
[java.lang.OutOfMemoryError: bitmap size exceeds VM budget]

I can't find out what the difference is between Process 1 and 2.

[Process 1]
1. main.java
CCScene scene = titleLayer.scene();
CCDirector.sharedDirector().runWithScene(scene);

2. titleLayer.java
CCScene scene = puzzleGame.scene();
CCDirector.sharedDirector().replaceScene(scene);

[Process 2]
1. main.java
CCScene scene = titleLayer.scene();
CCDirector.sharedDirector().runWithScene(scene);  

2. titleLayer.java
CCScene scene = puzzleSelLayer.scene();
CCDirector.sharedDirector().replaceScene(scene);  

3. puzzleSelLayer.java
CCScene scene = puzzleGame.scene();
CCDirector.sharedDirector().replaceScene(scene); <=== 
java.lang.OutOfMemoryError: bitmap size exceeds VM budget

12-17 12:49:35.136: DEBUG/CCDirector(6433): cocos2d: cocos2d v0.99.4
12-17 12:49:35.136: DEBUG/CCDirector(6433): cocos2d: Using Director Type:class 
org.cocos2d.nodes.CCDirector
12-17 12:49:35.214: DEBUG/dalvikvm(6433): GC_EXPLICIT freed 8487 objects / 
366984 bytes in 39ms
12-17 12:49:35.261: DEBUG/dalvikvm(6433): GC_EXTERNAL_ALLOC freed 513 objects / 
22656 bytes in 33ms
12-17 12:49:35.503: ERROR/dalvikvm-heap(6433): 2097152-byte external allocation 
too large for this process.
12-17 12:49:35.507: ERROR/GraphicsJNI(6433): VM won't let us allocate 2097152 
bytes
12-17 12:49:35.546: WARN/dalvikvm(6433): threadid=7: thread exiting with 
uncaught exception (group=0x4001d828)
12-17 12:49:35.612: ERROR/AndroidRuntime(6433): FATAL EXCEPTION: GLThread 8
12-17 12:49:35.612: ERROR/AndroidRuntime(6433): java.lang.OutOfMemoryError: 
bitmap size exceeds VM budget
12-17 12:49:35.612: ERROR/AndroidRuntime(6433):     at 
android.graphics.Bitmap.nativeCreate(Native Method)
12-17 12:49:35.612: ERROR/AndroidRuntime(6433):     at 
android.graphics.Bitmap.createBitmap(Bitmap.java:468)
12-17 12:49:35.612: ERROR/AndroidRuntime(6433):     at 
org.cocos2d.opengl.CCTexture2D.<init>(CCTexture2D.java:178)
12-17 12:49:35.612: ERROR/AndroidRuntime(6433):     at 
org.cocos2d.nodes.CCTextureCache.createTextureFromBitmap(CCTextureCache.java:159
)
12-17 12:49:35.612: ERROR/AndroidRuntime(6433):     at 
org.cocos2d.nodes.CCTextureCache.createTextureFromFilePath(CCTextureCache.java:1
51)
12-17 12:49:35.612: ERROR/AndroidRuntime(6433):     at 
org.cocos2d.nodes.CCTextureCache.addImage(CCTextureCache.java:61)
12-17 12:49:35.612: ERROR/AndroidRuntime(6433):     at 
org.cocos2d.nodes.CCSprite.<init>(CCSprite.java:354)
12-17 12:49:35.612: ERROR/AndroidRuntime(6433):     at 
org.cocos2d.nodes.CCSprite.sprite(CCSprite.java:263)
12-17 12:49:35.612: ERROR/AndroidRuntime(6433):     at 
com.mobirix.puzzle.gameLayer.<init>(gameLayer.java:217)
12-17 12:49:35.612: ERROR/AndroidRuntime(6433):     at 
com.mobirix.puzzle.gameLayer.scene(gameLayer.java:47)
12-17 12:49:35.612: ERROR/AndroidRuntime(6433):     at 
com.mobirix.puzzle.puzzleSelLayer.ccTouchesEnded(puzzleSelLayer.java:161)
12-17 12:49:35.612: ERROR/AndroidRuntime(6433):     at 
org.cocos2d.events.CCTouchHandler.ccTouchesEnded(CCTouchHandler.java:75)
12-17 12:49:35.612: ERROR/AndroidRuntime(6433):     at 
org.cocos2d.events.CCTouchDispatcher.touchesEnded(CCTouchDispatcher.java:240)
12-17 12:49:35.612: ERROR/AndroidRuntime(6433):     at 
org.cocos2d.events.CCTouchDispatcher.update(CCTouchDispatcher.java:205)
12-17 12:49:35.612: ERROR/AndroidRuntime(6433):     at 
org.cocos2d.nodes.CCDirector.onDrawFrame(CCDirector.java:657)
12-17 12:49:35.612: ERROR/AndroidRuntime(6433):     at 
android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1332)
12-17 12:49:35.612: ERROR/AndroidRuntime(6433):     at 
android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1116)
12-17 12:49:35.651: WARN/ActivityManager(2448): Process com.mobirix.puzzle has 
crashed too many times: killing!
12-17 12:49:35.651: WARN/ActivityManager(2448):   Force finishing activity 
com.mobirix.puzzle/.Jigsaw2d

Original issue reported on code.google.com by car3...@gmail.com on 17 Dec 2010 at 6:29

GoogleCodeExporter commented 8 years ago
It looks like there are many Bitmaps in memory. They wait to be transformed in 
GL textures. Try to set Max VM heap size in your emulator to higher value.

Original comment by opengen...@gmail.com on 18 Dec 2010 at 1:36

GoogleCodeExporter commented 8 years ago
There is no problem with below [Process 1], but [Process 2] is not working.

[Process1]
Direct call puzzleGame Scene or titleLayer Scene->puzzleGame Scene

[Process2]
titleLayer Scene -> puzzleSelLayer Scene -> puzzleGame Scene

I think that autorelease not working well

Thank you.

Original comment by car3...@gmail.com on 20 Dec 2010 at 5:28

GoogleCodeExporter commented 8 years ago
I woud try explicitly purging the CCTextureCache before loading the second 
scene. I think the bitmaps are still in memory. I have had lots of issues with 
large images and android and garbage collection. Do a google search for large 
images and android.

Original comment by ghemp...@gmail.com on 21 Jan 2011 at 9:45

GoogleCodeExporter commented 8 years ago
On CCTextureCache add bitmap.recycle() method after each bimap usage. It worked 
for me...

Original comment by sbok...@gmail.com on 14 Apr 2011 at 10:50