How to identify an "invalid option" on Mac OS X?

I have been working on a cross-platform application that is over ten years old. The user interface is Qt, and the backend rendering is with OpenGL. OpenGL contexts are managed at the end, not Qt.

I recently added error checking and reporting for all OpenGL code in our application. Sometimes a situation arises when the first render triggered by Qt causes an "invalid result" error message in the terminal, and all subsequent OpenGl calls terminate with an "invalid framebuffer" error message. These invalid output error messages were considered harmless in the past, because before the user sees this, he will eventually become valid and the scene will be displayed correctly. However, with the new OpenGL error checking / reporting, this is not possible, since a large number of errors are reported.

I would like to check if the valid value is valid. If this is not the case, he should return before the start of the render. How can I verify that a valid value is valid?

MacBook Pro, OS X Mountain Lion (10.8.3), ati graphics card

+4
source share
2 answers

I do not know at what level of API you are working. I am not sure that you can detect the problem after the fact. That is, if all you have is a context (possibly implicit, like the current thread) that could not connect to its capabilities.

I believe Qt uses Cocoa under the hood. I also assume that he created NSOpenGLContext and calls -setView: on it. You get this error with an invalid subtraction if the browser does not have a window device during this call.

One of the common ways is to postpone the setting of the contextual representation until -drawRect: appears on it, since at this moment you are sure that there is a window in the window and there is a device in the window. (Although this ignores the ability to force a -cacheDisplayInRect:toBitmapImageRep: outside the normal window display mechanism. For example, -cacheDisplayInRect:toBitmapImageRep: )

If you just want to know at the dial-up point -setView: whether it is safe or not, I think you can rely on checking the [[view window] windowNumber] . The docs for -windowNumber say:

If the window does not have a window device, the return value will be equal to or less than 0.

Another approach is to prevent the problem, not detect it. The strategy for this is to make sure that the window has been shown and drawn before calling -setView: You can force this by ordering it on the screen and invoking -display on it.

+4
source

The Ken Thomases post provided me with the basic information I needed to find a workable solution. An additional condition is required. Here is what worked

 //---------------------------------------------------------------------------- bool vtkCocoaRenderWindow::IsDrawable() { // you must initialize it first // else it always evaluates false this->Initialize(); // first check that window is valid NSView *theView = (NSView*)this->GetWindowId(); bool win =[[theView window] windowNumber]>0; // then check that the drawable is valid NSOpenGLContext *context = (NSOpenGLContext *)this->GetContextId(); bool ok = [context view] != nil; return win && ok; } 
0
source

All Articles