Search Unity

Exception thrown in iOS when using .ContainsKey()

Discussion in 'iOS and tvOS' started by boolean01, Jun 28, 2016.

  1. boolean01

    boolean01

    Joined:
    Nov 16, 2013
    Posts:
    92
    Hi

    I'm using the following line of code to check if a key exists in a dictionary:

    "if (eventTable.ContainsKey(eventType))"

    This works in the editor on Mac, but on the iPad (ios 9) I get the following exception and crash:

    "Key not found in dictionary".

    This exception should be caught by the internal TryGetValue in .Net, but seems to be bubbling up past it and crashing iOS. This also only occurs if I have "Fast and No Exceptions" enabled in the build settings. Could this setting be stripping away how .Net/Mono catches this exception?

    While I can work around the issue and just not use .ContainsKey, quite a few of the libraries and scripts I'm using make use of this so it's a bit of a pain to update them all.

    Would this be considered a Unity bug or am I just using an unsupported feature?

    Cheers.
     
  2. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    A few questions:

    1. Are you compiling using Mono or using IL2CPP ?
    2. Are you absolutely sure the error comes from the line you pasted here? seems very unlikely to me..
     
  3. boolean01

    boolean01

    Joined:
    Nov 16, 2013
    Posts:
    92
    1. IL2CPP
    2. 99% certain - if I manually ensure the item exists in the dictionary before running .ContainsKey I don't get any iOS exceptions. If that check says the item doesn't exist and then (as a test) I run .ContainsKey anyway I get the exception. I could whip up a blank project with just this line and do a test - if it seems strange to you as well then maybe it is a bug and I'll upload it to the unity bug reports.

    Cheers.
     
  4. povilas

    povilas

    Unity Technologies

    Joined:
    Jan 28, 2014
    Posts:
    427
    Hi, have you submitted a bug report for this issue by chance? If yes, what is the case number?