tidev/titanium-sdk

iOS 12.2.0.GA: backgroundRepeat crashes app

jonasfunk opened this issue · 14 comments

I have searched and made sure there are no existing issues for the issue I am filing

  • I have searched the existing issues

Description

Setting backgroundRepeat on a view will crash app

[ERROR] Application received error: UIGraphicsBeginImageContext() failed to allocate CGBitampContext: size={0, 0}, scale=3.000000, bitmapInfo=0x2002. Use UIGraphicsImageRenderer to avoid this assert.
[ERROR]     0   CoreFoundation                      0x00000001804658a8 __exceptionPreprocess + 172
[ERROR]     1   libobjc.A.dylib                     0x000000018005c09c objc_exception_throw + 56
[ERROR]     2   Foundation                          0x0000000180cf3b90 -[NSMutableDictionary(NSMutableDictionary) classForCoder] + 0
[ERROR]     3   UIKitCore                           0x0000000116b90f68 _UIGraphicsBeginImageContextWithOptions + 564
[ERROR]     4   TitaniumKit                         0x000000010665f060 -[TiUIView renderRepeatedBackground:] + 248
[ERROR]     5   TitaniumKit                         0x000000010665f2c4 -[TiUIView setBackgroundImage_:] + 344
[ERROR]     6   TitaniumKit                         0x0000000106683bd0 DoProxyDelegateReadValuesWithKeysFromProxy + 424
[ERROR]     7   TitaniumKit                         0x000000010666c9ec -[TiViewProxy firePropertyChanges] + 68
[ERROR]     8   TitaniumKit                         0x000000010666b754 -[TiViewProxy view] + 200
[ERROR]     9   TitaniumKit                         0x000000010666b7c4 -[TiViewProxy view] + 312
[ERROR]     10  TitaniumKit                         0x000000010664a78c -[TiWindowProxy openOnUIThread:] + 56
[ERROR]     11  libdispatch.dylib                   0x00000001801424f4 _dispatch_call_block_and_release + 24
[ERROR]     12  libdispatch.dylib                   0x0000000180143d3c _dispatch_client_callout + 16
[ERROR]     13  libdispatch.dylib                   0x0000000180152b24 _dispatch_main_queue_drain + 1272
[ERROR]     14  libdispatch.dylib                   0x000000018015261c _dispatch_main_queue_callback_4CF + 40
[ERROR]     15  CoreFoundation                      0x00000001803c61b4 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
[ERROR]     16  CoreFoundation                      0x00000001803c08cc __CFRunLoopRun + 1936
[ERROR]     17  CoreFoundation                      0x00000001803bfd28 CFRunLoopRunSpecific + 572
[ERROR]     18  GraphicsServices                    0x000000018986ebc0 GSEventRunModal + 160
[ERROR]     19  UIKitCore                           0x0000000116fdffdc -[UIApplication _run] + 868
[ERROR]     20  UIKitCore                           0x0000000116fe3c54 UIApplicationMain + 124
[ERROR]     21  listViewWithVideo                   0x00000001021fcbf0 main + 848
[ERROR]     22  dyld                                0x0000000102729558 start_sim + 20
[ERROR]     23  ???                                 0x00000001028b1f28 0x0 + 4337639208
[ERROR]     24  ???                                 0x0a38800000000000 0x0 + 736479276563431424

Expected Behavior

backgroundImage should repeat

Actual behavior

App crashes

Reproducible sample

const tabGroup = Ti.UI.createTabGroup();

tabGroup.addTab(createTab('Tab 1', 'I am Window 1', 'assets/images/tab1.png'));
tabGroup.addTab(createTab('Tab 2', 'I am Window 2', 'assets/images/tab2.png'));

tabGroup.open();

function createTab(title, message, icon) {
    const window = Ti.UI.createWindow({
        backgroundColor: 'backgroundColor',
        title: title
    });

    const view = Ti.UI.createView({
        backgroundImage: 'assets/images/tab1.png',
        backgroundRepeat: true,
        height: 50,
    });

    window.add(view);

    return Ti.UI.createTab({
        title: title,
        icon: icon,
        window: window
    });
}

Steps to reproduce

Run sample

Platform

iOS

SDK version you are using

SDK 12.2.0.GA

Alloy version you are using

No response

m1ga commented

works fine here:

2023-09-28_18-58

note: had to change createTab(...) to function createTab(...). Tested 12.1.2 and 12.2.0

Weird, crashes both our app and this test app 🤔.

m1ga commented

Xcode 14.3.1, macOS 13.4.1, Intel Mac. Perhaps that makes a difference?

Xcode 15, macOS 13.6, M1 here

Also running into this issue when backgroundRepeat is used. Only affecting simulators currently though.

m1ga commented

There is an issue at https://developer.apple.com/forums/thread/733326 about that error from React users

“Fixed it” by programmatically repeating the image. Luckily we only use it a single place in the app.

m1ga commented

UIGraphicsBeginImageContextWithOptions is deprecated use UIGraphicsImageRenderer, this occurs on ios >= 17 both simulator and phones

https://developer.apple.com/documentation/uikit/1623912-uigraphicsbeginimagecontextwitho?language=objc

But it says "up to 17" in the docs. Still something that should be change

@jonasfunk Can you attach how it looked pre-iOS 17? I think I fixed it (by moving the whole drawing logic to the UIGraphicsImageRenderer API, it looks like this:

But before drafting the PR, I'd want to be sure that it's what you expect! :-)

Yes, that is what I would expect :).
All my stuff has been updated to iOS 17, so I'm not able to provide a provide a sample of how it looked before iOS 17. But I would expect that my example should look like the example provided by @m1ga. And your example looks a lot like that.

Can someone please verify the above fix? We plan a 12.2.1 today and I'd love to include this :-)

m1ga commented

I'll see how fast I can install Xcode 15 then I can verify it

m1ga commented

@hansemannn Yes it works fine:

  • Xcode 15, 12.2.0.GA = crash
  • Xcode 15, this PR = no crash and I see the same pattern as with Xcode 14.3.1 (image in my first comment above)