0

I have been writing an android game, and I finally got everything done, and it ran perfectly fine on the emulator and on my phone, which is a rooted droid, but when I put in the marketplace I began getting reports of it force closing, I had my parents put it on their phone and it force closed when they tried to click the start button in the on screen menu, but my friends died when he tried to reopen it after playing it. I have his logcat, but I am not sure about my parents stuff yet. Here it is

07-18 23:58:32.457: ERROR/AndroidRuntime(25513): FATAL EXCEPTION: main
07-18 23:58:32.457: ERROR/AndroidRuntime(25513): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
07-18 23:58:32.457: ERROR/AndroidRuntime(25513):     at android.graphics.Bitmap.nativeCreate(Native Method)
07-18 23:58:32.457: ERROR/AndroidRuntime(25513):     at android.graphics.Bitmap.createBitmap(Bitmap.java:468)
07-18 23:58:32.457: ERROR/AndroidRuntime(25513):     at android.graphics.Bitmap.createBitmap(Bitmap.java:435)
07-18 23:58:32.457: ERROR/AndroidRuntime(25513):     at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:340)
07-18 23:58:32.457: ERROR/AndroidRuntime(25513):     at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:488)
07-18 23:58:32.457: ERROR/AndroidRuntime(25513):     at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:462)
07-18 23:58:32.457: ERROR/AndroidRuntime(25513):     at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:323)
07-18 23:58:32.457: ERROR/AndroidRuntime(25513):     at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:346)
07-18 23:58:32.457: ERROR/AndroidRuntime(25513):     at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:372)
07-18 23:58:32.457: ERROR/AndroidRuntime(25513):     at com.Waldev.cannontrial.CannonBlast$panel.<init>(CannonBlast.java:136)
07-18 23:58:32.457: ERROR/AndroidRuntime(25513):     at com.Waldev.cannontrial.CannonBlast.onCreate(CannonBlast.java:41)
07-18 23:58:32.457: ERROR/AndroidRuntime(25513):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-18 23:58:32.457: ERROR/AndroidRuntime(25513):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
07-18 23:58:32.457: ERROR/AndroidRuntime(25513):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
07-18 23:58:32.457: ERROR/AndroidRuntime(25513):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
07-18 23:58:32.457: ERROR/AndroidRuntime(25513):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
07-18 23:58:32.457: ERROR/AndroidRuntime(25513):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-18 23:58:32.457: ERROR/AndroidRuntime(25513):     at android.os.Looper.loop(Looper.java:123)
07-18 23:58:32.457: ERROR/AndroidRuntime(25513):     at android.app.ActivityThread.main(ActivityThread.java:4627)
07-18 23:58:32.457: ERROR/AndroidRuntime(25513):     at java.lang.reflect.Method.invokeNative(Native Method)
07-18 23:58:32.457: ERROR/AndroidRuntime(25513):     at java.lang.reflect.Method.invoke(Method.java:521)
07-18 23:58:32.457: ERROR/AndroidRuntime(25513):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-18 23:58:32.457: ERROR/AndroidRuntime(25513):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-18 23:58:32.457: ERROR/AndroidRuntime(25513):     at dalvik.system.NativeStart.main(Native Method)
07-18 23:58:32.487: WARN/ActivityManager(85):   Force finishing activity com.Waldev.cannontrial/.CannonBlast

I am not sure why it would do this, I thought that I had closed out the game cleanly, but thats not even the issue because my parents can't even get the game to open. Is there something that might have caused this to happen that is common? I added a few things to the manifest like finishOnTaskLaunch and stuff like that, but nothing seems to remedy the situation. Any ideas? And do you need anything else to see what might be going on, I will be around trying to fix this until it gets done, so I will comment pretty quickly. Thanks in advance

Vivin Paliath
  • 94,126
  • 40
  • 223
  • 295
William
  • 21
  • 1
  • 4
  • possible duplicate of [java.lang.OutOfMemoryError: bitmap size exceeds VM budget - android](http://stackoverflow.com/questions/1949066/java-lang-outofmemoryerror-bitmap-size-exceeds-vm-budget-android) – Vivin Paliath Jul 19 '10 at 23:16

2 Answers2

0

Try this stackoverflow question:

java.lang.OutOfMemoryError: bitmap size exceeds VM budget - Android

Your question is likely to be closed by the way, because it's a duplicate. But the question and solution I linked to should help you out.

Community
  • 1
  • 1
Vivin Paliath
  • 94,126
  • 40
  • 223
  • 295
  • That link doesn't explain why it would stop while in game as it does on droids, it won't do anything except display a few bitmaps and then it dies :/ – William Jul 19 '10 at 23:25
0

It depends on the way you're loading and managing your bitmaps. (For example, are you sure you're not reloading bitmaps during every onDraw() call?)

You can also reduce the amount of memory your bitmaps take up by increasing the sample size during loading:

Context c = myActivity; // Some activity
BitmapFactory.Options options = new BitmapFactory.Options();

// 4 here means your resulting bitmap will be 1/4 width and height => 1/16 size
options.inSampleSize = 4; // Powers of 2 are better

BitmapFactory.decodeResource(c.getResources(), R.drawable.sample_bitmap, options);
Andy Zhang
  • 8,285
  • 1
  • 37
  • 24
  • I use scaledBitmap on most of my bitmaps, is that not the same thing? – William Jul 19 '10 at 23:45
  • Hmm.. I'm gonna assume inSampleSize literally reads in less data, while scaledBitmap only scales it during rendering, retaining 100% of the data. I could be wrong though. Another note after some testing: increasing inSampleSize does physically reduce your resulting bitmap's dimensions, so you'll have to scale it to its target size. – Andy Zhang Jul 19 '10 at 23:56
  • okay, thanks, I will try that, but is there any reason you can think of that it would just die when reentering on some phones and die when just trying to start the game in others? I wouldn't think there was that big of a memory difference between the droid and the nexus – William Jul 20 '10 at 00:05
  • I can't think of any clear reason why it'd crash so differently on two different phones, sorry! You can also try allocating temporary storage in the options: http://www.memofy.com/memofy/show/1008ab7f2836ab7f01071c2dbfe138/outofmemory-exception-when-decoding-with-bitmapfactory – Andy Zhang Jul 20 '10 at 00:18
  • Hrmmmm, alright, thanks, it just feels weird that a program thats less than 1/2 a mb is killing phones lol, I am going through some open source stuff to see if there is anything major that I might have missed – William Jul 20 '10 at 00:27