GLKView drawInRect not being called

This worked before the latest XCode 9 beta 2. I have to presume it's something to do with the opengl performance problems there's been with the simulator.


Now it seems to be called sometimes, but something happens, and then it's not working. I haven't yet tracked down the something.

Answered by SeriousCyrus in 271847022

Figured it out, it was really simple. I was setting up my openGL in the viewWillApear method. I moved the openGL setup methods to the viewDidLoad method, and the drawing methods are being called again. Something changed, but I can't fault Apple for it...

I added a github example. Just run the app with a simulator.


https://github.com/seriouscyrus/GLKViewControllerBug


GLKView delegate is set and should be working.


The output should show the method being called, it does not.

I think I see where Apple has gone wrong....


I started looking in to the docs, I think someone read the GLKViewController docs and saw that drawing is done in the display method of it's view.


To do drawing in the display method, you need to subclass the GLKView.


Check the GLKView documentation, and it states you don't need to subclass GLKView, you can use the GLKViewDelegate methods instead. The GLKViewController even automatically sets a view's delegate to itself when a view is assigned to it. If you drop a GLKViewController into the storyboard it's automatically setup as such.


Someone obviously didn't see this. If I implement a subclass of the GLKView, I see it call it's display method every frame. Somewhere in the latest beta, the GLKViewDelegate was forgotten.


EDIT:

Just did some more checking. If you do create a GLKView subclass, the only method in the template is a commented out drawRect: method, that you should uncomment to implement custom drawing. (Not the display method).


Uncomment that method, and that's not called either.

I've raised 2 bugs.

One dealing directly with the GLKViewDelegate method not being called: 35030748

And one dealing with the unclear documentation for glkviewcontroller: 35073190

Well, I thought it was me and setup a demo project, but I forgot to set the EAGLContext on the view (I thought it did it automatically). Once you set the EAGLContext on the GLKView, it starts calling the proper methods.


Why it's not happening in my own application I don't know yet. I definitely set the contexts as I use share groups,

Accepted Answer

Figured it out, it was really simple. I was setting up my openGL in the viewWillApear method. I moved the openGL setup methods to the viewDidLoad method, and the drawing methods are being called again. Something changed, but I can't fault Apple for it...

GLKView drawInRect not being called
 
 
Q