I am new to the Mac world and am seeing some behavior that is puzzling to me. I am working on a basic full screen utility that will capture the main display of the Mac and display some text. The problem I am having is that if I capture the display multiple times, after the first time the text that I am writing the the contextRef begins to degrade at the beginning of the line each time it is written. The first time it might be that the fill doesn't get drawn in the first letter, after that whole sections of the text at the beginning of the line disappear. The code I am using is as follows:
CGDisplayCapture(kCGDirectMainDisplay);
CGDirectDisplayID display = kCGDirectMainDisplay;
CGContextRef ctx = CGDisplayGetDrawingContext (display);
CGContextSelectFont (ctx, "Times-Roman", 48, kCGEncodingMacRoman);
CGContextSetTextDrawingMode (ctx, kCGTextFillStroke);
CGContextSetRGBFillColor (ctx, 1, 1, 1, 0.75);
CGContextSetRGBStrokeColor (ctx, 1, 1, 1, 0.75);
CGContextShowTextAtPoint (ctx, 400, 400, text, strlen(text));
I have found that if I put a '[NSThread sleepForTimeInterval:0.25]' before the CGContextShowTextAtPoint that the text would always display properly but that is what I would consider a hack.
My question for those who are smarter then I is, what is going on to cause the problem and is there something different that I should be doing to try and resolve it?
TIA,
JT