Skip to content

Commit

Permalink
Fix for usage of ListBuffer to be properly released after leaving the…
Browse files Browse the repository at this point in the history
… scope
  • Loading branch information
Raegan03 committed Jun 16, 2024
1 parent 5ec983c commit dd193c2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ public object SpawnInstance(IObjectResolver resolver)
}
else if (scene.IsValid())
{
var gameObjectBuffer = UnityEngineObjectListBuffer<GameObject>.Get();
scene.GetRootGameObjects(gameObjectBuffer);
foreach (var gameObject in gameObjectBuffer)
using (UnityEngineObjectListBuffer<GameObject>.Get(out var gameObjectBuffer))
{
component = gameObject.GetComponentInChildren(componentType, true);
if (component != null) break;
scene.GetRootGameObjects(gameObjectBuffer);
foreach (var gameObject in gameObjectBuffer)
{
component = gameObject.GetComponentInChildren(componentType, true);
if (component != null) break;
}
}
if (component == null)
{
Expand Down
14 changes: 8 additions & 6 deletions VContainer/Assets/VContainer/Runtime/Unity/LifetimeScope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,15 @@ public static ExtraInstallationScope Enqueue(IInstaller installer)

static LifetimeScope Find(Type type, Scene scene)
{
var buffer = UnityEngineObjectListBuffer<GameObject>.Get();
scene.GetRootGameObjects(buffer);
foreach (var gameObject in buffer)
using (UnityEngineObjectListBuffer<GameObject>.Get(out var buffer))
{
var found = gameObject.GetComponentInChildren(type) as LifetimeScope;
if (found != null)
return found;
scene.GetRootGameObjects(buffer);
foreach (var gameObject in buffer)
{
var found = gameObject.GetComponentInChildren(type) as LifetimeScope;
if (found != null)
return found;
}
}
return null;
}
Expand Down

0 comments on commit dd193c2

Please sign in to comment.