iOS Question QRCode Generator Error

Chris Guanzon

Active Member
Licensed User
Longtime User
Hello, I have an error in creating a qr code using B4X QRCode Generator.

Here's the error

B4X:
Class (b4i_bcpath) instance released.
Class (b4i_bcpath) instance released.
Class (b4i_bcpath) instance released.
b83c0c3d318ccf473eef9e94c8c166835590adc829595e96e6957b8596cf61b2
4L, Size: 64
Error occurred on line: 121 (QRGenerator)
Object was not initialized (UIImage)
Stack Trace: (
  CoreFoundation       <redacted> + 252
  libobjc.A.dylib      objc_exception_throw + 56
  CoreFoundation       <redacted> + 0
  All Access Mobile    -[B4IObjectWrapper object] + 144
  All Access Mobile    -[B4XCanvas CreateBitmap] + 56
  All Access Mobile    -[b4i_qrgenerator _create::] + 8752
  All Access Mobile    -[ResumableSub_dashboard_GenerateQRCode resume::] + 780
  All Access Mobile    -[b4i_dashboard _generateqrcode] + 356
  All Access Mobile    -[ResumableSub_dashboard_SetGUI_Tab2 resume::] + 1264
  All Access Mobile    -[b4i_dashboard _setgui_tab2] + 356
All Access Mobile    -[ResumableSub_dashboard_Show resume::] + 3972
CoreFoundation       <redacted> + 144
CoreFoundation       <redacted> + 292
All Access Mobile    +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1528
All Access Mobile    -[B4IShell runMethod:] + 448
All Access Mobile    -[B4IShell raiseEventImpl:method:args::] + 2172
All Access Mobile    -[B4IShellBI raiseEvent:event:params:] + 1580
All Access Mobile    -[B4IDelegatableResumableSub resume::] + 380
All Access Mobile    -[B4I checkAndRunWaitForEvent:event:params:] + 484
All Access Mobile    -[B4IShellBI raiseEvent:event:params:] + 1436
All Access Mobile    __37-[B4ICommon ReturnFromResumableSub::]_block_invoke + 316
libdispatch.dylib    <redacted> + 24
libdispatch.dylib    <redacted> + 16
libdispatch.dylib    <redacted> + 1068
CoreFoundation       <redacted> + 12
CoreFoundation       <redacted> + 1924
CoreFoundation       CFRunLoopRunSpecific + 436
GraphicsServices     GSEventRunModal + 104
UIKitCore            UIApplicationMain + 212
All Access Mobile    main + 128
libdyld.dylib        <redacted> + 4
)
Class (b4i_b4xbytesbuilder) instance released.

The error occurs here On line 59

B4X:
Public Sub Create(Text As String) As B4XBitmap
    Dim Bytes() As Byte = Text.GetBytes("utf8") 'non-standard but still recommended
    Dim vd As QRVersionData
    For Each version As QRVersionData In versions
        If version.MaxUsableSize >= Bytes.Length Then
            vd = version
            Exit
        End If
    Next
    If vd.IsInitialized = False Then
      
        Log("Too long!")
        Return Null
    End If
    Log(vd.VersionName & ", Size: " & Bytes.Length)
  
    NumberOfModules = 17 + vd.Version * 4
    ModuleSize = mBitmapSize / (NumberOfModules + 8)
  
    mBitmapSize = ModuleSize * (NumberOfModules + 8)
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, mBitmapSize, mBitmapSize)
    cvs.Initialize(p)
  
    Dim Matrix(NumberOfModules, NumberOfModules) As Boolean
    Dim Reserved(NumberOfModules, NumberOfModules) As Boolean
  
    Dim Mode() As Byte = Array As Byte(0, 1, 0, 0) 'byte mode
    Dim ContentCountIndicator() As Byte
    If vd.Version >= 10 Then
        ContentCountIndicator = IntTo16Bits(Bytes.Length)
    Else
        ContentCountIndicator = UnsignedByteToBits(Bytes.Length)
    End If
    Dim EncodedData As B4XBytesBuilder
    EncodedData.Initialize
    EncodedData.Append(Mode)
    EncodedData.Append(ContentCountIndicator)
    For Each b As Byte In Bytes
        EncodedData.Append(UnsignedByteToBits(Bit.And(0xff, b)))
    Next
    'add terminator
    Dim PadSize As Int = Min(4, vd.MaxSize - EncodedData.Length)
    Dim pad(PadSize) As Byte
    EncodedData.Append(pad)
    Do While EncodedData.Length Mod 8 <> 0
        EncodedData.Append(Array As Byte(0))
    Loop
  
    Do While EncodedData.Length < vd.MaxSize
        EncodedData.Append(Array As Byte(1,1,1,0,1,1,0,0))
        If EncodedData.Length < vd.MaxSize Then EncodedData.Append(Array As Byte(0,0,0,1,0,0,0,1))
    Loop
    VersionWithTwoGroups(vd.Generator, vd.Group1Size, vd.Group2Size, vd.Block1Size, vd.Block2Size, EncodedData)
    AddFinders (vd)
    AddDataToMatrix(EncodedData.ToArray, vd)
    DrawMatrix
    cvs.Invalidate
    Dim bmp As B4XBitmap = cvs.CreateBitmap '// Error occurred here
    cvs.Release
    Return bmp
End Sub

Dim bmp As B4XBitmap = cvs.CreateBitmap '// Error occurred here

Anyone knows how to fix this?
 

Chris Guanzon

Active Member
Licensed User
Longtime User
Have you initialized the QRGenerator class?

yes,

B4X:
Sub GenerateQRCode As ResumableSub
    Libraries.qrcode.Initialize(imgQRCode.Width)
    bmpQR = Libraries.QRCode.Create(API.account_identifier)
    icon = Libraries.xui.LoadBitmapResize(File.DirAssets, "qr_icon.png", 100dip, 100dip, True)
    'ImageView1.SetBitmap(AddSomeColors(bmpQR, icon).Resize(ImageView1.Width, ImageView1.Height, True))
    imgQRCode.SetBitmap(Libraries.qrcode.AddBitmap(bmpQR, icon, 190).Resize(imgQRCode.Width, imgQRCode.Height, True))
    Return True
End Sub
 
Upvote 0

Chris Guanzon

Active Member
Licensed User
Longtime User
Maybe it is too small. Try to reproduce it in a small project and upload it.

In this sample, it is working fine. but in my project it's not. The code in this sample is also the same in my project for generating QR Code
 

Attachments

  • sample1.zip
    180.1 KB · Views: 154
Upvote 0
Top