iOS Question Strange crash with bitmapCreator's getARGB()

JordiCP

Expert
Licensed User
Longtime User
I have an app with many users. Periodically we review crashes with he customer.

There is one which has only appeared a couple of times, but I find it strange and can't understand why.
Perhaps it is quite obvious and someone can see what can go wrong here

From Crashlytics in Firebase Console:
EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000000000003
b4i_bitmapcreator.m - Línea 4720
-[b4i_bitmapcreator _getargb:::] + 4720
...

It happens using bitmapCreator's getARGB() in an utility function used to 'custom tint' several monochrome bitmaps with transparent background from assets.
This Sub is called several times in the code and works with no issues for me (and for most users, otherwise I guess we'd have plenty of crashes)

B4X:
Sub LoadBitmapWithColorAndAlphaFactor(fileName As String, myColor As Int, alphaFactor As Float) As Bitmap

    Dim fc As B4XBitmap = LoadBitmap(File.DirAssets,fileName)

    Dim bmpc As BitmapCreator
    bmpc.Initialize(fc.Width, fc.Height)
    bmpc.CopyPixelsFromBitmap(fc)
    
    Dim myARGB As ARGBColor
    myARGB.Initialize
    myARGB.r = Bit.And(0xFF, Bit.ShiftRight(myColor, 16))
    myARGB.g = Bit.And(0xFF, Bit.ShiftRight(myColor,  8))
    myARGB.b = Bit.And(0xFF, myColor)
    
    Dim ARGB_final As ARGBColor
    ARGB_final.Initialize
    Dim c,r As Int
    For c=0 To fc.Width-1
        For r=0 To fc.Height-1
            Dim ARGB As ARGBColor
            bmpc.GetARGB(c,r,ARGB)                                  ' <-- here is where the crash happens
            If ARGB.a<>0 Then
                ARGB_final.a =   ARGB.a * alphaFactor           
                ARGB_final.r = myARGB.r
                ARGB_final.g = myARGB.g
                ARGB_final.b = myARGB.b
                bmpc.SetARGB(c,r,ARGB_final)
            End If
        Next
    Next
    Return bmpc.Bitmap
    
End Sub
 

JordiCP

Expert
Licensed User
Longtime User
If the image is very small then it might be related to the device scale. Does the crash happen on iPads?
Even if the app can be run on iPads, users install it on their mobile. According to Crashlytics, the crashes have appeared in iPhone 8 Plus, iPhone 15 and iPhone 16 Pro Max.

It is true that some images are quite small (from 256x256 to 48x48 the smallest). Some of them (all .PNGs) were stored as 32bit images, others 24bit and others with 4bit, I guess it is automatically done the by the editor, depending on wether they have ARGB, only RGB or if they are just monochrome with alpha.

I think the internal format shouldn't affect and they are internally loaded as 32-bit ARGB, but it is just my guess and perhaps I'm wrong.
  • Do you think it would make any difference if I force-save the images as 32-bit?
  • Just to understand it better, how does/can the device scale affect the operation?

Thanks
 
Upvote 0
Top