Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TagsAtStartOfFlowContainerWithPathString() throwing an exception on some knots #209

Closed
hoverbird opened this issue Oct 15, 2016 · 2 comments
Labels

Comments

@hoverbird
Copy link

I haven't figured out why some paths in my story are throwing this exception and not others, but as far as I can tell there's nothing wrong with the knots it's failing on. The exception I'm seeing is:

NullReferenceException: Object reference not set to an instance of an object
Ink.Runtime.Story.TagsAtStartOfFlowContainerWithPathString (System.String pathString) (at Assets/Plugins/Ink/InkRuntime/Story.cs:1581)
Ink.Runtime.Story.TagsForContentAtPath (System.String path) (at Assets/Plugins/Ink/InkRuntime/Story.cs:1566)

It seems like in some of my knots, the first element in flowContainer.Content is not a compiled weave as the comment says it should be, but a tag. innerWeaveContainer is then null, which throws the exception on Story.cs:1581 when we try to fetch its content.

I found a workaround , which thusfar has fetched all my tags perfectly, but I'm not sure if this is a viable fix or if I'm just covering up for something wrong with my story structure:

var innerWeaveContainer = flowContainer.content [0] as Container;
// My workaround is below.
if (innerWeaveContainer == null) {
    innerWeaveContainer = flowContainer;
}

If this solution works I'm happy to submit a pull request. Thanks everyone for the tagging feature, it's otherwise working out GREAT for us!

@hoverbird hoverbird changed the title TagsAtStartOfFlowContainerWithPathString() throwing an exception for some stories TagsAtStartOfFlowContainerWithPathString() throwing an exception on some knots Oct 15, 2016
@joethephish
Copy link
Member

Thanks for this report! This is the same as the issue that's currently open in the inkjs repo: y-lohse/inkjs#38

My bad: I wrote some code to inline containers so they don't get nested so deeply, but at some point recently MonoDevelop/Xamarin's unit tests became buggy and reported success even though they had an internal error half way through. I didn't realise that my changes had negative consequences :-/

Glad you've found a workaround! I expect my fix will be:

            var path = new Runtime.Path (pathString);

            // Expected to be global story, knot or stitch
            var flowContainer = ContentAtPath (path) as Container;
            var firstContentPath = flowContainer.pathToFirstLeafContent;
            var firstContent = flowContainer.ContentAtPath (firstContentPath);
            var firstContentContainer = firstContent.parent as Container;

...the important part being the pathToFirstLeafContent, which will work no matter what the nested structure is - a bit more robust than assuming that it's compiled in a certain way.

@joethephish
Copy link
Member

Fixed in b23db3b, which had the knock on effect of fixing the bug in the unit tests, which now all run successfully.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants