Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## Version 1.2.4

### Fixes

- Fixed a `StackOverflowException` during injection when a component exposed a `Dictionary` property that had been iterated at edit time (e.g. from `OnDrawGizmos`), which leaves an internal reference cycle for traversal to follow. Generic collection types are no longer treated as nested serializable, so injection no longer recurses into their internal fields.

### Tests

- Added coverage ensuring generic collection types are excluded from nested serializable traversal while plain `[Serializable]` classes are still included.

## Version 1.2.3

### Fixes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ public static bool IsNestedSerializable(this Type type)
if (type == typeof(string))
return false;

// Unity does not serialize generic types (e.g. Dictionary<,>, List<T>) as nested custom
// classes, and their internal fields can form reference cycles (Dictionary <-> ValueCollection),
// so never recurse into them during traversal.
if (type.IsGenericType)
return false;

return !typeof(Object).IsAssignableFrom(type) &&
type.IsDefined(typeof(SerializableAttribute), inherit: false);
}
Expand Down
2 changes: 1 addition & 1 deletion UnityProject/Saneject/Assets/Plugins/Saneject/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "com.alexanderlarsen.saneject",
"author": "Alexander Larsen",
"displayName": "Saneject",
"version": "1.2.3",
"version": "1.2.4",
"description": "Inject dependencies in the Unity Editor, not Play Mode, by writing them directly into serialized fields at edit-time using familiar DI APIs, so everything stays visible in the Inspector, including interfaces.\n\nNo runtime container. No startup cost. No hidden wiring. No weird lifecycles. Just simple, deterministic edit-time DI that works with Unity, not around it.",
"documentationUrl": "https://github.com/alexanderlarsen/Saneject/blob/main/README.md",
"changelogUrl": "https://github.com/alexanderlarsen/Saneject/blob/main/CHANGELOG.md",
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Collections.Generic;
using NUnit.Framework;
using Plugins.Saneject.Editor.Extensions;
using Tests.Saneject.Fixtures.Scripts.InjectionTargets;
using UnityEngine;

namespace Tests.Saneject.Editor.Extensions
{
public class TypeExtensionsTests
{
// Regression: generic collection types (e.g. Dictionary<,>, List<>) carry [Serializable] and would
// otherwise be treated as nested serializable, causing traversal to recurse into their internal
// fields. A Dictionary property's cached ValueCollection holds a back-reference to the dictionary,
// producing a reference cycle and an uncatchable StackOverflowException during injection.
[Test]
public void IsNestedSerializable_ReturnsFalse_ForGenericCollectionTypes()
{
Assert.That(typeof(Dictionary<Vector3, NestedChildTarget>).IsNestedSerializable(), Is.False);
Assert.That(typeof(List<NestedChildTarget>).IsNestedSerializable(), Is.False);
}

// Guard rail: the generic exclusion above must not stop plain [Serializable] user classes from
// being traversed for nested injection.
[Test]
public void IsNestedSerializable_ReturnsTrue_ForPlainSerializableClass()
{
Assert.That(typeof(NestedChildTarget).IsNestedSerializable(), Is.True);
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading