diff options
| author | Marc Gilleron <marc.gilleron@gmail.com> | 2018-05-24 00:59:39 +0200 | 
|---|---|---|
| committer | Marc Gilleron <marc.gilleron@gmail.com> | 2018-05-24 01:09:11 +0200 | 
| commit | 6f6ee60e198eb664e2d3f140090a09bf210db2df (patch) | |
| tree | 3365c93a81806e7f968986742a7bcf86a19ba475 | |
| parent | 0fa3e302631f22a0a6495464d185c07add9be7a3 (diff) | |
Fix potential bugs with Find in Files
- Iteration still going on after scan finished
- Comparing milliseconds with seconds
- Potential imprecision due to accumulating milliseconds (iteration could take fewer than 1ms)
- Folders to scan not cleared when a new search starts
| -rw-r--r-- | editor/find_in_files.cpp | 10 | 
1 files changed, 6 insertions, 4 deletions
diff --git a/editor/find_in_files.cpp b/editor/find_in_files.cpp index ddf619866d..004a49e2b4 100644 --- a/editor/find_in_files.cpp +++ b/editor/find_in_files.cpp @@ -109,6 +109,7 @@ void FindInFiles::start() {  	_current_dir = "";  	PoolStringArray init_folder;  	init_folder.append(_root_dir); +	_folders_stack.clear();  	_folders_stack.push_back(init_folder);  	_initial_files_count = 0; @@ -127,11 +128,12 @@ void FindInFiles::_process() {  	// This part can be moved to a thread if needed  	OS &os = *OS::get_singleton(); -	float duration = 0.0; -	while (duration < 1.0 / 120.0) { -		float time_before = os.get_ticks_msec(); +	float time_before = os.get_ticks_msec(); +	while (is_processing()) {  		_iterate(); -		duration += (os.get_ticks_msec() - time_before); +		float elapsed = (os.get_ticks_msec() - time_before); +		if (elapsed > 1000.0 / 120.0) +			break;  	}  }  |