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

Casting error from Enchantment to ICharacter. #183

Open
lunjohnzhang opened this issue May 14, 2020 · 5 comments
Open

Casting error from Enchantment to ICharacter. #183

lunjohnzhang opened this issue May 14, 2020 · 5 comments

Comments

@lunjohnzhang
Copy link

lunjohnzhang commented May 14, 2020

Hello,

We have implemented a .NETCore Evaluator to iteratively run games. When we try to use the Game.Process(PlayTask gameTask) function to process a game, .NET gives us this error after certain iterations

Unhandled Exception: System.AggregateException: One or more errors occurred. (Unable to cast object of type 'SabberStoneCore.Model.Entities.Enchantment' to type 'SabberStoneCore.Model.Entities.ICharacter'.) ---> System.InvalidCastException: Unable to cast object of type 'SabberStoneCore.Model.Entities.Enchantment' to type 'SabberStoneCore.Model.Entities.ICharacter'.
at SabberStoneCore.Model.Game.Process(PlayerTask gameTask) in /Users/yulunzhang/Desktop/Coding/icaros/hearthstone/SabberStone/SabberStoneCore/src/Model/Game.cs:line 486
at DeckEvaluator.Evaluation.GameEvaluator.PlayGame() in /Users/yulunzhang/Desktop/Coding/icaros/hearthstone/EvoStone/DeckEvaluator/src/Evaluation/GameEvaluator.cs:line 165
at DeckEvaluator.Evaluation.GameDispatcher.runGame(Int32 gameId, GameEvaluator ev) in /Users/yulunzhang/Desktop/Coding/icaros/hearthstone/EvoStone/DeckEvaluator/src/Evaluation/GameDispatcher.cs:line 72
at System.Threading.Tasks.Parallel.<>c__DisplayClass19_01.<ForWorker>b__1(RangeWorker& currentWorker, Int32 timeout, Boolean& replicationDelegateYieldedBeforeCompletion) --- End of stack trace from previous location where exception was thrown --- at System.Threading.Tasks.Parallel.<>c__DisplayClass19_01.b__1(RangeWorker& currentWorker, Int32 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
at System.Threading.Tasks.TaskReplicator.Replica1.ExecuteAction(Boolean& yieldedBeforeCompletion) at System.Threading.Tasks.TaskReplicator.Replica.Execute() --- End of inner exception stack trace --- at System.Threading.Tasks.TaskReplicator.Run[TState](ReplicatableUserAction1 action, ParallelOptions options, Boolean stopOnFirstFailure)
at System.Threading.Tasks.Parallel.ForWorker[TLocal](Int32 fromInclusive, Int32 toExclusive, ParallelOptions parallelOptions, Action1 body, Action2 bodyWithState, Func4 bodyWithLocal, Func1 localInit, Action1 localFinally) --- End of stack trace from previous location where exception was thrown --- at System.Threading.Tasks.Parallel.ThrowSingleCancellationExceptionOrOtherException(ICollection exceptions, CancellationToken cancelToken, Exception otherException) at System.Threading.Tasks.Parallel.ForWorker[TLocal](Int32 fromInclusive, Int32 toExclusive, ParallelOptions parallelOptions, Action1 body, Action2 bodyWithState, Func4 bodyWithLocal, Func1 localInit, Action1 localFinally)
at System.Threading.Tasks.Parallel.For(Int32 fromInclusive, Int32 toExclusive, ParallelOptions parallelOptions, Action`1 body)
at DeckEvaluator.Evaluation.GameDispatcher.Run() in /Users/yulunzhang/Desktop/Coding/icaros/hearthstone/EvoStone/DeckEvaluator/src/Evaluation/GameDispatcher.cs:line 127
at DeckEvaluator.Program.Main(String[] args) in /Users/yulunzhang/Desktop/Coding/icaros/hearthstone/EvoStone/DeckEvaluator/src/Program.cs:line 119
[1] 78423 abort dotnet bin/DeckEvaluator.dll 1

This error exposes a casting error in Game.cs, but when we look through the source code of SabberStone it doesn't seem to have such a casting on the specified place (line 486 of Game.cs). We will appreciate if you can help us with this.

SabberStone version: 2.1.0 (we pull the code from master and compiled it)
.NETCore version: 2.1

@Bert-Proesmans
Copy link
Contributor

Can you publish the code that triggers this exception? It will help with discovering where the issue lies.

@Bert-Proesmans
Copy link
Contributor

So I checked the MASTER ref on your EvoStone fork (https://github.com/lunjohnzhang/EvoStone/tree/a0eb3eb8594fa0d32a49a3c6f99abc056b41eb7d) as is. My worker did a complete run with Evolution as strategy. There weren't any crashes.
Without more details, this issue might be caused by EvoStone.
When providing more info, mention the commit hash specifically and publish a reproduction if possible, or make your custom code public.

@lunjohnzhang
Copy link
Author

lunjohnzhang commented May 25, 2020

Sorry for the late reply, I was doing something else over the past week.

I have opened another branch here that contains the code to reproduce the error. Commit hash: lunjohnzhang/EvoStone@02ac556

To run it, make sure that SabberStoneCore.dll is correctly compiled. Then, please go to TestBed/DeckSearch, and then run python setup.py to set up the project. Then run dotnet bin/DeckEvaluator.dll config/paladin_me.tml error_deck.tml. I remove the threading stuff in the original repo so the error is clearer.

The code is running one round of 200 games between the deck inside error_deck.tml and a fixed set of 200 opponent decks. However, note that the code does not produce the error every time when you run it, and even though it produces the error, it may produce it at different times regardless of the fact that it should be running the same thing every time. For me, it produces the error 7 out of 10 runs. This is another weird thing regarding this error.

Thank you very much for you help and feel free to ask me any questions regarding this project.

@Bert-Proesmans

@Bert-Proesmans
Copy link
Contributor

So we're specifically looking for an error that isn't 100% reproducible. This happens during a serialized run of 200 games.
At about 10 runs of the above command the error should manifest at least a few times.

I'm running now. Hopefully I'll get some reproduction this evening.

@Bert-Proesmans
Copy link
Contributor

Ok, so the casting happens here: https://github.com/HearthSim/SabberStone/blob/master/SabberStoneCore/src/Model/Game.cs#L499

The PlayerTask has been calculated from a different game. It's applied to another game that has forked off and potentially desynced somehow. The target identifier within the gameTask points to a non-character in the forked game.

I don't know if this is intended and badly handled or unintentional. Using git blame appoints @rnilva with this commit 6a08c57

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

No branches or pull requests

2 participants