Skip to content

Don't unbox non-blittable generic valuetypes for parameter loading#69

Merged
Kasuromi merged 4 commits intomasterfrom
generic-unboxing-fix
Apr 1, 2023
Merged

Don't unbox non-blittable generic valuetypes for parameter loading#69
Kasuromi merged 4 commits intomasterfrom
generic-unboxing-fix

Conversation

@Kasuromi
Copy link
Copy Markdown
Member

@Kasuromi Kasuromi commented Dec 29, 2022

Fixes an issue where non-blittable generic value types get unboxed when they shouldn't be during parameter loading.

The most notable example is adding a boxed integer into a dictionary, the value field would have invalid data written to it.

private unsafe void Test() {
    long testLong = 2137;
    var testInt64 = new Il2CppSystem.Int64();
    *&testInt64.m_value = testLong;

    var dictionary = new Il2CppSystem.Collections.Generic.Dictionary<string, Il2CppSystem.Object>();
    dictionary.Add("test", testInt64.BoxIl2CppObject()); // PREV: Writes invalid data to value field
 
    foreach (var kv in dictionary)
    {
        Log.LogInfo(kv.Key);   // "test"
        Log.LogInfo(kv.Value); // 2137   (PREV: crash on access)
    }
}

@Kasuromi Kasuromi changed the title Don't unbox non-blittable valuetypes for parameter loading Don't unbox non-blittable generic valuetypes for parameter loading Dec 30, 2022
@Kasuromi Kasuromi force-pushed the generic-unboxing-fix branch from 9d320b1 to 945e721 Compare April 1, 2023 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants