Error in iOS10

Code that previously worked fine, now emitts error after presenting drawable:


func draw() {
...
mainCommandBuffer.present(currentDrawable)
mainCommandBuffer.commit()
}


EXC_BAD_ACCESS on [CAMetalDrawable present]

with log error message:

[CAMetalLayerDrawable texture] should not be called after presenting the drawable.


There is no other info, and I have no idea what to try to fix. I'm no not calling "texture" after presenting drawable, it is last line in the method.

Does someone have a clue?


Thanks

Hi Nemesis,


I have the exact same issu since iOS 10. If you find something please post the answer.


Thanks

"Hi Again,


For me, it was just because I did not call draw() method after presenting the drawable.

What Apple documentation says about currentDrawable property of MTKView => "This value is updated at the end of every call to draw()." So once presented, the draw() method should be called in order to update the currentDrawable.


Your peace of code do not give me context enough to help you but I'm pretty sure that it's the same idea for you


Regards,


Damien

You should only call need to call

draw()
if you've disabled the display link timer in the view (for example, by setting its
isPaused
property to
true
). Otherwise, the
MTKView
's delegate's
draw(in:)
method will be called, or if the view doesn't have a delegate, its own
draw(:)
method is called. All of your drawing should happen in the scope of one of these two methods. If you need to manually call
draw()
while the view is configured to draw automatically, that may indicate a problem with where/how you're doing your drawing.

Thank you wcm.


Yes it's the case. For the moment I'm calling draw() method manually and set isPaused to true. In fact I'm generating and processing images from raw data and show them on the flight in the MTKView. The image generation rate was greater than the GTKView configured framerate and the crashe was because I tried to present the same drawable twice.


Do you think that calling draw() method manually causes perfomance issue ? If so, should I present my drawable inside an overidden draw() method ?


Thanks

Hey wcm,

In my case it is not related to draw() call, but I discovered that it may be somehow related to view resize. If one is not attempting to change size of the view rendering works, but at the moment when view frame is changed error pops up.

Calling

draw()
manually doesn't have any negative performance implications; it's a legitimate way to use
MTKView
when you're not using its built-in timer. My point above was that you shouldn't need to manually call
draw()
if you're already getting regular callbacks to your
draw(:)
or
draw(in:)
methods, and that you should do all drawing and presentation in those methods or methods called by those methods.

This may indicate that something regressed between iOS 9 and iOS 10. Can you please file a bug report with a version of your project that reproduces this issue?

Are there any more updates to this thread ?

I am facing the same issue in my project where I am using MTKView. ( used to work earlier on iOS 9.3, XCode 7.3.1 and now crashes with that


EXC_BAD_ACCESS on [CAMetalDrawable present]

with log error message:

[CAMetalLayerDrawable texture] should not be called after presenting the drawable.

The MTKView bounds are not being resized, neither am I calling draw() manually. There is no delgate set on MTKView so I guess I am falling back to MTKView's draw method.


// general calls

draw()

{

...

id<CAMetalDrawable> drawable = mView.currentDrawable;

...

[commandBuffer presentDrawable:drawable];

[commandBuffer commit];

}

I never saw any bug reports related to this issue, so it hasn't been investigated. If you want to file a report and mention the number here, we can take a look.

Sure. Will file a bug report. Quick update : I swapped out my MTKView with a simple UIView embedded with a CAMetalLayer, and adjust a few initialization lines accordingly and the code works very well.

I don't know if it helps anyone, but I just started getting this error after overriding an MTKView's draw() method rather than draw(_ rect:), all other things equal.

Error in iOS10
 
 
Q