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

V2 - calculateNextStation - Index out of Bounds exception #65

Closed
armyf35 opened this issue Jan 5, 2024 · 7 comments
Closed

V2 - calculateNextStation - Index out of Bounds exception #65

armyf35 opened this issue Jan 5, 2024 · 7 comments
Labels
Applies To: Dev Branch Any 2.x releases Bug: Minor Annoyances / overall functionality unimpeded Potential Fix Implemented A potential fix for this issue has been implemented in one of the latest builds

Comments

@armyf35
Copy link

armyf35 commented Jan 5, 2024

  1. Choose any stations EXCLUDING the nearest
  2. Loco acts like its in road mode

Might be an issue on the live build, have not tested it.

2024-01-05 00:47:40Z - Dispatcher_V2.0.0.2 - DEB: Car ER 9993 Closest Station was: sylva
2024-01-05 00:47:40Z - Dispatcher_V2.0.0.2 - TRA: EXITING FUNCTION: GetClosestStation
2024-01-05 00:47:40Z - Dispatcher_V2.0.0.2 - DEB: Loco ER 9993 does not have a destination. Defaulting to closest station sylva
2024-01-05 00:47:40Z - Dispatcher_V2.0.0.2 - VER: Loco ER 9993 calculating next station
2024-01-05 00:47:40Z - Dispatcher_V2.0.0.2 - VER: Selected Station: wilmot has position 0
2024-01-05 00:47:40Z - Dispatcher_V2.0.0.2 - VER: Selected Station: whittier has position 1
2024-01-05 00:47:40Z - Dispatcher_V2.0.0.2 - DEB: Current Index was calculated as: -1
2024-01-05 00:47:40Z - Dispatcher_V2.0.0.2 - DEB: Loco ER 9993 next station is to the east
ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
  at System.Collections.Generic.List`1[T].get_Item (System.Int32 index) [0x00009] in <7e05db41a20b45108859fa03b97088d4>:0 
  at RouteManager.v2.core.StationManager.calculateNextStation (System.Collections.Generic.List`1[T] orderedSelectedStations, System.Collections.Generic.List`1[T] selectedPassengerStops, RollingStock.PassengerStop currentStation, Model.Car locomotive) [0x00170] in <10d249ed37cd4219b7867e31fab8ea09>:0 
  at RouteManager.v2.core.StationManager.getNextStation (Model.Car locomotive) [0x000f0] in <10d249ed37cd4219b7867e31fab8ea09>:0 
  at RouteManager.v2.core.AutoEngineer+<AutoEngineerControlRoutine>d__0.MoveNext () [0x000f8] in <10d249ed37cd4219b7867e31fab8ea09>:0 
  at UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) [0x00026] in <16292a0376dd4a2e8ff79beef190c0a8>:0 
UnityEngine.MonoBehaviour:StartCoroutineManaged2(MonoBehaviour, IEnumerator)
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
RouteManager.v2.Dispatcher:Update()
@AdamC1228 AdamC1228 added Bug: Minor Annoyances / overall functionality unimpeded Applies To: Dev Branch Any 2.x releases labels Jan 5, 2024
@AdamC1228 AdamC1228 changed the title Beta - Cannot start route mode without selecting the nearest station V2 - calculateNexStation Index out of Bounds exception Jan 5, 2024
@AdamC1228 AdamC1228 changed the title V2 - calculateNexStation Index out of Bounds exception V2 - calculateNexStation - Index out of Bounds exception Jan 5, 2024
@AdamC1228 AdamC1228 added the Potential Fix Implemented A potential fix for this issue has been implemented in one of the latest builds label Jan 6, 2024
AdamC1228 added a commit that referenced this issue Jan 6, 2024
Implemented checks to prevent #64
Implemented initial fix for #65
More clean up of old code to prevent confusion / missing use of obsolete in future.
@AdamC1228
Copy link
Collaborator

AdamC1228 commented Jan 6, 2024

Potential fix implemented and now available on the v2-dev branch. Feel free to retest / verify but you will need to manually compile the code.

@armyf35 armyf35 changed the title V2 - calculateNexStation - Index out of Bounds exception V2 - calculateNextStation - Index out of Bounds exception Jan 6, 2024
@armyf35
Copy link
Author

armyf35 commented Jan 6, 2024

Nope, still getting the error, I'm pretty sure I know how to fix it. I'll make a PR for this tomorrow. Pretty sure there is a easy fix of just returning the first stop like you did, but I would like to see if I can get a good way to calculate the closest selected stop and return that instead.

2024-01-06 03:26:56Z - Dispatcher_V2.0.0.3 - INF: loco DSL 9670 currently has not called a coroutine - Calling the Coroutine with DSL 9670 as an arguement
2024-01-06 03:26:56Z - Dispatcher_V2.0.0.3 - TRA: ENTERED FUNCTION: AutoEngineerControlRoutine
2024-01-06 03:26:56Z - Dispatcher_V2.0.0.3 - VER: Coroutine Triggered!
2024-01-06 03:26:56Z - Dispatcher_V2.0.0.3 - DEB: Loco: DSL 9670 	 Route Mode: True
2024-01-06 03:26:56Z - Dispatcher_V2.0.0.3 - DEB: Loco: DSL 9670 	 has ID: Ccdu
2024-01-06 03:26:56Z - Dispatcher_V2.0.0.3 - TRA: ENTERED FUNCTION: GetClosestStation
2024-01-06 03:26:56Z - Dispatcher_V2.0.0.3 - DEB: Car DSL 9670 calculating closest station...
2024-01-06 03:26:56Z - Dispatcher_V2.0.0.3 - VER: Car (Ccdu DSL 9670) centerpoint (2805.34, 578.60, 3019.45) has value (2805.34, 578.60, 3019.45))
2024-01-06 03:26:56Z - Dispatcher_V2.0.0.3 - VER: Station center was: (24603.29, 620.60, -938.92)
2024-01-06 03:26:56Z - Dispatcher_V2.0.0.3 - VER: Station center was: (-29959.43, 539.00, -20076.18)
2024-01-06 03:26:56Z - Dispatcher_V2.0.0.3 - VER: Station center was: (-6324.65, 525.00, -1327.83)
2024-01-06 03:26:56Z - Dispatcher_V2.0.0.3 - VER: Station center was: (2816.67, 578.57, 3059.75)
2024-01-06 03:26:56Z - Dispatcher_V2.0.0.3 - VER: Station center was: (12274.70, 561.48, 5882.71)
2024-01-06 03:26:56Z - Dispatcher_V2.0.0.3 - VER: Station center was: (2002.89, 591.78, -213.11)
2024-01-06 03:26:56Z - Dispatcher_V2.0.0.3 - VER: Station center was: (4193.02, 645.16, -3133.15)
2024-01-06 03:26:56Z - Dispatcher_V2.0.0.3 - VER: Station center was: (-23001.43, 653.42, -18015.15)
2024-01-06 03:26:56Z - Dispatcher_V2.0.0.3 - VER: Station center was: (22354.29, 603.20, -1422.08)
2024-01-06 03:26:56Z - Dispatcher_V2.0.0.3 - VER: Station center was: (4492.84, 529.00, 5414.90)
2024-01-06 03:26:56Z - Dispatcher_V2.0.0.3 - VER: Station center was: (9563.77, 546.64, 7406.34)
2024-01-06 03:26:56Z - Dispatcher_V2.0.0.3 - VER: Station center was: (1725.46, 590.08, 1467.05)
2024-01-06 03:26:56Z - Dispatcher_V2.0.0.3 - VER: Station center was: (-15619.00, 595.11, -10610.29)
2024-01-06 03:26:56Z - Dispatcher_V2.0.0.3 - VER: Station center was: (-18974.56, 792.92, -15226.34)
2024-01-06 03:26:56Z - Dispatcher_V2.0.0.3 - VER: Station center was: (16503.47, 570.00, 2327.54)
2024-01-06 03:26:56Z - Dispatcher_V2.0.0.3 - DEB: Car DSL 9670 Closest Station was: hemingway
2024-01-06 03:26:56Z - Dispatcher_V2.0.0.3 - TRA: EXITING FUNCTION: GetClosestStation
2024-01-06 03:26:56Z - Dispatcher_V2.0.0.3 - VER: Loco DSL 9670 calculating next station
2024-01-06 03:26:56Z - Dispatcher_V2.0.0.3 - VER: Selected Station: whittier has position 0
2024-01-06 03:26:56Z - Dispatcher_V2.0.0.3 - VER: Selected Station: topton has position 1
2024-01-06 03:26:56Z - Dispatcher_V2.0.0.3 - VER: Selected Station: rhodo has position 2
2024-01-06 03:26:56Z - Dispatcher_V2.0.0.3 - VER: Selected Station: andrews has position 3
2024-01-06 03:26:56Z - Dispatcher_V2.0.0.3 - DEB: Current Index was calculated as: -1
2024-01-06 03:26:56Z - Dispatcher_V2.0.0.3 - DEB: Loco DSL 9670 next station is to the east
ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
  at System.Collections.Generic.List`1[T].get_Item (System.Int32 index) [0x00009] in <7e05db41a20b45108859fa03b97088d4>:0 
  at RouteManager.v2.core.StationManager.calculateNextStation (System.Collections.Generic.List`1[T] orderedSelectedStations, System.Collections.Generic.List`1[T] selectedPassengerStops, RollingStock.PassengerStop currentStation, Model.Car locomotive) [0x001c0] in <1369ef0b56094bd6b83840fbbe2d56ca>:0 
  at RouteManager.v2.core.StationManager.getNextStation (Model.Car locomotive) [0x000f0] in <1369ef0b56094bd6b83840fbbe2d56ca>:0 
  at RouteManager.v2.core.StationManager.getInitialDestination (Model.Car locomotive) [0x00001] in <1369ef0b56094bd6b83840fbbe2d56ca>:0 
  at RouteManager.v2.core.AutoEngineer+<AutoEngineerControlRoutine>d__0.MoveNext () [0x00114] in <1369ef0b56094bd6b83840fbbe2d56ca>:0 
  at UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) [0x00026] in <16292a0376dd4a2e8ff79beef190c0a8>:0 
UnityEngine.MonoBehaviour:StartCoroutineManaged2(MonoBehaviour, IEnumerator)
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
RouteManager.v2.Dispatcher:Update()

It is also adding unselected stations in the log at least, might just be its not able to cleanup from the exception though.

The next test I did this

2024-01-06 03:26:47Z - Dispatcher_V2.0.0.3 - VER: Selected Station: hemingway has position 0
2024-01-06 03:26:47Z - Dispatcher_V2.0.0.3 - VER: Selected Station: topton has position 1
2024-01-06 03:26:47Z - Dispatcher_V2.0.0.3 - VER: Selected Station: rhodo has position 2
2024-01-06 03:26:47Z - Dispatcher_V2.0.0.3 - VER: Selected Station: andrews has position 3
2024-01-06 03:26:47Z - Dispatcher_V2.0.0.3 - DEB: Current Index was calculated as: 0

Then tried with just topton, rhodo and andrews but got this in the log

2024-01-06 03:26:56Z - Dispatcher_V2.0.0.3 - VER: Selected Station: whittier has position 0
2024-01-06 03:26:56Z - Dispatcher_V2.0.0.3 - VER: Selected Station: topton has position 1
2024-01-06 03:26:56Z - Dispatcher_V2.0.0.3 - VER: Selected Station: rhodo has position 2
2024-01-06 03:26:56Z - Dispatcher_V2.0.0.3 - VER: Selected Station: andrews has position 3
2024-01-06 03:26:56Z - Dispatcher_V2.0.0.3 - DEB: Current Index was calculated as: -1

Another bug now, if you run a train with the engine facing "west" it starts acting very oddly. Thinking its at the end of the line before it should etc. My guess is when it does the direction check and flips LocoTelem.locoTravelingEastWard it then causes the next calculateNextStation to be incorrect. If that is the case then we probably need to separate out the trains travelling direction versus if the locomotive is going forward or backward.

Similar to the first part, I'll make another PR for this part tomorrow.

@AdamC1228
Copy link
Collaborator

I always toss any behavior after an exception out as at that point garbage in garbage out.

There is something I am doing differently that I am just not seeing this crash. Once I have some dinner I will spend some time in game trying to get this to crash in this manner.

As for the direction that is something I have known about for some time. I had planned to address this when I rewrite the portion of code handling the direction changes in the auto-engineer class as that part of the code is relatively untouched and still needs some attention.

@AdamC1228
Copy link
Collaborator

Appears my testing was flawed. I have reproduced now.

@armyf35
Copy link
Author

armyf35 commented Jan 7, 2024

Just made a PR for fixing everything but the East/West issue.

The odd behavior with unselected stations was due to getNextStation checking all selected stations rather than just the specific locomotives

@AdamC1228
Copy link
Collaborator

Merged but made adjustments to select the closest station. When traveling eastward the furthest station would be selected instead of the closest of the selected stations. Please test the adjustments and if everything still checks out we can consider this closed. Thanks!

@armyf35
Copy link
Author

armyf35 commented Jan 7, 2024

Just tested and it works and this can be closed.

I am going to add something to calculate the closest selected station, figure that is a better solution rather than sending the train all the way to one of the two endpoints

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Applies To: Dev Branch Any 2.x releases Bug: Minor Annoyances / overall functionality unimpeded Potential Fix Implemented A potential fix for this issue has been implemented in one of the latest builds
Projects
None yet
Development

No branches or pull requests

2 participants