Skip to content
This repository has been archived by the owner on Jun 8, 2021. It is now read-only.

Null Reference Error in "ShrinkIfPossible" #21

Closed
HulloImJay opened this issue May 2, 2018 · 3 comments
Closed

Null Reference Error in "ShrinkIfPossible" #21

HulloImJay opened this issue May 2, 2018 · 3 comments

Comments

@HulloImJay
Copy link

I am sometimes getting a null reference error in the function
public PointOctreeNode<T> ShrinkIfPossible(float minLength)

on the first line of this block
if (objects.Count == 0 && children.Length == 0) { return this; }

after calling PointOctree.Remove().

Attached is a screen of MonoDevelop hitting a break point in a test block I added. It appears that "objects" can have a count of 0 and "children" can be null at the same time. Note also that inserting this block appears to prevent the issue, but I'm concerned about what side effects it might have as I don't really have a good grasp of the inner workings here.

screen shot 2018-05-02 at 10 22 01 am

This occurs often but not always in my scenario (perhaps 30% of the time), and usually throws null reference errors for a number of frames before stopping. This is a somewhat elaborate project with a strong possibility of timing and chance influencing the scenario here.

I regret that I don't have a clean reproduction case for you :(

@Nition
Copy link
Owner

Nition commented May 3, 2018

I think you've found a legitimate bug there. Looks like the if (objects.Count == 0 && children.Length == 0) check should also be checking whether children is null. Your objects == null part should be unnecessary as objects is assigned right away and never cleared.

Try this:

if (objects.Count == 0 && (children == null || children.Length == 0)) {
	return this;
}

I've also just updated this repo with that change.

@HulloImJay
Copy link
Author

This seems to prevent the issue. I'm not familiar with the pull request process, so I'll just let you make the change when you are able.

Thanks! :)

@Nition
Copy link
Owner

Nition commented May 3, 2018

All good, it's done.

@Nition Nition closed this as completed Oct 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants