@@ -1160,7 +1160,7 @@ public bool PreProcessRoutes(CancellationToken cancellation)
11601160 {
11611161 // read route
11621162 bool pathValid = true ;
1163- AIPath newPath = LoadPath ( thisRoute , out pathValid ) ;
1163+ LoadPathNoClone ( thisRoute , out pathValid ) ;
11641164 if ( ! pathValid ) allPathsLoaded = false ;
11651165 if ( cancellation . IsCancellationRequested )
11661166 return ( false ) ;
@@ -1176,7 +1176,8 @@ public bool PreProcessRoutes(CancellationToken cancellation)
11761176 /// <param name="pathstring"></param>
11771177 /// <param name="validPath"></param>
11781178 /// <returns></returns>
1179- public AIPath LoadPath ( string pathstring , out bool validPath )
1179+ public AIPath LoadPath ( string pathstring , out bool validPath ) => new AIPath ( LoadPathNoClone ( pathstring , out validPath ) ) ;
1180+ public AIPath LoadPathNoClone ( string pathstring , out bool validPath )
11801181 {
11811182 validPath = true ;
11821183
@@ -1191,11 +1192,7 @@ public AIPath LoadPath(string pathstring, out bool validPath)
11911192 bool binaryloaded = false ;
11921193 AIPath outPath = null ;
11931194
1194- if ( Paths . ContainsKey ( formedpathFilefull ) )
1195- {
1196- outPath = new AIPath ( Paths [ formedpathFilefull ] ) ;
1197- }
1198- else
1195+ if ( ! Paths . TryGetValue ( formedpathFilefull , out outPath ) )
11991196 {
12001197 string formedpathFilefullBinary = Path . Combine ( Path . GetDirectoryName ( formedpathFilefull ) , "OpenRails" ) ;
12011198 formedpathFilefullBinary = Path . Combine ( formedpathFilefullBinary , Path . GetFileNameWithoutExtension ( formedpathFilefull ) ) ;
@@ -1213,7 +1210,7 @@ public AIPath LoadPath(string pathstring, out bool validPath)
12131210
12141211 if ( outPath . Nodes != null )
12151212 {
1216- Paths . Add ( formedpathFilefull , new AIPath ( outPath ) ) ;
1213+ Paths . Add ( formedpathFilefull , outPath ) ;
12171214 binaryloaded = true ;
12181215 }
12191216 }
@@ -1235,7 +1232,7 @@ public AIPath LoadPath(string pathstring, out bool validPath)
12351232 {
12361233 try
12371234 {
1238- Paths . Add ( formedpathFilefull , new AIPath ( outPath ) ) ;
1235+ Paths . Add ( formedpathFilefull , outPath ) ;
12391236 }
12401237 catch ( Exception e )
12411238 {
0 commit comments