titanium-sdk icon indicating copy to clipboard operation
titanium-sdk copied to clipboard

iOS: setting TabGroup `navTintColor` will crash on start

Open m1ga opened this issue 8 months ago • 1 comments

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

  • [x] I have searched the existing issues

Description

There was a change after 12.2.0 for the navTintColor: https://github.com/tidev/titanium-sdk/pull/13917 A user on slack reported a crash with TabGroups that I can reproduce when setting the navTintColor in the TabGroup.

Expected Behavior

don't crash

Actual behavior

crash with

Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   libobjc.A.dylib               	       0x180069684 objc_release + 16
1   libobjc.A.dylib               	       0x1800926dc AutoreleasePoolPage::releaseUntil(objc_object**) + 212
2   libobjc.A.dylib               	       0x1800925a0 objc_autoreleasePoolPop + 256
3   CoreFoundation                	       0x1804de418 _CFAutoreleasePoolPop + 28
4   CoreFoundation                	       0x1804274a8 __CFRunLoopPerCalloutARPEnd + 44
5   CoreFoundation                	       0x180422a18 __CFRunLoopRun + 1952
6   CoreFoundation                	       0x180421e3c CFRunLoopRunSpecific + 536
7   GraphicsServices              	       0x190f62d00 GSEventRunModal + 164
8   UIKitCore                     	       0x185bcec98 -[UIApplication _run] + 796
9   UIKitCore                     	       0x185bd3064 UIApplicationMain + 124
10  test_ios.debug.dylib          	       0x101633fc4 __debug_main_executable_dylib_entry_point + 848 (main.m:77)
11  ???                           	       0x100bb93d8 ???
12  dyld                          	       0x100d72b4c start + 6000

Reproducible sample

var win1 = Ti.UI.createWindow({
    title: 'Blue'
});

var win2 = Ti.UI.createWindow({
    title: 'Red'
});

var tab1 = Ti.UI.createTab({
    window: win1,
		title: "win1"
}),
tab2 = Ti.UI.createTab({
    window: win2,
		title: "win2"
}),
tabGroup = Ti.UI.createTabGroup({
		tabs: [tab1, tab2],
		navTintColor:"#ff0000"   // <--------------- this will crash it
});
tabGroup.open();

Steps to reproduce

run the example code

Platform

iOS

SDK version you are using

12.6.4.GA

Alloy version you are using

No response

m1ga avatar Apr 27 '25 11:04 m1ga

is it normal that the navbar flickers when changing the tabs?

https://github.com/user-attachments/assets/4928caf4-6137-43bd-9729-2b5743a298c1

m1ga avatar Apr 27 '25 11:04 m1ga

A look at the crash log suggests that an unretained object was released.

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
...
Termination Reason: SIGNAL 11 Segmentation fault: 11

Because I ~~hate~~ don't like manual reference counting, I talked with ChatGPT... The problem of https://github.com/tidev/titanium-sdk/commit/951877b29c0655a2f2e9d053d25ddfcdf464c7dd is here: https://github.com/tidev/titanium-sdk/blob/13c868427fee3c56cdf8e0e777eb4daa50ef9a8b/iphone/TitaniumKit/TitaniumKit/Sources/Modules/TiUIWindowProxy.m#L323-L326

newColor is set to a new object if navTintColor isn't set for the window, but for the tab group. When newColor is later released in the block, it was unretained.


P.S.:

is it normal that the navbar flickers when changing the tabs?

I tried it with several iOS simulators/versions and couldn't reproduce it.

hbugdoll avatar Sep 30 '25 11:09 hbugdoll

I've tested it with an iOS 18.4 simulator and it still flickers with the code above. The navTintColor crash is fixed with your PR 👍

m1ga avatar Sep 30 '25 13:09 m1ga

I've tested it with an iOS 18.4 simulator [...] The navTintColor crash is fixed with your PR 👍

Thanks for testing!

hbugdoll avatar Sep 30 '25 21:09 hbugdoll

[...] and it still flickers with the code above.

Oops, I left out the iOS 18 simulators by mistake. Yes, this does indeed occur under iOS 18!

It's not just the navigation bar, but the entire window that is affected. Apple changed the whole transition animation between tab windows in iOS 18 :flushed:

  • https://developer.apple.com/forums/thread/763122
  • https://medium.com/@ssharyk/problems-with-uitabbarcontroller-tab-switching-in-ios-18-d6b70091c598

iOS 17:

https://github.com/user-attachments/assets/ab41ecbb-e779-4060-867e-b29eed5c33bf

iOS 18:

https://github.com/user-attachments/assets/4a09e981-3c18-43d5-9c41-f7ea8e916161

hbugdoll avatar Sep 30 '25 21:09 hbugdoll