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

 
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
Cookies are required to use this site. You must accept them to continue using the site. Learn more…