mirror of
				https://github.com/nsnail/spectre.console.git
				synced 2025-11-01 01:25:27 +08:00 
			
		
		
		
	Fix dividing with infinity bug
When calculating the remaining time for a progress task, we divide the value delta with the current speed. If the speed is zero, then the resulting double will be 'infinity' which will lead to TimeSpan.FromSeconds throwing. This commit fixes that bug by setting the speed to 1 if it's 0 when calculating the remaining time. Closes #169
This commit is contained in:
		 Patrik Svensson
					Patrik Svensson
				
			
				
					committed by
					
						 Patrik Svensson
						Patrik Svensson
					
				
			
			
				
	
			
			
			 Patrik Svensson
						Patrik Svensson
					
				
			
						parent
						
							6932c95731
						
					
				
				
					commit
					e280b82679
				
			| @@ -265,6 +265,14 @@ namespace Spectre.Console | ||||
|                     return null; | ||||
|                 } | ||||
|  | ||||
|                 // If the speed is zero, the estimate below | ||||
|                 // will return infinity (since it's a double), | ||||
|                 // so let's set the speed to 1 in that case. | ||||
|                 if (speed == 0) | ||||
|                 { | ||||
|                     speed = 1; | ||||
|                 } | ||||
|  | ||||
|                 var estimate = (MaxValue - Value) / speed.Value; | ||||
|                 return TimeSpan.FromSeconds(estimate); | ||||
|             } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user