After many hours of troubleshooting, I've isolated strange behavior of an 
NSProgressIndicator in one of my projects into a demo app.

If, when using an determinate NSProgressIndicator repeatedly to show progress 
in different tasks and all of the following are true:

* Hide it between tasks
* Let the app's run loop cycle between tasks
* Run it fast enough
* Do not have any other progress indicator running in the window

then, after the first task runs OK, the progress bar will not work properly on 
subsequent tasks.  It will show the first increment and then get stuck, showing 
a short bit of blue at the left only.

It's all main thread.  Can anyone tell me why these factors cause my progress 
bar to fail?

I have an early 2006 Mac Mini and Mac OS X 10.6.2.

Thanks,

Jerry Krinock

Here is the movie:
http://sheepsystems.com/engineering/NSProgressBarBadness.mov

Here is the demo app:
http://sheepsystems.com/engineering/NSProgressBarBadness.zip

Here is the code:

#import <Cocoa/Cocoa.h>

@interface NSProgressBarBadnessAppDelegate : NSObject <NSApplicationDelegate> {
    IBOutlet NSWindow* window ;
    IBOutlet NSProgressIndicator* progressBar ;
    IBOutlet NSProgressIndicator* progressCircle ;
    NSString* m_taskMillisecondsString ;
    BOOL m_displayAfterIncrementing ;
    BOOL m_hideAfterEachTask ;
    BOOL m_spin ;
}

@property (assign) NSString* taskMillisecondsString ;
@property (assign) BOOL displayAfterIncrementing ;
@property (assign) BOOL hideAfterEachTask ;
@property (assign) BOOL spin ;

- (IBAction)recreate:(id)sender ;

@end


#import "NSProgressBarBadnessAppDelegate.h"

@implementation NSProgressBarBadnessAppDelegate

@synthesize taskMillisecondsString = m_taskMillisecondsString ;
@synthesize displayAfterIncrementing = m_displayAfterIncrementing ;
@synthesize hideAfterEachTask = m_hideAfterEachTask ;
@synthesize spin = m_spin ;

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    // Set parameters which will trigger the problem
    // (on my Early 2006 Mac Mini running Mac OS X 10.6.2)
    [self setDisplayAfterIncrementing:YES] ;
    [self setTaskMillisecondsString:@"500"] ;
    [self setHideAfterEachTask:YES] ;
    [self setSpin:NO] ;
    
    [progressBar setIndeterminate:NO] ;
    [progressBar setUsesThreadedAnimation:YES] ;
    [NSTimer scheduledTimerWithTimeInterval:.5
                                     target:self
                                   selector:@selector(test:)
                                   userInfo:[NSNumber numberWithInt:0]
                                    repeats:NO] ;
}

- (void)test:(NSTimer*)timer {
    NSInteger i = [[timer userInfo] intValue] ;
    
    [progressBar setHidden:NO] ;
    
    NSInteger nSteps = 10 ;
    NSInteger j ;
    if ([self spin]) {
        [progressCircle startAnimation:self] ;
    }
    for (j=0; j<=nSteps; j++) {
        [progressBar setDoubleValue:nSteps*j] ;
        if ([self displayAfterIncrementing]) {
            [progressBar display] ;
        }
        usleep([[self taskMillisecondsString] intValue] * 1000/nSteps) ;
    }
    if ([self spin]) {
        [progressCircle stopAnimation:self] ;
    }
    
    if ([self hideAfterEachTask]) {
        [progressBar setHidden:YES] ;
    }
    
    [NSTimer scheduledTimerWithTimeInterval:1.0
                                     target:self
                                   selector:@selector(test:)
                                   userInfo:[NSNumber numberWithInt:(i+1)]
                                    repeats:NO] ;
}

- (IBAction)recreate:(id)sender {
    NSRect frame ;
    frame = [progressBar frame] ;
    [progressBar removeFromSuperviewWithoutNeedingDisplay] ;

    progressBar = [[NSProgressIndicator alloc] initWithFrame:frame] ;
    [progressBar setIndeterminate:NO] ;
    [[window contentView] addSubview:progressBar] ;
    [progressBar release] ;
    [progressBar setStyle:NSProgressIndicatorBarStyle] ;
    [progressBar setUsesThreadedAnimation:YES] ; 
}

@end

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to