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

Extension (2.4.10+) Crashes on Init when calling DialogueRunner.AddFunction() with an instance method #55

Open
fmoo opened this issue Aug 24, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@fmoo
Copy link

fmoo commented Aug 24, 2024

What is the current behavior?

When DialogueRunner.AddFunction<>() is called with an instance method, the extension crashes during initialization.

Please provide the steps to reproduce, and if possible a minimal demo of the problem:

Include this CustomExtensions.cs in your project

using UnityEngine;
using Yarn.Unity;

public class CustomExtensions : MonoBehaviour {
    [SerializeField] DialogueRunner runner;

    void Awake() {
        if (runner != null) InitializeRunner(runner);
    }

    public void InitializeRunner(DialogueRunner runner) {
        new ScopedExtensions(runner);
    }

    public class ScopedExtensions {
        private DialogueRunner thisRunner;
        public int Sub2(string varA, string varB) {
            thisRunner.VariableStorage.TryGetValue<int>(varA, out var a);
            thisRunner.VariableStorage.TryGetValue<int>(varB, out var b);
            return a - b;
        }

        public ScopedExtensions(DialogueRunner runner) {
            thisRunner = runner;
            thisRunner.AddFunction<string, string, int>("Sub2", Sub2);  // Crashes yarn
        }
    }
}

And a sample yarn file:

title: TestFile
---
<<declare $b = 0>>
<<set $b = Sub2("a", "b")>>
===

Open the .yarn file and observe the following error logs (one in a popup, one in the yarnspinner plugin console): https://pastebin.com/X29QAW6Z

What is the expected behavior?

The yarn extension loads and I can ctrl+click into Sub2 and jump to the implementation

Please tell us about your environment:

  • Yarn Spinner Version: 2.2.2+git
  • Extension Version: 2.4.10+
  • Unity Version: 2021.3.12f1

Other information

https://pastebin.com/X29QAW6Z

@fmoo fmoo added the bug Something isn't working label Aug 24, 2024
@fmoo
Copy link
Author

fmoo commented Aug 24, 2024

I believe this is the same trigger condition as #48, as the .yarn lines logs type checking errors on 2.4.9 and earlier.

@fmoo
Copy link
Author

fmoo commented Dec 6, 2024

I believe this is the same trigger condition as #48, as the .yarn lines logs type checking errors on 2.4.9 and earlier.

This does not seem to be the case as I was able to get a structure that cmd+click and function syntax works OK on 2.4.9, but still crashes on newer versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant