iOS Question [__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[2]

Rory Mapstone

Member
Licensed User
Longtime User
Hi,

I recently upgraded to b4i v2.51.
But now I get the above mentioned error when in debug mode. But when I step the code, all is well.
This does not happen every time. If i removed all breakpoints, cleaned the project or re-install the app, i might not get the error for a couple of runs.

Any ideas on what might be causing this?

Kind Regards
 

Rory Mapstone

Member
Licensed User
Longtime User
Hi,
It happens at random places. eg something as simple as adding something to the customlistview -> clv.add(...)
or in the case below, returning a value from a function

B4X:
Sub SQL_GetCFG_Value (Key As String, Default As String) As String
    Dim Result As String = SQL_GetConnection.ExecQuerySingleResult(Global.StringFormat ("SELECT CFG_VALUE FROM CFG WHERE CFG_CODE='{0}'", Array As Object (Key)))
    If (Result = Null) Or (Result = "") Then Result = Default
    Return Result
End Sub

Application_Start
Authorized
Two-stage rotation animation is deprecated. This application should use the smoother single-stage animation.
Two-stage rotation animation is deprecated. This application should use the smoother single-stage animation.
Error occurred on line: 131 (Database)
*** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[2]
Stack Trace: (
CoreFoundation <redacted> + 154
libobjc.A.dylib objc_exception_throw + 38
CoreFoundation <redacted> + 418
CoreFoundation <redacted> + 44
My Tribez Test -[b4i_mytribez_api _set_push_account:::::::] + 510
My Tribez Test -[b4i_mytribez_api _setdevicetoken] + 1756
CoreFoundation <redacted> + 68
CoreFoundation <redacted> + 282
My Tribez Test +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1786
My Tribez Test -[B4IShell runMethod:] + 574
My Tribez Test -[B4IShell raiseEventImpl:method:args::] + 2212
My Tribez Test -[B4IShellBI raiseEvent:event:params:] + 1442
My Tribez Test +[B4IDebug delegate:::] + 52
My Tribez Test -[b4i_mytribez_api _setdevicetoken] + 342
My Tribez Test -[b4i_main _application_start:] + 11752
CoreFoundation <redacted> + 68
CoreFoundation <redacted> + 282
My Tribez Test +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1786
My Tribez Test -[B4IShell runMethod:] + 574
My Tribez Test -[B4IShell raiseEventImpl:method:args::] + 2212
My Tribez Test -[B4IShellBI raiseEvent:event:params:] + 1442
My Tribez Test __33-[B4I raiseUIEvent:event:params:]_block_invoke + 74
libdispatch.dylib <redacted> + 10
libdispatch.dylib <redacted> + 22
libdispatch.dylib <redacted> + 278
CoreFoundation <redacted> + 8
CoreFoundation <redacted> + 1300
CoreFoundation CFRunLoopRunSpecific + 522
CoreFoundation CFRunLoopRunInMode + 106
GraphicsServices GSEventRunModal + 138
UIKit UIApplicationMain + 1136
My Tribez Test main + 108
libdyld.dylib <redacted> + 2
)
Application_Active
 
Upvote 0

Rory Mapstone

Member
Licensed User
Longtime User
Thank you, but the fact is that it happens all over. But i remove all breakpoints, it works fine. Or if i have breakpoints and i step into each line. if i were to run from a breakpoint, it would crash again.
 
Upvote 0

iCAB

Well-Known Member
Licensed User
Longtime User
Same thing happens to me all the time after inserting break point in specific places
 
Upvote 0

iCAB

Well-Known Member
Licensed User
Longtime User
Here is what I found out:

1. I have a function call that expects several parameters ( call it func1 )
2. one of the parameters is: CheckedItems() As Boolean
3. in some cases I pass Null (on purpose) for CheckedItems
4. func1 calls another function func2 and passes CheckedItems as is ( Sometimes the crash is on this line )
5. func2 calls another function func3 and passes CheckedItems as is ( other times the crash is on this line )
5. inside func3 we check: If CheckedItems <> Null Then, then we use the values from CheckedItems, otherwise we ignore the array

the error message I am getting is:
B4X:
*** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[10]

The solution that works for me is not to use Null as a value for CheckedItems.
But it is important to mention the following:
1. The code works with B4A no issues
2. Many times, it works with B4I (when executed from the exact same starting point )
3. Many times when stepping through it works but if you run the code it causes the issue (that made it hard to find)

Hopefully this helps
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Many times, it works with B4I (when executed from the exact same starting point )
In debug mode there are two execution pipelines. If the relevant code was not modified since the last deployment and there are no breakpoints in this code then the fast pipeline is used. In that case it is very similar to running in release mode. You can clean the project (Ctrl + P) to force a full deployment.

The behavior should be the same but in some edge cases there are differences. If you are able to reproduce it in a small project then please upload it as it will be useful with fixing this issue.
 
Upvote 0

iCAB

Well-Known Member
Licensed User
Longtime User
If you are able to reproduce it in a small project then please upload it as it will be useful with fixing this issue.

I am trying to reproduce the issue in a small project: so far not much luck. I will keep trying over the next few days.

Thanks for the clarification
 
Upvote 0
Top