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

Crash while compiling Yarn file #231

Closed
OhTerryTorres opened this issue Apr 17, 2020 · 2 comments
Closed

Crash while compiling Yarn file #231

OhTerryTorres opened this issue Apr 17, 2020 · 2 comments
Assignees
Labels
Milestone

Comments

@OhTerryTorres
Copy link

OhTerryTorres commented Apr 17, 2020

A particular Yarn file causes a compilation error.

Error on line 6 at position 10:
no viable alternative at input '<<set $s1.'
<<set $s1.pirateRespect to 0>>
..........^

The node in question looks like this:

title: S1
tags: 
colorID: 0
position: 337,-9941
---
**<<set $s1_pirateRespect to 0>>**
<<set $s1_firstMate to "Kazuma">>
{$firstMate} takes the spyglass from his eye.
<<if Rapp()>>
    Rapp: Check it out.<p> Looks like we found something.
<<else>>
    Guido: Care to take a peek?
<<endif>>
{$firstMate} offers it to you.
...

Full Yarn file here.

The variable $s1_pirateRespect was changed from $s1.pirateRespect back when updating to YarnSpinner 1.0. So it appears to be... an old version of the file?

Reimporting triggers the following build errors, top to bottom:

NullReferenceException: Object reference not set to an instance of an object
Yarn.Compiler.BodyVisitor.GenerateFormattedText (System.Collections.Generic.IList`1[T] nodes, System.String& outputString, System.Int32& expressionCount) (at <9d419cb6180b453c97c5942b14e16443>:0)
Yarn.Compiler.BodyVisitor.VisitCommand_statement (YarnSpinnerParser+Command_statementContext context) (at <9d419cb6180b453c97c5942b14e16443>:0)
YarnSpinnerParser+Command_statementContext.Accept[TResult] (Antlr4.Runtime.Tree.IParseTreeVisitor`1[Result] visitor) (at <9d419cb6180b453c97c5942b14e16443>:0)
Antlr4.Runtime.Tree.AbstractParseTreeVisitor`1[Result].VisitChildren (Antlr4.Runtime.Tree.IRuleNode node) (at <f2f4188ed7484f8ca20ff6e9163f87df>:0)
YarnSpinnerParserBaseVisitor`1[Result].VisitStatement (YarnSpinnerParser+StatementContext context) (at <9d419cb6180b453c97c5942b14e16443>:0)
YarnSpinnerParser+StatementContext.Accept[TResult] (Antlr4.Runtime.Tree.IParseTreeVisitor`1[Result] visitor) (at <9d419cb6180b453c97c5942b14e16443>:0)
Antlr4.Runtime.Tree.AbstractParseTreeVisitor`1[Result].Visit (Antlr4.Runtime.Tree.IParseTree tree) (at <f2f4188ed7484f8ca20ff6e9163f87df>:0)
Yarn.Compiler.Compiler.EnterBody (YarnSpinnerParser+BodyContext context) (at <9d419cb6180b453c97c5942b14e16443>:0)
YarnSpinnerParser+BodyContext.EnterRule (Antlr4.Runtime.Tree.IParseTreeListener listener) (at <9d419cb6180b453c97c5942b14e16443>:0)
Antlr4.Runtime.Tree.ParseTreeWalker.EnterRule (Antlr4.Runtime.Tree.IParseTreeListener listener, Antlr4.Runtime.Tree.IRuleNode r) (at <f2f4188ed7484f8ca20ff6e9163f87df>:0)
Antlr4.Runtime.Tree.ParseTreeWalker.Walk (Antlr4.Runtime.Tree.IParseTreeListener listener, Antlr4.Runtime.Tree.IParseTree t) (at <f2f4188ed7484f8ca20ff6e9163f87df>:0)
Antlr4.Runtime.Tree.ParseTreeWalker.Walk (Antlr4.Runtime.Tree.IParseTreeListener listener, Antlr4.Runtime.Tree.IParseTree t) (at <f2f4188ed7484f8ca20ff6e9163f87df>:0)
Antlr4.Runtime.Tree.ParseTreeWalker.Walk (Antlr4.Runtime.Tree.IParseTreeListener listener, Antlr4.Runtime.Tree.IParseTree t) (at <f2f4188ed7484f8ca20ff6e9163f87df>:0)
Yarn.Compiler.Compiler.Compile (Antlr4.Runtime.Tree.IParseTree tree) (at <9d419cb6180b453c97c5942b14e16443>:0)
Yarn.Compiler.Compiler.CompileString (System.String text, System.String fileName, Yarn.Program& program, System.Collections.Generic.IDictionary`2[System.String,Yarn.Compiler.StringInfo]& stringTable) (at <9d419cb6180b453c97c5942b14e16443>:0)
YarnImporter.ImportYarn (UnityEditor.Experimental.AssetImporters.AssetImportContext ctx) (at Assets/YarnSpinner/Editor/YarnImporter.cs:71)
YarnImporter.OnImportAsset (UnityEditor.Experimental.AssetImporters.AssetImportContext ctx) (at Assets/YarnSpinner/Editor/YarnImporter.cs:54)
UnityEditor.Experimental.AssetImporters.ScriptedImporter.GenerateAssetData (UnityEditor.Experimental.AssetImporters.AssetImportContext ctx) (at /Users/builduser/buildslave/unity/build/Modules/AssetPipelineEditor/Public/ScriptedImporter.cs:22)


AssetImporter is referencing an asset from the previous import. This should not happen.


Asset import failed, "Assets/Resources/Dialogues/S1a.yarn" > NullReferenceException: Object reference not set to an instance of an object
Yarn.Compiler.BodyVisitor.GenerateFormattedText (System.Collections.Generic.IList`1[T] nodes, System.String& outputString, System.Int32& expressionCount) (at <9d419cb6180b453c97c5942b14e16443>:0)
Yarn.Compiler.BodyVisitor.VisitCommand_statement (YarnSpinnerParser+Command_statementContext context) (at <9d419cb6180b453c97c5942b14e16443>:0)
YarnSpinnerParser+Command_statementContext.Accept[TResult] (Antlr4.Runtime.Tree.IParseTreeVisitor`1[Result] visitor) (at <9d419cb6180b453c97c5942b14e16443>:0)
Antlr4.Runtime.Tree.AbstractParseTreeVisitor`1[Result].VisitChildren (Antlr4.Runtime.Tree.IRuleNode node) (at <f2f4188ed7484f8ca20ff6e9163f87df>:0)
YarnSpinnerParserBaseVisitor`1[Result].VisitStatement (YarnSpinnerParser+StatementContext context) (at <9d419cb6180b453c97c5942b14e16443>:0)
YarnSpinnerParser+StatementContext.Accept[TResult] (Antlr4.Runtime.Tree.IParseTreeVisitor`1[Result] visitor) (at <9d419cb6180b453c97c5942b14e16443>:0)
Antlr4.Runtime.Tree.AbstractParseTreeVisitor`1[Result].Visit (Antlr4.Runtime.Tree.IParseTree tree) (at <f2f4188ed7484f8ca20ff6e9163f87df>:0)
Yarn.Compiler.Compiler.EnterBody (YarnSpinnerParser+BodyContext context) (at <9d419cb6180b453c97c5942b14e16443>:0)
YarnSpinnerParser+BodyContext.EnterRule (Antlr4.Runtime.Tree.IParseTreeListener listener) (at <9d419cb6180b453c97c5942b14e16443>:0)
Antlr4.Runtime.Tree.ParseTreeWalker.EnterRule (Antlr4.Runtime.Tree.IParseTreeListener listener, Antlr4.Runtime.Tree.IRuleNode r) (at <f2f4188ed7484f8ca20ff6e9163f87df>:0)
Antlr4.Runtime.Tree.ParseTreeWalker.Walk (Antlr4.Runtime.Tree.IParseTreeListener listener, Antlr4.Runtime.Tree.IParseTree t) (at <f2f4188ed7484f8ca20ff6e9163f87df>:0)
Antlr4.Runtime.Tree.ParseTreeWalker.Walk (Antlr4.Runtime.Tree.IParseTreeListener listener, Antlr4.Runtime.Tree.IParseTree t) (at <f2f4188ed7484f8ca20ff6e9163f87df>:0)
Antlr4.Runtime.Tree.ParseTreeWalker.Walk (Antlr4.Runtime.Tree.IParseTreeListener listener, Antlr4.Runtime.Tree.IParseTree t) (at <f2f4188ed7484f8ca20ff6e9163f87df>:0)
Yarn.Compiler.Compiler.Compile (Antlr4.Runtime.Tree.IParseTree tree) (at <9d419cb6180b453c97c5942b14e16443>:0)
Yarn.Compiler.Compiler.CompileString (System.String text, System.String fileName, Yarn.Program& program, System.Collections.Generic.IDictionary`2[System.String,Yarn.Compiler.StringInfo]& stringTable) (at <9d419cb6180b453c97c5942b14e16443>:0)
YarnImporter.ImportYarn (UnityEditor.Experimental.AssetImporters.AssetImportContext ctx) (at Assets/YarnSpinner/Editor/YarnImporter.cs:71)
YarnImporter.OnImportAsset (UnityEditor.Experimental.AssetImporters.AssetImportContext ctx) (at Assets/YarnSpinner/Editor/YarnImporter.cs:54)
UnityEditor.Experimental.AssetImporters.ScriptedImporter.GenerateAssetData (UnityEditor.Experimental.AssetImporters.AssetImportContext ctx) (at /Users/builduser/buildslave/unity/build/Modules/AssetPipelineEditor/Public/ScriptedImporter.cs:22)

The error is resolved if approximately the first 34 nodes in the Yarn file are deleted.

Build warnings for all other Yarn files are accurate.

  • Yarn Spinner Version: 1.1.0
  • Unity Version: 2019.2.12f1
@desplesda
Copy link
Collaborator

Thank you for this report! Will investigate.

@desplesda
Copy link
Collaborator

Looks like the issue isn't actually in the node S1 in your file. In isolation, it compiles fine.

When I attempted to compile the full Yarn file you linked, I saw an exception when parsing the command <<p>> on line 386. (The same command also appears on line 1368.)

The issue is that commands that are a single character long (<<p>>) cause a crash in the compiler. As a workaround until a fix is shipped, replace the single-character command with something else (e.g. <pp>).

Technical details of the error!

It appears that <<p>> is being lexed as a COMMAND_START '<<', followed by a COMMAND_TEXT_END 'p>>'. This is incorrect behaviour from the lexer, because COMMAND_TEXT_END should only ever be >>.

It appears that the more directive in line 380 of YarnSpinnerLexer.g4 is causing the entire string p>> to be incorrectly matched against the token COMMAND_TEXT_END, when it should have been matched as a COMMAND_TEXT followed by a COMMAND_TEXT_END.

COMMAND_ARBITRARY: . -> more, mode(CommandTextMode);

This can be fixed by marking the token as COMMAND_TEXT before moving to CommandTextMode:

COMMAND_ARBITRARY: . -> type(COMMAND_TEXT), mode(CommandTextMode);

I'll push a fix for this issue now, and it should be resolved in the next release.

Thanks for reporting this!

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