DirectoryIterator::getEstimatedProgress() out of bounds


#1

Hello,
I know that DirectoryIterator::getEstimatedProgress() is intended to be a guide but I would expect it to always return a value between 0 and 1. On Windows it seems often to output values > 1.0.

I’m on 4.3.1 on the develop branch although not right up to date.

Here’s a simple example that reproduces it:

#ifndef MAINCOMPONENT_H_INCLUDED
#define MAINCOMPONENT_H_INCLUDED

#include "../JuceLibraryCode/JuceHeader.h"


class MainContentComponent   : public Component,
                               private Button::Listener,
                               private Timer
{
public:
    //==============================================================================
    MainContentComponent()
    {
        chooseFolder.setButtonText ("Choose Folder");
        addAndMakeVisible (chooseFolder);
        chooseFolder.addListener (this);
        
        progress.setMultiLine (true);
        addAndMakeVisible (progress);
        
        setSize (300, 800);
    }
    
    ~MainContentComponent() {}

    void paint (Graphics& g) override
    {
        g.fillAll (Colours::grey);
    }
    
    void resized() override
    {
        Rectangle<int> area (getLocalBounds());
        
        chooseFolder.setBounds (area.removeFromTop (30).reduced (2));
        progress.setBounds(area.reduced (4));
    }
    
private:
    void buttonClicked (Button*) override
    {
        progress.clear();
        
        FileChooser chooser ("Choose a folder to iterater...",
                             File::getSpecialLocation (File::userHomeDirectory),
                             "*.*");
        
        if (chooser.browseForDirectory())
        {
            iter = new DirectoryIterator (chooser.getResult(), true);
            startTimer (1);
        }
    }
    
    void timerCallback() override
    {
        if (! iter->next())
        {
            progress.insertTextAtCaret ("====FINISHED====\n");
            iter = nullptr;
        }
        
        if (iter == nullptr)
        {
            stopTimer();
            return;
        }

        progress.insertTextAtCaret (String ("Progress: ") + String (iter->getEstimatedProgress()) + String ("\n"));
    }
    
    //==========================================================================
    
    TextButton chooseFolder;
    TextEditor progress;
    ScopedPointer<DirectoryIterator> iter;
    
    //==============================================================================
    JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainContentComponent)
};


#endif  // MAINCOMPONENT_H_INCLUDED

And a snippet of the result of iterating a Projucer project folder:

...
Progress: 1.27157
Progress: 1.27159
Progress: 1.27161
Progress: 1.27163
Progress: 1.27166
Progress: 1.27168
Progress: 1.2717
Progress: 1.27173
Progress: 1.27175
Progress: 1.27192
Progress: 1.27202
Progress: 1.27212
Progress: 1.27196
Progress: 1.27205
Progress: 1.27198
Progress: 1.27199
Progress: 1.272
Progress: 1.27201
Progress: 1.27202
Progress: 1.27203
Progress: 1.27204
Progress: 1.27205
Progress: 1.27206
Progress: 1.27207
Progress: 1.27208
Progress: 1.27209
Progress: 1.2721
Progress: 1.27211
Progress: 1.27212
Progress: 1.27213
Progress: 1.27214
Progress: 1.27215
Progress: 1.27218
Progress: 1.2722
Progress: 1.27222
Progress: 1.27224
Progress: 1.27226
Progress: 1.27228
Progress: 1.2723
Progress: 1.27232
Progress: 1.27234
Progress: 1.27236
Progress: 1.27238
Progress: 1.2724
Progress: 1.27242
Progress: 1.27244
Progress: 1.27246
Progress: 1.27248
Progress: 1.2725
Progress: 1.27252
Progress: 1.27252
Progress: 1.27254
Progress: 1.27255
Progress: 1.27256
Progress: 1.27257
Progress: 1.27258
Progress: 1.2726
Progress: 1.27261
Progress: 1.27262
Progress: 1.27263
Progress: 1.27264
Progress: 1.27265
Progress: 1.27267
Progress: 1.27268
Progress: 1.27269
Progress: 1.27269
Progress: 1.2727
Progress: 1.27271
Progress: 1.27272
Progress: 1.27273
Progress: 1.27274
Progress: 1.27274
Progress: 1.27275
Progress: 1.27276
Progress: 1.27277
Progress: 1.27278
Progress: 1.27278
Progress: 1.27279
Progress: 1.2728
Progress: 1.27281
Progress: 1.27282
Progress: 1.27282
Progress: 1.27283
Progress: 1.27284
Progress: 1.27285
Progress: 1.27286
Progress: 1.27287
Progress: 1.27286
Progress: 1.27304
Progress: 1.27321
Progress: 1.27342
Progress: 1.27343
Progress: 1.27345
Progress: 1.27346
Progress: 1.27348
Progress: 1.27349
Progress: 1.2735
Progress: 1.27352
Progress: 1.27353
Progress: 1.27354
Progress: 1.27356
Progress: 1.27357
Progress: 1.27359
Progress: 1.27358
Progress: 1.27359
Progress: 1.27359
Progress: 1.27359
Progress: 1.2736
Progress: 1.2736
Progress: 1.27361
Progress: 1.27361
Progress: 1.27362
Progress: 1.27362
Progress: 1.27363
Progress: 1.27363
Progress: 1.27364
Progress: 1.27364
Progress: 1.27364
Progress: 1.27365
Progress: 1.27365
Progress: 1.27366
Progress: 1.27366
Progress: 1.27367
Progress: 1.27367
Progress: 1.27368
Progress: 1.27368
Progress: 1.27369
Progress: 1.27369
Progress: 1.27369
Progress: 1.2737
Progress: 1.2737
Progress: 1.27371
Progress: 1.27371
Progress: 1.27372
Progress: 1.27372
Progress: 1.27373
Progress: 1.27373
Progress: 1.27374
Progress: 1.27374
Progress: 1.27375
Progress: 1.27375
Progress: 1.27375
Progress: 1.27379
Progress: 1.27382
Progress: 1.27384
Progress: 1.27386
Progress: 1.27388
Progress: 1.27391
Progress: 1.27393
Progress: 1.27395
Progress: 1.27399
Progress: 1.27402
Progress: 1.27405
Progress: 1.27408
Progress: 1.27411
Progress: 1.27414
Progress: 1.2742
Progress: 1.27424
Progress: 1.27429
Progress: 1.27433
Progress: 1.2743
Progress: 1.27431
Progress: 1.27432
Progress: 1.27433
Progress: 1.27434
Progress: 1.27435
Progress: 1.27436
Progress: 1.27437
Progress: 1.27437
Progress: 1.27438
Progress: 1.27439
Progress: 1.2744
Progress: 1.27441
Progress: 1.27442
Progress: 1.27443
Progress: 1.27444
Progress: 1.27445
Progress: 1.27446
Progress: 1.27446
Progress: 1.27447
Progress: 1.27449
Progress: 1.2745
Progress: 1.27451
Progress: 1.27452
Progress: 1.27453
Progress: 1.27454
Progress: 1.27455
Progress: 1.27456
Progress: 1.27458
Progress: 1.27459
Progress: 1.2746
Progress: 1.27461
Progress: 1.27462
Progress: 1.27463
Progress: 1.27464
Progress: 1.27465
Progress: 1.27467
Progress: 1.27468
Progress: 1.27469
Progress: 1.27471
Progress: 1.27472
Progress: 1.27473
Progress: 1.27474
Progress: 1.27476
Progress: 1.27477
Progress: 1.27478
Progress: 1.2748
Progress: 1.27481
Progress: 1.27482
Progress: 1.27483
Progress: 1.27485
Progress: 1.27486
Progress: 1.27487
Progress: 1.27489
Progress: 1.2749
Progress: 1.27491
Progress: 1.27492
Progress: 1.27494
Progress: 1.27495
Progress: 1.27496
Progress: 1.27497
Progress: 1.27499
Progress: 1.275
Progress: 1.27501
Progress: 1.27501
Progress: 1.27502
Progress: 1.27503
Progress: 1.27503
Progress: 1.27504
Progress: 1.27505
Progress: 1.27505
Progress: 1.27506
Progress: 1.27507
Progress: 1.27507
Progress: 1.27508
Progress: 1.27509
Progress: 1.27509
Progress: 1.2751
Progress: 1.27511
Progress: 1.27511
Progress: 1.27512
Progress: 1.27513
Progress: 1.27513
Progress: 1.27514
Progress: 1.27515
Progress: 1.27515
Progress: 1.27516
Progress: 1.27517
Progress: 1.27517
Progress: 1.27518
Progress: 1.27519
Progress: 1.2752
Progress: 1.27521
Progress: 1.27522
Progress: 1.27523
Progress: 1.27523
Progress: 1.27524
Progress: 1.27525
Progress: 1.27526
Progress: 1.27527
Progress: 1.27528
Progress: 1.27529
Progress: 1.2753
Progress: 1.27531
Progress: 1.27532
Progress: 1.27533
Progress: 1.27534
Progress: 1.27535
Progress: 1.27536
Progress: 1.27537
Progress: 1.26786
Progress: 1.5
Progress: 1.625
====FINISHED====

#2

Thanks Martin, yes - I’ll add a check to make sure it doesn’t do that. Not sure how it’d happen, but I guess with files you never know whether they’ll be getting deleted/added while you’re iterating them.


#3

I’m pretty sure it was happening on directories that weren’t changing. I’ll do a more detailed step-through to see if I can see what’s going on.