0

I have an OpenGLES app, with a CADisplayLink (added in NSRunLoopCommonModes) that I use to call the main loop (where I do all the OpenGL calls).

I added a UIScrollView, but it randomly get stuck. If I send the app to the background, when I get back sometimes it works perfectly, while others it's stuck (I can sort of move it around, but it doesn't slide when you let go).

Tracking down the problem, I noticed the UIScrollView's internal funcion _smoothScrollWithUpdateTime: is not being called. Apparently it uses is own CADisplayLink to get that call. So I tried adding my own CADisplayLink (separate from the main one that does all the drawing), and it's also randomly not being called. Here is the code:

- (void) addDisplayLink
{
    displayLink = [NSClassFromString(@"CADisplayLink") displayLinkWithTarget:self selector:@selector(loop:)];
    [displayLink setFrameInterval:1];
    [displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
}

- (void) loop:(id)sender
{
    NSLog(@"Loop working!");
}

Any ideas?

TL/DR: I have two CADisplayLinks and one of them is not working.

Andres
  • 1,875
  • 1
  • 19
  • 28
  • It seems this only happens if I actually draw something in my main loop, commenting out the swap buffers line ([context_ presentRenderbuffer:GL_RENDERBUFFER_OES]) 'fixes' the problem. Of course not drawing anything is not an acceptable solution! – Andres Nov 20 '12 at 19:23
  • This sounds like a related issue to what's described here: http://stackoverflow.com/questions/5944050/cadisplaylink-opengl-rendering-breaks-uiscrollview-behaviour . My suggestion there to move your rendering to a background queue might also help you here. – Brad Larson Nov 20 '12 at 19:45
  • @BradLarson - Thanks, so if I understand your post correctly, the reason my second DisplayLink is not being called is because it takes too long for the first one to process a frame? I'm doing very little, and it takes only 6ms to process a frame (3ms CPU, 3ms GPU according to the debugger, running at 60 fps without problems). Is that enough to break it? – Andres Nov 20 '12 at 20:24
  • If everything's running on the main thread, your OpenGL ES rendering may be taking just long enough to disrupt the scrolling timer. I know that I saw some odd artifacts there before I moved all of my rendering to a background queue. – Brad Larson Nov 20 '12 at 20:29

0 Answers0