Skip to content

Commit

Permalink
Bugfix: A division by zero exception can occur when calculating the a…
Browse files Browse the repository at this point in the history
…verage number of waiting/floating vehicles
  • Loading branch information
VictorPhilipp committed Jan 4, 2017
1 parent 2fd094b commit 669c9e4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ User manual: http://www.viathinksoft.de/tmpe
1.8.13, 01/01/2017
- Bugfix: Timed traffic ligt data can become corrupt when upgrading a road segment next to a traffic light, leading to faulty UI behavior (thanks to @Brain for reporting this issue)
- Bugfix: The position of the main menu button resets after switching to the free camera mode (thanks to @Impact and @gravage for reporting this issue)
- Bugfix: A division by zero exception can occur when calculating the average number of waiting/floating vehicles
- Improved selection of overlay markers on underground roads (thanks to @Padi for reminding me of that issue)
- Minor performance improvements

Expand Down
4 changes: 3 additions & 1 deletion TLM/TLM/Traffic/SegmentEnd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ public Dictionary<ushort, uint> GetVehicleMetricGoingToSegment(bool includeStopp

if (Options.simAccuracy <= 2) {
uint avgSegmentLength = (uint)netManager.m_segments.m_buffer[SegmentId].m_averageLength;
uint normLength = Math.Min(100u, (uint)(state.TotalLength * 100u) / avgSegmentLength);
uint normLength = 100u;
if (avgSegmentLength > 0)
normLength = Math.Min(100u, (uint)(state.TotalLength * 100u) / avgSegmentLength);

#if DEBUGMETRIC
if (debug)
Expand Down
13 changes: 9 additions & 4 deletions TLM/TLM/UI/SubTools/LaneConnectorTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class NodeLaneMarker {
internal ushort nodeId;
internal bool startNode;
internal Vector3 position;
internal Vector3 secondaryPosition;
internal bool isSource;
internal uint laneId;
internal int innerSimilarLaneIndex;
Expand Down Expand Up @@ -136,10 +137,13 @@ private void ShowOverlay(bool viewOnly, RenderManager.CameraInfo cameraInfo) {
}

private bool IsLaneMarkerHovered(NodeLaneMarker laneMarker, ref Ray mouseRay) {

float y = Singleton<TerrainManager>.instance.SampleDetailHeightSmooth(laneMarker.position);
Bounds bounds = new Bounds(Vector3.zero, Vector3.one);
bounds.center = new Vector3(laneMarker.position.x, y, laneMarker.position.z);
bounds.center = laneMarker.position;
if (bounds.IntersectRay(mouseRay))
return true;

bounds = new Bounds(Vector3.zero, Vector3.one);
bounds.center = laneMarker.secondaryPosition;
return bounds.IntersectRay(mouseRay);
}

Expand Down Expand Up @@ -430,14 +434,15 @@ private List<NodeLaneMarker> GetNodeMarkers(ushort nodeId) {

pos = (Vector3)pos + offset;
float terrainY = Singleton<TerrainManager>.instance.SampleDetailHeightSmooth(((Vector3)pos));
Vector3 finalPos = new Vector3(((Vector3)pos).x, terrainY > ((Vector3)pos).y ? terrainY : ((Vector3)pos).y, ((Vector3)pos).z);
Vector3 finalPos = new Vector3(((Vector3)pos).x, terrainY, ((Vector3)pos).z);

nodeMarkers.Add(new NodeLaneMarker() {
segmentId = segmentId,
laneId = laneId,
nodeId = nodeId,
startNode = !isEndNode,
position = finalPos,
secondaryPosition = (Vector3)pos,
color = colors[nodeMarkers.Count],
isSource = isSource,
laneType = laneInfo.m_laneType,
Expand Down

0 comments on commit 669c9e4

Please sign in to comment.