iOS Question UIImage: Object was not initialized

luke2012

Well-Known Member
Licensed User
Longtime User
Hi all,
I'm testing the B4i version of my cross-platform app using B4XPages (by @Erel).
The B4X code below runs perfectly in the Android (B4A) version of the app without errors but in the iOS version it crashes with this error: "Object was not initialized (UIImage)".

B4i DEBUGGING
I did 2 checks:
1) Checked through the log that the relative images are correctly initialized before calling the sub "CreateItem"(see log)
2) Check that the image is initialized ("If aImg.IsInitialized Then") before calling the .SetBitmap () function.

Both checks indicate that the ui image (object) in question, is always initialized.
I'm trying to understand why the app crashes with this error. Some idea?

B4X:
Public Sub LoadArtList (ArtContent As B4XOrderedMap)
  
    'ARTICLE LIST CREATION (news listview)
    clvNews.Clear
  
    Private lstArt As List = ArtContent.Values
    lstArt.SortType("CDate", False)
    For i=0 To lstArt.Size-1
        Private AI As ArtItem
        AI = lstArt.Get(i)
        'Private mapArt As Map = ArtContent.Get(ArtNID)
        Private ArtVal As ArtValue
        ArtVal.Initialize
        ArtVal.ArtNID = AI.ArtNID
        ArtVal.ArtTitle = AI.ArtTitle
        ArtVal.ArtBody = AI.ArtBody
        ArtVal.ArtImgID = AI.ArtImgID
        ArtVal.ArtImgTitle = AI.ArtImgTitle
        ArtVal.ArtImgAlt = AI.ArtImgAlt
        ArtVal.ArtImgURL = AI.ArtImgURL
        ArtVal.ArtImg = AI.ArtImg
      
        Private imgID As Int = ArtVal.ArtImgID
        Private img As Bitmap = ArtVal.ArtImg
        Log ("Image ID = " & imgID & " | img.IsInitialized = " & img.IsInitialized)
      
        ArtVal.CDate = AI.CDate     'creation date
        Private pnl As B4XView = CreateItem (ArtVal)
        clvNews.Add (pnl, ArtVal)
    Next

    clvNews.sv.ScrollViewOffsetY = 0
End Sub

Private Sub CreateItem (av As ArtValue) As B4XView  
    Private pnl As B4XView = xui.CreatePanel("")
    pnl.SetLayoutAnimated (0,0,0,100%x, 100%y)
    pnl.LoadLayout("article_itemlayout")
    lblArtTitle.Text = av.ArtTitle
    vwArtBody.LoadHtml(av.ArtBody)
    Private aImg As Bitmap = av.ArtImg
    'Private imgHeight As Int = 100%y-(lblArtTitle.Height + vwArtBody.Height)
    If aImg.IsInitialized Then
          
        'av is a type that contains all item data
        'imgArticle, lblArtTitle are B4XView
        'aImg is a Bitmap
        'vwArtBody is a WebView
     
        '>>> this is the line of code where the error occurs (only this line of code crashes the app, all the rest of the code runs fine):
        imgArticle.SetBitmap(aImg.Resize(pnl.Width, pnl.Height-(lblArtTitle.Height + vwArtBody.Height), False))
      
        lblImgAlt.Enabled = True
        lblImgAlt.Text = av.ArtImgAlt
        lblImgAlt.Visible = True
      
    End If
  
    Return pnl
End Sub

LOG
Image ID = 229 | img.IsInitialized = true
Image ID = 121 | img.IsInitialized = true
Image ID = 122 | img.IsInitialized = true

Thanks in advance for your suggestions (useful also for other developers) :)
Luca.
 
Last edited:

luke2012

Well-Known Member
Licensed User
Longtime User
1. Using %x / %y outside of the resize event is a bug.
2. What is the output of:
B4X:
Dim b As B4XBitmap = pnl.Width, pnl.Height-(lblArtTitle.Height + vwArtBody.Height), False)
Log(b)
imgArticle.SetBitmap(b)

Hi Erel,
first of all thanks for your reply (help).

1) "Using %x / %y outside of the resize event is a bug."
Thanks now I know. Please note that this is my first B4XPages app (so I'm still getting to know the framework gradually).
About this I have a couple of questions (to better understand):

- Is it a bug only within B4i? In the B4A version the app works correctly (normally without UI defects or crashes).
- What is the connection between the error "Object was not initialized (UIImage)" and Using% x /% y outside of the resize event ?

2) "What is the output of:"

B4X:
Dim b As B4XBitmap = pnl.Width, pnl.Height - (lblArtTitle.Height + vwArtBody.Height), False)

Sorry but this line give me an error: "Invalid number of parentheses"
Is it a typo?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
1) It is not related to B4XPages and it is not a bug in B4i. You need to understand how the page resizing works. Watch the B4i / B4J resize event video tutorial: https://www.b4x.com/etp.html
It is likely not related but there is a small chance that the size will be zero. It should be fixed.

2)
Change:
B4X:
Log(pnl.Width & " x " & pnl.Height-(lblArtTitle.Height + vwArtBody.Height))
 
Upvote 0

luke2012

Well-Known Member
Licensed User
Longtime User
1) It is not related to B4XPages and it is not a bug in B4i. You need to understand how the page resizing works. Watch the B4i / B4J resize event video tutorial: https://www.b4x.com/etp.html
It is likely not related but there is a small chance that the size will be zero. It should be fixed.

2)
Change:
B4X:
Log(pnl.Width & " x " & pnl.Height-(lblArtTitle.Height + vwArtBody.Height))

Hi Erel,
thanks for your reply

1) Thanks, I take a look.

2) The result of ....

B4X:
        Dim res As Int = pnl.Height-(lblArtTitle.Height + vwArtBody.Height)
        Log(pnl.Width & " x " & res)

Is: 156 x -90
 
Upvote 0
Top