Yucked/Victoria

[ BUG ] NullReferenceException on LavaPlayer.PlayAsync(Action<PlayArgs> playArgsAction)

Closed this issue · 1 comments


Describe the bug/issue.

This method always throws NullReferenceException.

Screenshot_5

This is due to the fact that PlayArgs is a struct and not a class, which means that when the playArgs object gets passed to the Action delegate it's done by value and not by reference, thus it does not modify the playArgs object outside of its scope.

The easiest solution would be to promote PlayArgs to a class. Another way to do it would be to create a custom delegate that accepts a ref parameter and replace the Action parameter with it. I'll provide some screenshots below to show you how I did it and I could make a PR with the change if you'd like.

Screenshot_29

^Custom delegate

Screenshot_33

^Replacing Action parameter with the custom delegate and passing the playArgs object as a reference.

Screenshot_36

^This might be the biggest issue with the solution in case the user wants to use a lambda, as due to the ref keyword, it's not allowed to just specify the parameter of the lambda it's also required to specify the type of the parameter, which can make it kind of convoluted.

Stacktrace / Screenshots

Screenshot_12

^Passing the lambda to set the PlayArgs object.

Screenshot_11

^But as you can see, after calling the Action's invoke method with the playArgs object as its argument, the object still remains "empty".

I noticed that a while back but forgot to push a fix out. Thank you for reminding me! The best solution would be to declare it as a class.