Skip to content

Commit

Permalink
indexoutofrange exception after stopping game fixed & function renamed
Browse files Browse the repository at this point in the history
  • Loading branch information
Saeed Barari committed Jul 28, 2023
1 parent 037692c commit 1bbcc5f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion BContextList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void Init() {
}

[MethodImpl( MethodImplOptions.AggressiveInlining )]
public BContext GetRoot() => this[RootIndex];
public BContext GetRoot() => RootIndex >= Count ? this[0] : this[RootIndex];

public new void Add(BContext context) {
base.Add( context );
Expand Down
10 changes: 5 additions & 5 deletions BinjectManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,9 @@ internal static void UpdateAllRootContextsAndTopmostScene() {
#if B_DEBUG
bool changed = false;
#endif
rootOrder = GetHierarchyOrder( contexts.GetRoot().transform, stack );
rootOrder = CalculateHierarchyOrder( contexts.GetRoot().transform, stack );
for (int i = 0; i < contexts.Count; i++) {
var order = GetHierarchyOrder( contexts[i].transform, stack );
var order = CalculateHierarchyOrder( contexts[i].transform, stack );
if (order < rootOrder) {
rootOrder = order;
contexts.RootIndex = i;
Expand Down Expand Up @@ -292,12 +292,12 @@ internal static void UpdateAllRootContextsAndTopmostScene() {

foreach (var contexts in _groupedContexts.Values) {
const int SCENE_BENEFIT = 1_000_000;
rootOrder = GetHierarchyOrder( contexts.GetRoot().transform, stack ) * sceneOrder[contexts.GetRoot().gameObject.scene] * SCENE_BENEFIT;
rootOrder = CalculateHierarchyOrder( contexts.GetRoot().transform, stack ) * sceneOrder[contexts.GetRoot().gameObject.scene] * SCENE_BENEFIT;
#if B_DEBUG
bool changed = false;
#endif
for (int i = 0; i < contexts.Count; i++) {
var order = GetHierarchyOrder( contexts[i].transform, stack ) * sceneOrder[contexts[i].gameObject.scene] * SCENE_BENEFIT;
var order = CalculateHierarchyOrder( contexts[i].transform, stack ) * sceneOrder[contexts[i].gameObject.scene] * SCENE_BENEFIT;
if (order < rootOrder) {
rootOrder = order;
contexts.RootIndex = i;
Expand All @@ -324,7 +324,7 @@ internal static void UpdateAllRootContextsAndTopmostScene() {
/// the <see cref="stack"/> has to be empty but initialized.
/// </summary>
[MethodImpl( MethodImplOptions.AggressiveInlining )]
static int GetHierarchyOrder(Transform transform, Stack<Transform> stack) {
static int CalculateHierarchyOrder(Transform transform, Stack<Transform> stack) {
do {
stack.Push( transform );
transform = transform.parent;
Expand Down

0 comments on commit 1bbcc5f

Please sign in to comment.