iOS Question AddView throws Object was not initialized (UIView)

CrunkFX

Member
Licensed User
Hey there,

can you tell me what causes this B4A snippet to throw an exception in B4i? Is it just not compatible with XUI? I don´t get it.

Transition Template B4A:
Public Sub PrepareTransition_RadiusIn (Xui As XUI, RootWidth As Float, RootHeight As Float, CurrentPageRoot As B4XView, NewPageRoot As B4XView) As ResumableSub
    Dim pnl As B4XView = Xui.CreatePanel("")
    NewPageRoot.AddView(pnl, 0, 0, RootWidth, RootHeight) '<< stops here
    Dim cnv As B4XCanvas
    cnv.Initialize(pnl)
    Dim frontBmp As B4XBitmap = CurrentPageRoot.Snapshot
    Dim backBmp As B4XBitmap = NewPageRoot.Snapshot
    Dim startingSize As Float = IIf(RootHeight>RootWidth,RootHeight,RootWidth)
    cnv.ClearRect(cnv.TargetRect)
    Dim frames As Int = 22
    Dim stepSize As Float = startingSize/frames
    For i = 0 To frames-1
        cnv.DrawBitmap(backBmp,getRect(0,0,RootWidth,RootHeight))
        Dim path As B4XPath
        path.InitializeOval(getRect((RootWidth/2)-(startingSize)+(stepSize*i),(RootHeight/2)-(startingSize)+(stepSize*i),(startingSize*2)-((stepSize*2)*i) , (startingSize*2)-((stepSize*2)*i)))
        cnv.ClipPath(path)
        cnv.DrawBitmap(frontBmp,getRect(0,0,RootWidth,RootHeight))
        cnv.RemoveClip
        cnv.Invalidate
        Sleep(16)
    Next
    pnl.RemoveViewFromParent
    Return True
End Sub

ERROR:
Application_Start
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
Application_Active
Page with this id already exists: location!
FCMConnected
Application_Pushtoken
Error occurred on line: 57 (B4x_Transition)
Object was not initialized (UIView)
Stack Trace: (
  CoreFoundation       6B22DD81-3585-3BE6-BC77-BA19810EC0F2 + 627356
  libobjc.A.dylib      objc_exception_throw + 60
  CoreFoundation       6B22DD81-3585-3BE6-BC77-BA19810EC0F2 + 983952
  Mein Friseur         -[B4IObjectWrapper object] + 120
  Mein Friseur         -[B4XViewWrapper asPanelWrapper] + 68
  Mein Friseur         -[B4XViewWrapper AddView:::::] + 76
  CoreFoundation       6B22DD81-3585-3BE6-BC77-BA19810EC0F2 + 138020
  CoreFoundation       6B22DD81-3585-3BE6-BC77-BA19810EC0F2 + 259600
  Mein Friseur         +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1400
  Mein Friseur         -[B4IShell runVoidMethod] + 208
 Mein Friseur         -[B4IShell raiseEventImpl:method:args::] + 1608
 Mein Friseur         -[B4IShellBI raiseEvent:event:params:] + 1360
 Mein Friseur         -[B4IDebugResumableSub resume::] + 352
 Mein Friseur         __21-[B4ICommon Sleep:::]_block_invoke + 56
 libdispatch.dylib    E3EA4F63-5D11-342A-AF19-9F58DBC8E259 + 7788
 libdispatch.dylib    E3EA4F63-5D11-342A-AF19-9F58DBC8E259 + 14896
 libdispatch.dylib    E3EA4F63-5D11-342A-AF19-9F58DBC8E259 + 73544
 libdispatch.dylib    _dispatch_main_queue_callback_4CF + 44
 CoreFoundation       6B22DD81-3585-3BE6-BC77-BA19810EC0F2 + 333824
 CoreFoundation       6B22DD81-3585-3BE6-BC77-BA19810EC0F2 + 46852
 CoreFoundation       CFRunLoopRunSpecific + 600
 GraphicsServices     GSEventRunModal + 164
 UIKitCore            137A95AA-DA6D-332C-BC01-E13BB9B6E317 + 5327704
 UIKitCore            UIApplicationMain + 364
 Mein Friseur         main + 104
 dyld                 start + 520
)

Kind regards
CrunkFX
 

CrunkFX

Member
Licensed User
So in order to make i a bit clearer for you here is my full code:

Page with Button calling the function:
Sub Class_Globals
    Public App As Application
    Public Root As B4XView
    Private xui As XUI
    Private Page1 As Page
    Private Safari As SafariController
    Private BGImage As B4XImageView
    Private location_page As Location
End Sub

'You can add more parameters here.
Public Sub Initialize As Object
    B4XPages.GetManager.TransitionAnimationDuration = 400
    InitSafariView
    Return Me
End Sub

Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("Dorsten_View")
    BGImage.Load(File.DirAssets, "xxx.jpg")
    B4XPages.AddPage("Location", location_page.Initialize)
End Sub

Public Sub  Label2_Click
   
    Sleep(0)
    B4x_Transition.PrepareTransition_OpenDoor(xui, Root.Width, Root.Height,Root, location_page.Root)
    B4XPages.ShowPageAndRemovePreviousPages("Location")
    'B4XPages.ShowPage("Location")
End Sub

Page to be called:
Sub Class_Globals
    Public Root As B4XView
    Private xui As XUI
    Private B4XImageView1 As B4XImageView
End Sub

'You can add more parameters here.
Public Sub Initialize As Object
    Return Me
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    'Root = Root1
    Root.LoadLayout("Location")
    B4XImageView1.Load(File.DirAssets, "xxx.jpg")
End Sub

Private Sub Dortmund_Btn_Click
    B4XPages.ShowPage("Dortmund")
End Sub

Public Sub loadpageinadvance
    'we call this sub to reload data here and make the transition with the correct loading layout
    Root.Color = xui.Color_RGB(Rnd(0,255),Rnd(0,255),Rnd(0,255))
    '...
End Sub

The Transition itself:
Public Sub PrepareTransition_OpenDoor (Xui As XUI, RootWidth As Float, RootHeight As Float, CurrentPageRoot As B4XView, NewPageRoot As B4XView) As ResumableSub
    Dim pnl As B4XView = Xui.CreatePanel("")
    NewPageRoot.AddView(pnl, 0, 0, RootWidth, RootHeight)
    Dim cnv As B4XCanvas
    cnv.Initialize(pnl)
    Dim leftDoor As B4XBitmap = CurrentPageRoot.Snapshot.Crop(0,0,RootWidth/2, RootHeight)
    Dim rightDoor As B4XBitmap = CurrentPageRoot.Snapshot.Crop(RootWidth/2,0,RootWidth/2, RootHeight)
    Dim backBmp As B4XBitmap = NewPageRoot.Snapshot
    cnv.ClearRect(cnv.TargetRect)
    Dim frames As Int = 14
    Dim stepWidth As Float = (RootWidth/2)/frames
    For i = 0 To frames-1
        cnv.DrawBitmap(backBmp,getRect(0,0,RootWidth,RootHeight))
        cnv.DrawBitmap(leftDoor,getRect(-(i*stepWidth),0,RootWidth/2,RootHeight))
        cnv.DrawBitmap(rightDoor,getRect((RootWidth/2)+(i*stepWidth),0,RootWidth/2,RootHeight))
        cnv.Invalidate
        Sleep(16)
    Next
    pnl.RemoveViewFromParent
    Return True
End Sub

I have no idea why this is working in B4A but not in B4i?
 
Upvote 0

CrunkFX

Member
Licensed User
Please upload a small project with this code.
Whilst creating a small demo project in B4A and B4i i figured out that this might be some sort of timing issue.

When i try to set this in the remote class before navigating to it, it throws an error on either B4A and B4i:
B4X:
Root.Color = xui.Color_RGB(Rnd(0,255),Rnd(0,255),Rnd(0,255))

if i put this before calling the function
B4X:
sleep(0)
or changing the function to:
B4X:
B4XPages.GetPage("mainpage").As(B4XMainPage).Root.Color = xui.Color_RGB(Rnd(0,255),Rnd(0,255),Rnd(0,255))

it works fine.

What is causing this as the Page is already initialized once the other page is beeing created?
 
Upvote 0
Top