Question

I have followed this guide.

Whereas I sincerely failed to understand what it says at point 13, I just have opened the pane of the inspector, but it doesn't say what attributes to set. However, I have copied and pasted the code in the proper classes. But it appears a normal window, without the triangle draw, just like when I make a normal program in Objective-C having an empty window.

Edit:

I thought that the problem was the initialization of the window, so I have written an awakeFromNib method to make the drawRect method start:

- (void) awakeFromNib
{
    NSRect rect=NSMakeRect(100.0, 100.0, 100.0, 100.0);
    [self drawRect: rect];
}

But at the first instruction of drawRect I get an EXC_BAD_ACCESS exception

glClearColor(0, 0, 0, 0);

Maybe the window is not initialized properly?

Était-ce utile?

La solution

You are probably segfaulting because OpenGL tries to change some state in the current context while there is no current context (because you sent -drawRect: without first setting the current context).

You shouldn't ever send -drawRect: yourself. Instead, use -setNeedsDisplay and let Cocoa set the current context and send -drawRect: for you:

- (void)awakeFromNib {
  self.needsDisplay = YES;
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top