iOS Question B4i xMagnetics class

Andris

Active Member
Licensed User
Longtime User
To calculate magnetic declinations in B4A, I've been successfully using derez's Magnetics Library. In that thread, Erel provided an xMagnetics class in order to do the same thing in B4i and asked that it be tested. I finally tested it in my B4i application and unfortunately it crashed, generating this log message:
B4X:
Application_Start
Application_Active
Error occurred on line: 33 (XMagnetics)
Target is null. Method called: setObjectFastN::
Stack Trace: (
  CoreFoundation       <redacted> + 148
  libobjc.A.dylib      objc_exception_throw + 56
  CoreFoundation       <redacted> + 0
  (myapp)            +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 192
  (myapp)            -[B4IShell runVoidMethod] + 232
  (myapp)            -[B4IShell raiseEventImpl:method:args::] + 1416
  (myapp)            -[B4IShellBI raiseEvent:event:params:] + 1408
  (myapp)            __24-[B4ITimer startTicking]_block_invoke + 332
  libdispatch.dylib    <redacted> + 16
  libdispatch.dylib    <redacted> + 428
 libdispatch.dylib    <redacted> + 1588
 libdispatch.dylib    <redacted> + 720
 CoreFoundation       <redacted> + 12
 CoreFoundation       <redacted> + 2012
 CoreFoundation       CFRunLoopRunSpecific + 436
 GraphicsServices     GSEventRunModal + 100
 UIKit                UIApplicationMain + 236
 (myapp)            main + 124
 libdyld.dylib        <redacted> + 4
)

The crash happens in Line 33 of the class module, when assigning a value to SP(0):
B4X:
Private Sub DoInitialize
    Dim lines As List = File.ReadList(File.DirAssets, "wmmc.cof")
    Dim FirstLine() As String = Regex.Split(",", lines.Get(0))
    EPOCH = FirstLine(0)
    MAXORD = 12
    DTR = cPI / 180
    SP(0) = 0
    CP(0) = 1
    P(0, 0) = 1
    PP(0) = 1
    DP(0, 0) = 0
    ...

Actually, any of the array initializations cause this problem. They are declared as:
B4X:
    Private  C(13, 13) As Double
    Private  CD(13, 13) As Double
    Private  P(13, 13) As Double
    Private  DP(13, 13) As Double
    Private  SNORM(13, 13) As Double
    Private  K(13, 13) As Double
    Private SP(13) As Double
    Private CP(13) As Double
    Private FN(13) As Double
    Private FM(13) As Double
    Private PP(13) As Double

So why would simply assigning values to these arrays cause this kind of a crash?
 
Top