-1

I am developing GL paint application.

To paint any object, I am using UIView that implemented.

Starting paint method :

- (void)viewDidLoad {
    ....
    [NSThread detachNewThreadSelector:@selector(paintingObjects) 
                             toTarget:self
                           withObject:nil];
}

- (void)paintingObjects {
    while(1) {
        [NSThread sleepForTimeInterval:2];
        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
        ImplementedView *tmp = [self view];
        [tmp draw];
        [pool drain];
    }
}

But it is not working (doesn't paint object).

What is wrong here ?

Please help me guys.

Thanks in advance.

rpetrich
  • 32,196
  • 6
  • 66
  • 89
Ferdinand
  • 1,193
  • 4
  • 23
  • 43

1 Answers1

1

All user-interface classes are not thread-safe and must be called from the main thread:

- (void)paintingObjects {
    while(1) {
        [NSThread sleepForTimeInterval:2];
        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
        ImplementedView *tmp = [self view];
        [tmp performSelectorOnMainThread:@selector(draw) withObject:nil waitUntilDone:YES];
        [pool drain];
    }
}

In this case, you would likely be better off using NSTimer.

rpetrich
  • 32,196
  • 6
  • 66
  • 89