MacOS – Various graphics-related corruption/errors/misrendering with Mountain Lion

buggraphicsmacosopencl

Since the November 2012 update to Moutain Lion, I keep getting these weird graphical issues.

The list of woes:

OpenCL crashes during application startup

Sometimes after the laptop wakes up from a long sleep, when trying to launch any applications, they all crash with the following kind of stacktrace exhibiting a problem in CoreImage/OpenCL:

Code Type:       X86-64 (Native)
Parent Process:  launchd [136]
OS Version:      Mac OS X 10.8.3 (12D68)

Crashed Thread:  0  Dispatch queue: com.apple.main-thread

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x000000010c8d0000

VM Regions Near 0x10c8d0000:
    shared memory          000000010c8c0000-000000010c8d0000 [   64K] r--/r-- SM=SHM  
--> 
    CG shared images       000000011a442000-000000011a44a000 [   32K] r--/r-- SM=SHM  

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libsystem_c.dylib               0x00007fff9371c6d3 strlen + 51
1   libsystem_c.dylib               0x00007fff9376a067 strdup + 21
2   libcldcpuengine.dylib           0x000000010c2a4e72 0x10c29e000 + 28274
3   libcldcpuengine.dylib           0x000000010c2a2ac6 glrCompBuildProgram + 96
4   com.apple.opencl                0x00007fff906cb398 0x7fff906a3000 + 164760
5   com.apple.opencl                0x00007fff906b3bc3 clBuildProgram + 904
6   com.apple.CoreImage             0x00007fff92542455 -[FEOpenCLContext _loadKernel:target:testOnly:] + 1156
7   com.apple.CoreImage             0x00007fff9263c35f -[FEContext(Kernel) loadKernel:target:] + 94
8   com.apple.CoreImage             0x00007fff9257e54f FEApplyTreeNode::render1(FETreeContext*, FEShape const&, fe_kernel_target_struct*, int, float*, FETreeTexture*) + 105
9   com.apple.CoreImage             0x00007fff9257f735 FEApplyTreeNode::render2(FETreeContext*, FEShape const*, void (*)(FEContext*, void*, FEFormat), void (*)(FEContext*, void*), void*) + 1583
10  com.apple.CoreImage             0x00007fff9257c7c7 FETreeNode::render_(FETreeContext*, FEShape const*, void (*)(FEContext*, void*, FEFormat), void (*)(FEContext*, void*), void*) + 169
11  com.apple.CoreImage             0x00007fff925804c5 FETreeNode::render(FETreeContext*, FEShape const&, void (*)(FEContext*, void*, FEFormat), void (*)(FEContext*, void*), void*) + 107
12  com.apple.CoreImage             0x00007fff92584211 FETreeContext::renderTree(FETreeNode*, FEShape const&, void (*)(FEContext*, void*, FEFormat), void (*)(FEContext*, void*), void*) + 277
13  com.apple.CoreImage             0x00007fff92584535 FETreeContext::renderImage_(FEImage*, CGRect, FEShape const*, CGAffineTransform, CGColorSpace*, FEFormat, bool, void (*)(FEContext*, void*, FEFormat), void (*)(FEContext*, void*), void*) + 703
14  com.apple.CoreImage             0x00007fff92584911 FETreeContext::renderImage(FEImage*, CGRect, FEShape const*, CGAffineTransform, CGColorSpace*, FEFormat, bool, void (*)(FEContext*, void*, FEFormat), void (*)(FEContext*, void*), void*) + 459
15  com.apple.CoreImage             0x00007fff9255b1a6 -[FEImage(Internal) _renderWithContext:bounds:transform:colorSpace:format:premultiplied:setupCallback:finishCallback:callbackData:] + 339
16  com.apple.CoreImage             0x00007fff9255a5bf -[FEImage getBitmap:withContext:origin:transform:colorSpace:] + 694
17  com.apple.CoreImage             0x00007fff9250fa9a -[CIContextImpl render:toBitmap:rowBytes:bounds:format:colorSpace:] + 427
18  com.apple.CoreImage             0x00007fff9250e968 -[CIContext render:toBitmap:rowBytes:bounds:format:colorSpace:] + 77
19  com.apple.coreui                0x00007fff938ff5fc _CUICreateImageByApplyingEffectsToImageViaCI(long, CUIDescriptor const*, __CFArray const*, CGImage*, double, unsigned char) + 16220
20  com.apple.coreui                0x00007fff938f9219 CUIArtFileRenderer::DrawImage(CGRect, long, CUIDescriptor const*) + 9651
21  com.apple.coreui                0x00007fff938e7887 CUIArtFileRenderer::Draw(CUIDescriptor const*, CGAffineTransform, CUIReturnInfo&) + 1571
22  com.apple.coreui                0x00007fff938c2895 CUIRenderer::Draw(CGRect, CGContext*, __CFDictionary const*, __CFDictionary const**) + 3343
23  com.apple.coreui                0x00007fff938edbcb CUIDraw + 180

Model: MacBookAir5,2, BootROM MBA51.00EF.B02, 2 processors, Intel Core i7, 2 GHz, 8 GB, SMC 2.5f7
Graphics: Intel HD Graphics 4000, Intel HD Graphics 4000, Built-In, 512 MB

(Crash report snipped for convenience)

Graphical corruption

I experience the same graphic artefacts (white noise) corruption overlayed on different UI elements like opened windows, the Finder icons in the Cmd+Tab list, background image,… like so: Screenshot

For corrupted windows, any action that issues a repainting cures the issue but the others (Finder icon, background image) stay (probably because they never repaint) until the computer is rebooted.

Broken icons

In what is a persisting problem afterwards (even after rebooting), any template icons (or otherwise shader-processed-behind-the-scenes icons) disappear from places like status bar/toolbar/side-panels:

Toolbar area screenshot

For this last one, the usual tricks of creating a new user or reinstalling a prior version work in the beginning but the issue resurfaces later.

Since I have FileVault turned on, I also can't seem to be able to boot into safe mode to flush the icon caches manually (same 25-30% stuck loading bar problem than described elsewhere).

Cleaning whatever other Caches folder I can find doesn't help either.

Now, the interesting thing is that problem 1 and problem 3 are both circumvented with a simple action: running the application manually from a terminal (as in, not via open(1) i.e. not with launchd as the parent process).

In that case the icons renders perfectly and there is no weird OpenCL crash for the lifespan of that instance although it doesn't fix the problem for normally launched applications afterwards.

As I scouted the internet I couldn't find people with precisely the same set of issues so it could simply be that my machine is faulty but I'm posting here beforehand to see if anyone else has more ideas on how to diagnose the problem (and to provide a Google entry-point for it).

Best Answer

I have just experienced the same problem. I noticed graphic artefacts on my desktop, but did not worry about it until Transmission failed to start. Couple of iterations later I restarted it from iTerm (thus bypassing launchd), and it worked. I shrugged shoulders and rebooted - now that was a mistake.

Pretty much all apps that use default MacOS windows rendering engine could not start, including Finder. This meant I could not start iTerm or Terminal either. The likes of Chrome, VLC, Sonos and iTunes, which use their own window renderer, worked. I got a very similar stacktrace all the time bar the last call - not strdup, but memmove, also from stdlib. Surprisingly enough, when I tried to log in as another user, everything still worked.

I tried resetting SMC and PRAM to no avail. Then I rebooted in safe mode, in which rendering worked, and rebooted back to the normal mode. This helped. At least I can launch apps now - but Finder crashes and relaunches every now and then occasionally.