Android Question BBCodeView and OutOfMemoryError crash from the console

giggetto71

Active Member
Licensed User
Longtime User
Hi Guys,
I have an app where I use BBCodeView lib to display the app help. the .text contains text and few, about 15, pgn (very small files, few Kb, max 100Kb).
On few devices I get some crashes from the google play console which seems indicating some issues with loading some pictures. Here attached an extract of the crash log.


java.lang.OutOfMemoryError:
at dalvik.system.VMRuntime.newNonMovableArray (Native Method)
at android.graphics.Bitmap.nativeCreate (Native Method)
at android.graphics.Bitmap.createBitmap (Bitmap.java:939)
at android.graphics.Bitmap.createBitmap (Bitmap.java:912)
at android.graphics.Bitmap.createBitmap (Bitmap.java:843)
at android.graphics.Bitmap.createScaledBitmap (Bitmap.java:719)
at anywheresoftware.b4a.objects.drawable.CanvasWrapper$BitmapWrapper.Resize (CanvasWrapper.java:568)
at anywheresoftware.b4a.objects.drawable.CanvasWrapper$BitmapWrapper.InitializeResize (CanvasWrapper.java:549)
at anywheresoftware.b4a.keywords.Common.LoadBitmapResize (Common.java:1370)
at anywheresoftware.b4a.objects.B4XViewWrapper$XUI.LoadBitmapResize (B4XViewWrapper.java:713)
at gigiosoft.MQTTAlert.bbcodeparser$ResumableSub_SetImageView.resume (bbcodeparser.java:737)
at gigiosoft.MQTTAlert.bbcodeparser._setimageview (bbcodeparser.java:561)
at gigiosoft.MQTTAlert.bbcodeparser._texttorun (bbcodeparser.java:905)
at gigiosoft.MQTTAlert.bbcodeparser._createruns (bbcodeparser.java:148)
at gigiosoft.MQTTAlert.bbcodeview._parseanddraw (bbcodeview.java:490)
at gigiosoft.MQTTAlert.bbcodeview._settext (bbcodeview.java:558)
at gigiosoft.MQTTAlert.main._setwizard (main.java:17101)
at gigiosoft.MQTTAlert.main._activity_create (main.java:1962)
............................

the code is already within a Try/Catch but for some reasons it does not get caught.
I have checked and I am not using the latest BCTextEngine as I am using 1.87. Can that be something fixed with 1.88 or 1.89? Anything I could try to identify what is causing this out of memory and understand why it affects only some devices?
thanks!



B4X:
Try
    BBCodeView1.ParseData.DefaultFont = xui.CreateDefaultFont(20/access.GetUserFontScale)
    '[Alignment=Center][TextSize=20][b]Title[/b][/TextSize][/Alignment]
    
    BBCodeView1.Text = _
$"
xxxxxxxxxxx xkxlkj j j lkj lkj lj lòkj lj lkj l klj lkjk. 
You can configure bla bla a [b]local[/b] or a [b]cloud[/b] bla bla.bla bla
[img FileName="image_1.png" width=340 height=240/]
this APP bla blah xxxxxxx
[img FileName="image_2.png" width=340 height=240/]
Configuration is xxxxxxx"$

Catch
   Log(LastException)
End Try
 

agraham

Expert
Licensed User
Longtime User
the code is already within a Try/Catch but for some reasons it does not get caught.
You can't catch out of memory errors as your stack is already blown. It's not the size of the files but the size of the resultant bitmaps that matter. I guess you are trying to use too many too large bitmaps. Some devices with less memory can't cope.
 
Upvote 0

giggetto71

Active Member
Licensed User
Longtime User
You can't catch out of memory errors as your stack is already blown. It's not the size of the files but the size of the resultant bitmaps that matter. I guess you are trying to use too many too large bitmaps. Some devices with less memory can't cope.
Thanks. I have double checked the total size of the 15 png files I load and that is 310Kb. the text size is around 7000 chars. To me it does not look huge but I don't have much experience with BBCodeView so I may be wrong. Should I try to use less? Smaller?

Have you enabled lazy loading in the designer properties?

No..Shame on me I did not know about this setting. I will make a try. thanks for the suggestion.
 
Upvote 0

giggetto71

Active Member
Licensed User
Longtime User
ok double checked. the parameter "Lazy Loading" was already checked in the Designer.
anything else I could check?
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
anything else I could check?
Based on Andrew's statement, it is the size of the bitmaps they expand to that matters. Did you try:
width=34 height=24 instead of width=340 height=240 to see if it makes a difference, then gradually increase them. I thought an image with 340x240 pixels has a file size of close to 320 KB. and you have 15 of them.
 
Upvote 0
Top