I have a program playing quartz compositions in QCViews. Because the QCViews are on a secondary screen, I need to display a (smaller) copy in the main screen (kind of control screen).
So I fire a timer every 0.1 seconds, take a snapshot of the QCView an set the resulting image in a NSImageView.
My problems :
The snapshot is correct about 90 % of the time but sometimes goes blank. Once this happens all snapshots taken from this QCView are blank until there is a stopRendering / startRendering. This happens even as in the same time another QCView with exactly the same composition is running and delivering good snapshots.
The snapshots seem to be out of sync with the QCView. I tried to fire the timer with a higher frequency but it did not change anything (I mention this in case it could be related to my main problem of blank images).
Any ide开发者_开发问答as or pointers ?
EDIT:
I tried to reproduce : created a minimal project then copy pasted my code :
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSRect r = NSMakeRect(0, 0, nb * 101, 101 );
feedbackwindow = [[[NSWindow alloc] initWithContentRect: r
styleMask: NSResizableWindowMask
backing: NSBackingStoreBuffered
defer: NO ] retain ];
for ( int n = 0; n < nb; n++ )
{
v[n] = [[[QCView alloc] init] autorelease];
[v[n] setFrame: NSMakeRect( 101 * n, 0, 100, 100 ) ];
[[window contentView] addSubview: v[n]];
if(![v[n] loadCompositionFromFile:[[NSBundle mainBundle] pathForResource:@"clock" ofType:@"qtz"]]) {
NSLog(@"Could not load composition");
}
[v[n] startRendering];
img[n] = [[[NSImageView alloc] init] autorelease];
[img[n] setFrame: NSMakeRect(101 * n, 0, 100, 100 ) ];
[[feedbackwindow contentView] addSubview: img[n]];
}
[feedbackwindow orderFront:nil];
[window orderFront:nil];
[self setFeedbackTimer: [NSTimer scheduledTimerWithTimeInterval: ( 0.01 )
target: self
selector: @selector(updateImage)
userInfo: nil
repeats: YES ]];
}
- (void) updateImage
{
for ( int n = 0; n < nb; n++ )
{
NSImage* snapshot = [v[n] snapshotImage];
[img[n] setImage: snapshot];
}
}
Alas I don't get the problem...
The snapshots are out of date from the QCViews but perfectly good :(
It seems that the snapshot retrieve the previous image instead of the current one : I made a simple Quartz Composer clock with "system time" -> "time formatter (format = ss)" -> "image with string" -> "sprite" and the snapshot are exactly one second late : they change at the same time as the original clock but display the previous image ...
Sounds like a bug too but probably not the same one that causes invalid images ...
精彩评论