Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice

Bug ConditionalWeakTable getting corrupted

Discussion in 'Editor & General Support' started by Jawsarn, Jul 8, 2022.

  1. Jawsarn

    Jawsarn

    Joined:
    Jan 12, 2017
    Posts:
    245
    The values in the table are "frequently" getting corrupted as in casting. I cannot reliably reproduce it, but it happeens every now and then. We're currently running 2021.3.4f1


    Code (CSharp):
    1. InvalidCastException: Specified cast is not valid.
    2. (wrapper castclass) System.Object.__castclass_with_cache(object,intptr,intptr)
    3. System.Runtime.CompilerServices.ConditionalWeakTable`2[TKey,TValue].TryGetValue (TKey key, TValue& value) (at <d4cde64232cf45659d86aafa597faa77>:0)
    upload_2022-7-8_17-6-29.png
    upload_2022-7-8_17-7-40.png
     
    Enderlook likes this.
  2. kyubuns

    kyubuns

    Joined:
    Aug 6, 2013
    Posts:
    138
    We have the same problem.
    It is not a problem on Editor and probably only happens when we do an IL2CPP build.
    Does anyone have any information on this?

    Unity 2021.3.16
     
  3. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,926
  4. kyubuns

    kyubuns

    Joined:
    Aug 6, 2013
    Posts:
    138
    Ok.
    I have sent a Bug Report with the smallest project to reproduce.
    IN-28680.
     
    firelight_jaden likes this.
  5. kyubuns

    kyubuns

    Joined:
    Aug 6, 2013
    Posts:
    138
    Reminder.
    The following code crashes when run on Unity 2021.3.16f1.
    Additionally, the IL2CPP built client (checked on iOS, mac, windows. Probably all.) But it also crashes.
    It works fine with Unity2020.3.18f1.

    Code (CSharp):
    1. using System.Collections.Generic;
    2. using System.Runtime.CompilerServices;
    3. using UnityEngine;
    4. public class Test : MonoBehaviour
    5. {
    6.     private readonly List<int[]> _keys = new List<int[]>();
    7.     private readonly ConditionalWeakTable<int[], string> _test = new ConditionalWeakTable<int[], string>();
    8.     public void Update()
    9.     {
    10.         Debug.Log($"== {Time.frameCount}");
    11.         for (var k = 0; k < 1000; ++k)
    12.         {
    13.             var i = new[] { Random.Range(0, 10000000) };
    14.             _test.Add(i, $"Test{i[0]}");
    15.             _keys.Add(i);
    16.         }
    17.         for (var k = 0; k < 10; ++k)
    18.         {
    19.             var i = _keys[Random.Range(0, _keys.Count)];
    20.             var b = _test.GetValue(i, _ => null);
    21.             Debug.Log($"{b}");
    22.         }
    23.     }
    24. }
     
    Last edited: Jan 13, 2023
    firelight_jaden likes this.
  6. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,926
    Thank you for the details.
     
  7. rhys_vdw

    rhys_vdw

    Joined:
    Mar 9, 2012
    Posts:
    110
  8. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,926
  9. rhys_vdw

    rhys_vdw

    Joined:
    Mar 9, 2012
    Posts:
    110
    Great, thank you. :)
     
  10. TJNBG

    TJNBG

    Joined:
    Apr 7, 2021
    Posts:
    23
    Hello,

    This is still reproducible in 2022.2.15, even though the issuetracker says it was fixed in 2022.2.11.

    Any updates?
     
  11. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,926
    As far as we have seen, this bug was corrected the versions listed in the issue tracker link earlier in this thread.

    However, you might be experiencing a different issue. Is this something you can submit a new bug report for.