Problem Description
We are developing a app for iOS and iPadOS that involves extensive custom drawing of paths, shapes, texts, etc. To improve drawing and rendering speed, we use CARenderer to generate cached images (CGImage) on a background thread. We adopted this approach based on this StackOverflow post: https://stackoverflow.com/a/75497329/9202699.
However, we are experiencing frequent crashes in our production environment that we can hardly reproduce in our development environment. Despite months of debugging and seeking support from DTS and the Apple Feedback platform, we have not been able to fully resolve this issue. Our recent crash reports indicate that the crashes occur when calling CATransaction.commit().
We suspect that CATransaction may not be functioning properly outside the main thread. However, based on feedback from the Apple Feedback platform, we were advised to use CATransaction.begin() and CATransaction.commit() on a background thread.
If anyone has any insights, we would greatly appreciate it.
Code Sample
The line CATransaction.commit() is causing the crash: [EXC_BREAKPOINT: com.apple.root.****-qos.cooperative]
private let transactionLock = NSLock() // to ensure one transaction at a time
private let device = MTLCreateSystemDefaultDevice()!
@inline(never)
static func drawOnCGImageWithCARenderer(
layerRect: CGRect,
itemsToDraw: [ItemsToDraw]
)
-> CGImage? {
// We have encapsulated everything related to CALayer and its
// associated creations and manipulations within CATransaction
// as suggested by engineers from Apple Feedback Portal.
transactionLock.lock()
CATransaction.begin()
// Create the root layer.
let layer = CALayer()
layer.bounds = layerRect
layer.masksToBounds = true
// Add one sublayer for each item to draw
itemsToDraw.forEach { item in
// We have thousands or hundred thousands of drawing items to add.
// Each drawing item may produce a CALayer, CAShapeLayer or CATextLayer.
// This is also why we want to utilise CARenderer to leverage GPU rendering.
layer.addSublayer(
item.createCALayerOrCATextLayerOrCAShapeLayer()
)
}
// Create MTLTexture and CARenderer.
let textureDescriptor = MTLTextureDescriptor.texture2DDescriptor(
pixelFormat: .rgba8Unorm,
width: Int(layer.frame.size.width),
height: Int(layer.frame.size.height),
mipmapped: false
)
textureDescriptor.usage = [MTLTextureUsage.shaderRead, .shaderWrite, .renderTarget]
let texture = device.makeTexture(descriptor: textureDescriptor)!
let renderer = CARenderer(mtlTexture: texture)
renderer.bounds = layer.frame
renderer.layer = layer.self
/* ********************************************************* */
// From our crash report, this is where the crash happens.
CATransaction.commit()
/* ********************************************************* */
transactionLock.unlock()
// Rendering layers onto MTLTexture using CARenderer.
renderer.beginFrame(atTime: 0, timeStamp: nil)
renderer.render()
renderer.endFrame()
// Draw MTLTexture onto image.
guard
let colorSpace = CGColorSpace(name: CGColorSpace.sRGB),
let ciImage = CIImage(mtlTexture: texture, options: [.colorSpace: colorSpace]) else {
return nil
}
// Convert CIImage to CGImage.
let context = CIContext()
return context.createCGImage(ciImage, from: ciImage.extent)
}
OpenGLES
RSS for tagCreate 3D and 2D graphics effects using OpenGL ES, a compact and efficient subset of OpenGL.
Posts under OpenGLES tag
12 Posts
Sort by:
Post
Replies
Boosts
Views
Activity
I have used the Mac M1 and M4.
Developing OpenGL projects on machines running macOS 15.2 and 13.6.
Call the OpenGL library functions of Mac.
glTexImage2D
If you use GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_ALPHA these three textures, you will get an error gl 500.
It makes me unable to draw normally on Mac.
What's the reason for this? Don't they support it?
I'm trying to build and run a Maui project but keep getting the following error:
I'm using JetBrains Rider and I have it set not to build for iOS but I can't seem to get past this message. I'm using an Apple Silicon Mac, the project is cross platform, builds and runs fine on Windows. The problem seems to be with libSDL2.a.
Has anyone encountered this error before? If so any suggestions on what to do about it?
I'm tying to build and run a Maui project on Mac and keep getting the following error:
I'm using JetBrains Rider and even though I have it set not to build for iOS I can't get past this error.
Other possibly useful infos:
OpenGL
Silk.NET
running on Apple Silicon
cross platform project, builds and runs fine on Windows
I'm trying to add an SVG image to my launch screen. The SVG image is working fine in the main storyboard also used in a UIImageView, but the launch screen remains completely black; the launch screen is set with white background, so it seems to be completely ignored. When I remove the image from the UIImageView the launch screen is shown with correct background color but of course without the whished image. I can also correctly implement text in the launch screen, the launch screen shows the text and the background color correctly. As soon as I define an image from the asset catalogue for the UIImageView in the launch screen, the launch screen is completely black not showing anything. I tried also with a simple png image-set instead of the SVG image, but still the same issue. How can I implement a SVG image in my launch screen?
Hi,
we've been developing an iOS game using OpenGL ES, trying running compatible iOS app on Vision Pro Simulator on M1 Mac, but we met a strange EXC_BAD_ACCESS crash in glDrawElements(), while the app run normally on ios or ipad simulators with the same developing environment. The stack like following:
Our Mac is a Mac Studio(2022) with Apple M1 Max and MacOS 14.1.2.
Xcode: Version 15.3 (15E204a)
Simulator OS: Vision OS 1.1
Hey folks,
I have a legacy game that is running OpenGL ES - and it no longer works on the simulators that are running Apple Silicon, ie iPhone 15 Pro, or the 13" iPads. And yes, i'm also running on Apple Silicon (M1 Max).
The apps work fine on the actual devices, but the simulator crashes on any glDrawElements with a stack that looks like the following:
I have not yet seen an announcement about this not working but i've seen mention in other apps of stopping to support GL (https://github.com/maplibre/maplibre-native/issues/2351)
Can anyone shed some light? I'm obviously going to try to fix it, or find a recent sample app from which to start to see what might be up. Or move to metal, but i hadn't bargained for that level of effort atm ;)
Any suggestions appreciated!
We’re experiencing an issue with wrong SceneKit hit testing results in iOS 17.2 compared with iOS 16.1 when using the either Metal or OpenGLES2 engines.
Tapping on a 3D model to place a SCNNode
// pointInScene: tapped point
let hitResults = sceneView.hitTest(pointInScene, options: nil)
return hitResults.first { $0.node.name?.compare("node_name") == .orderedSame }
can i use the es3.1 api in code?
Hi, I'm displaying linear gray by CAMetalLayer with the shader below.
fragment float4 fragmentShader(VertexOut in [[stage_in]],
texture2d<float, access::sample> BGRATexture [[ texture(0) ]])
{
float color = in.texCoordinates.x;
return float4(float3(color), 1.0);
}
And my CAMetalLayer has been set to linearSRGB.
metalLayer.colorspace = CGColorSpace(name: CGColorSpace.linearSRGB)
metalLayer.pixelFormat = .bgra8Unorm
Why the display seem add gamma? Apparently the middle gray is 187 but not 128.
I know opengl is marked as deprecated since ios12 but I have an old project using it and I want to update some feature of it then release the update version.
So I'm wondering if I can still release an app using opengl to app store currently?
(I know it's better to shift to MetalKit but for some reason I want to cut the cost if I can. )