Skip to content

[iOS] EXC_BAD_ACCESS in CGFontStrikeRelease on background entry due to missing @autoreleasepool in _initWithString (Device-ios.mm) #3291

Description

@udirub
  • axmol version: 2.11.3
  • developing environments
    • Xcode version: 26.6

I have been getting many crashes from my users. I've attached 2 photos of their stack trace. It does not seem to originate in my code.
I have not been able to reproduce the crash but Claude pinpointed a cause with a simple fix so I wanted to share it with you and see if it should be included. I've also added an image of what Claude changed.

Here are Claude's remarks:

Root cause: _initWithString in Device-ios.mm􀰓 creates UIFont, NSAttributedString, and other ObjC objects with no surrounding @autoreleasepool. These objects drain lazily with the main run loop's pool, leaving CoreText's CGFontStrike cache with dangling pointers. When _applicationDidEnterBackground fires CTFontRemoveFromCaches, it follows the corrupted pointer and crashes at 0x2 in block_free.

Fix (two changes in _initWithString):

  1. Wrap the function body in @autoreleasepool {} so all ObjC font objects are released immediately after rendering
  2. Fix the NSString* str leak — [[NSString alloc] initWithBytes:...] was never released; changed to [[[NSString alloc] ...] autorelease]

Evidence: 700+ unique device crashes across iOS 18 and iOS 26, back to at least app version 3.1, all with identical stack signature (CGFontStrikeRelease → CGFontCacheRemoveFont → CTFontRemoveFromCaches → _applicationDidEnterBackground).

Image Image Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions