@@ -286,6 +286,20 @@ public ushort LaneToCustomSpeedLimit(float laneSpeedLimit, bool roundToSignLimit
286286 /// </summary>
287287 /// <param name="info"></param>
288288 public void FixCurrentSpeedLimits ( NetInfo info ) {
289+ if ( info == null ) {
290+ #if DEBUG
291+ Log . Warning ( $ "SpeedLimitManager.FixCurrentSpeedLimits: info is null!") ;
292+ #endif
293+ return ;
294+ }
295+
296+ if ( info . name == null ) {
297+ #if DEBUG
298+ Log . Warning ( $ "SpeedLimitManager.FixCurrentSpeedLimits: info.name is null!") ;
299+ #endif
300+ return ;
301+ }
302+
289303 if ( ! customizableNetInfos . Contains ( info ) )
290304 return ;
291305
@@ -308,6 +322,20 @@ public void FixCurrentSpeedLimits(NetInfo info) {
308322 /// </summary>
309323 /// <param name="info"></param>
310324 public void ClearCurrentSpeedLimits ( NetInfo info ) {
325+ if ( info == null ) {
326+ #if DEBUG
327+ Log . Warning ( $ "SpeedLimitManager.ClearCurrentSpeedLimits: info is null!") ;
328+ #endif
329+ return ;
330+ }
331+
332+ if ( info . name == null ) {
333+ #if DEBUG
334+ Log . Warning ( $ "SpeedLimitManager.ClearCurrentSpeedLimits: info.name is null!") ;
335+ #endif
336+ return ;
337+ }
338+
311339 if ( ! customizableNetInfos . Contains ( info ) )
312340 return ;
313341
@@ -330,8 +358,26 @@ public void ClearCurrentSpeedLimits(NetInfo info) {
330358 /// <param name="roundToSignLimits">if true, custom speed limit are rounded to speed limits available as speed limit sign</param>
331359 /// <returns></returns>
332360 public ushort GetVanillaNetInfoSpeedLimit ( NetInfo info , bool roundToSignLimits = true ) {
333- if ( info . m_netAI == null )
361+ if ( info == null ) {
362+ #if DEBUG
363+ Log . Warning ( $ "SpeedLimitManager.GetVanillaNetInfoSpeedLimit: info is null!") ;
364+ #endif
334365 return 0 ;
366+ }
367+
368+ if ( info . m_netAI == null ) {
369+ #if DEBUG
370+ Log . Warning ( $ "SpeedLimitManager.GetVanillaNetInfoSpeedLimit: info.m_netAI is null!") ;
371+ #endif
372+ return 0 ;
373+ }
374+
375+ if ( info . name == null ) {
376+ #if DEBUG
377+ Log . Warning ( $ "SpeedLimitManager.GetVanillaNetInfoSpeedLimit: info.name is null!") ;
378+ #endif
379+ return 0 ;
380+ }
335381
336382 /*if (! (info.m_netAI is RoadBaseAI))
337383 return 0;*/
@@ -361,8 +407,19 @@ public ushort GetVanillaNetInfoSpeedLimit(NetInfo info, bool roundToSignLimits =
361407 /// <param name="info">the NetInfo of which the custom speed limit should be determined</param>
362408 /// <returns></returns>
363409 public int GetCustomNetInfoSpeedLimitIndex ( NetInfo info ) {
364- if ( info . m_netAI == null )
410+ if ( info == null ) {
411+ #if DEBUG
412+ Log . Warning ( $ "SpeedLimitManager.SetCustomNetInfoSpeedLimitIndex: info is null!") ;
413+ #endif
365414 return - 1 ;
415+ }
416+
417+ if ( info . name == null ) {
418+ #if DEBUG
419+ Log . Warning ( $ "SpeedLimitManager.SetCustomNetInfoSpeedLimitIndex: info.name is null!") ;
420+ #endif
421+ return - 1 ;
422+ }
366423
367424 /*if (!(info.m_netAI is RoadBaseAI))
368425 return -1;*/
@@ -381,8 +438,19 @@ public int GetCustomNetInfoSpeedLimitIndex(NetInfo info) {
381438 /// <param name="info">the NetInfo for which the custom speed limit should be set</param>
382439 /// <returns></returns>
383440 public void SetCustomNetInfoSpeedLimitIndex ( NetInfo info , int customSpeedLimitIndex ) {
384- if ( info . m_netAI == null )
441+ if ( info == null ) {
442+ #if DEBUG
443+ Log . Warning ( $ "SetCustomNetInfoSpeedLimitIndex: info is null!") ;
444+ #endif
445+ return ;
446+ }
447+
448+ if ( info . name == null ) {
449+ #if DEBUG
450+ Log . Warning ( $ "SetCustomNetInfoSpeedLimitIndex: info.name is null!") ;
451+ #endif
385452 return ;
453+ }
386454
387455 /*if (!(info.m_netAI is RoadBaseAI))
388456 return;*/
@@ -402,6 +470,7 @@ public void SetCustomNetInfoSpeedLimitIndex(NetInfo info, int customSpeedLimitIn
402470 foreach ( string childNetInfoName in childNetInfoNamesByCustomizableNetInfoName [ infoName ] ) {
403471 if ( NetInfoByName . ContainsKey ( childNetInfoName ) ) {
404472 Log . _Debug ( $ "Updating child NetInfo { childNetInfoName } : Setting speed limit to { gameSpeedLimit } ") ;
473+ CustomLaneSpeedLimitIndexByNetInfoName [ childNetInfoName ] = customSpeedLimitIndex ;
405474 UpdateNetInfoGameSpeedLimit ( NetInfoByName [ childNetInfoName ] , gameSpeedLimit ) ;
406475 }
407476 }
@@ -410,7 +479,23 @@ public void SetCustomNetInfoSpeedLimitIndex(NetInfo info, int customSpeedLimitIn
410479
411480 private void UpdateNetInfoGameSpeedLimit ( NetInfo info , float gameSpeedLimit ) {
412481 if ( info == null ) {
413- Log . _Debug ( $ "Updating speed limit of NetInfo: info is null!") ;
482+ #if DEBUG
483+ Log . Warning ( $ "SpeedLimitManager.UpdateNetInfoGameSpeedLimit: info is null!") ;
484+ #endif
485+ return ;
486+ }
487+
488+ if ( info . name == null ) {
489+ #if DEBUG
490+ Log . Warning ( $ "SpeedLimitManager.UpdateNetInfoGameSpeedLimit: info.name is null!") ;
491+ #endif
492+ return ;
493+ }
494+
495+ if ( info . m_lanes == null ) {
496+ #if DEBUG
497+ Log . Warning ( $ "SpeedLimitManager.UpdateNetInfoGameSpeedLimit: info.name is null!") ;
498+ #endif
414499 return ;
415500 }
416501
@@ -449,6 +534,21 @@ public bool SetSpeedLimit(ushort segmentId, NetInfo.Direction finalDir, ushort s
449534 }
450535
451536 NetInfo segmentInfo = Singleton < NetManager > . instance . m_segments . m_buffer [ segmentId ] . Info ;
537+
538+ if ( segmentInfo == null ) {
539+ #if DEBUG
540+ Log . Warning ( $ "SpeedLimitManager.SetSpeedLimit: info is null!") ;
541+ #endif
542+ return false ;
543+ }
544+
545+ if ( segmentInfo . m_lanes == null ) {
546+ #if DEBUG
547+ Log . Warning ( $ "SpeedLimitManager.SetSpeedLimit: info.name is null!") ;
548+ #endif
549+ return false ;
550+ }
551+
452552 uint curLaneId = Singleton < NetManager > . instance . m_segments . m_buffer [ segmentId ] . m_lanes ;
453553 int laneIndex = 0 ;
454554 while ( laneIndex < segmentInfo . m_lanes . Length && curLaneId != 0u ) {
@@ -648,21 +748,26 @@ public bool LoadData(List<Configuration.LaneSpeedLimit> data) {
648748 Log . Info ( $ "Loading lane speed limit data. { data . Count } elements") ;
649749 foreach ( Configuration . LaneSpeedLimit laneSpeedLimit in data ) {
650750 try {
651- if ( ! NetUtil . IsLaneValid ( laneSpeedLimit . laneId ) )
751+ if ( ! NetUtil . IsLaneValid ( laneSpeedLimit . laneId ) ) {
752+ Log . _Debug ( $ "SpeedLimitManager.LoadData: Skipping lane { laneSpeedLimit . laneId } : Lane is invalid") ;
652753 continue ;
754+ }
653755
654756 ushort segmentId = Singleton < NetManager > . instance . m_lanes . m_buffer [ laneSpeedLimit . laneId ] . m_segment ;
655757 NetInfo info = Singleton < NetManager > . instance . m_segments . m_buffer [ segmentId ] . Info ;
656758 int customSpeedLimitIndex = GetCustomNetInfoSpeedLimitIndex ( info ) ;
759+ Log . _Debug ( $ "SpeedLimitManager.LoadData: Handling lane { laneSpeedLimit . laneId } : Custom speed limit index of segment { segmentId } info ({ info } , name={ info ? . name } , lanes={ info ? . m_lanes } is { customSpeedLimitIndex } ") ;
657760 if ( customSpeedLimitIndex < 0 || AvailableSpeedLimits [ customSpeedLimitIndex ] != laneSpeedLimit . speedLimit ) {
658761 // lane speed limit differs from default speed limit
659- Log . _Debug ( $ "Loading lane speed limit: lane { laneSpeedLimit . laneId } = { laneSpeedLimit . speedLimit } ") ;
762+ Log . _Debug ( $ "SpeedLimitManager.LoadData: Loading lane speed limit: lane { laneSpeedLimit . laneId } = { laneSpeedLimit . speedLimit } ") ;
660763 Flags . setLaneSpeedLimit ( laneSpeedLimit . laneId , laneSpeedLimit . speedLimit ) ;
661764 SubscribeToSegmentGeometry ( segmentId ) ;
765+ } else {
766+ Log . _Debug ( $ "SpeedLimitManager.LoadData: Skipping lane speed limit of lane { laneSpeedLimit . laneId } ({ laneSpeedLimit . speedLimit } )") ;
662767 }
663768 } catch ( Exception e ) {
664769 // ignore, as it's probably corrupt save data. it'll be culled on next save
665- Log . Warning ( "Error loading speed limits: " + e . ToString ( ) ) ;
770+ Log . Warning ( "SpeedLimitManager.LoadData: Error loading speed limits: " + e . ToString ( ) ) ;
666771 success = false ;
667772 }
668773 }
0 commit comments