Bug 59826 - (iOS 11) only Xamarin.iOS UITextView becomeFirstResponder crashes when UIToolbar is in the same view
Summary: (iOS 11) only Xamarin.iOS UITextView becomeFirstResponder crashes when UITool...
Status: NEEDINFO
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll (show other bugs)
Version: XI 11.0 (xcode9)
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-09-28 16:44 UTC by Shirley Gong
Modified: 2017-11-07 23:40 UTC (History)
3 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
build log info. (18.01 KB, text/plain)
2017-10-02 17:55 UTC, Shirley Gong
Details
Visual Studio for Mac info. (2.06 KB, text/plain)
2017-10-02 17:57 UTC, Shirley Gong
Details

Description Shirley Gong 2017-09-28 16:44:13 UTC
Calling UITextView becomeFirstResponder crashes when having a UIToolbar visible on the top of the screen. However, if the UIToolbar is hidden, it will not crash. Pre-iOS 11 it worked fine. After compiling with Xcode 9, it crashes consistently.

Both UITextView and UIToolbar here are both components that are from iOS native binding project.

Code around the crash is simply

```if ([textView canBecomeFirstResponder]) {
    NSLog(@"activateTextEntry canBecomeFirstResponder");

    BOOL result = [textView becomeFirstResponder]; // CRASH

    NSLog(@"activateTextEntry becomeFirstResponder %@", (result) ? @"TRUE" : @"FALSE");
}```

Here is the crash log from system. Any help is highly appreciated!

```System Integrity Protection: enabled

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

Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       KERN_PROTECTION_FAILURE at 0x00007fff54e9bff8
Exception Note:        EXC_CORPSE_NOTIFY

Termination Signal:    Segmentation fault: 11
Termination Reason:    Namespace SIGNAL, Code 0xb
Terminating Process:   exc handler [0]

VM Regions Near 0x7fff54e9bff8:
    MALLOC_SMALL           00007f8b32000000-00007f8b32800000 [ 8192K] rw-/rwx SM=PRV  
--> STACK GUARD            00007fff5169c000-00007fff54e9c000 [ 56.0M] ---/rwx SM=NUL  stack guard for thread 0
    Stack                  00007fff54e9c000-00007fff5568e000 [ 8136K] rw-/rwx SM=COW  thread 0

Application Specific Information:
CoreSimulator 494.13.6 - Device: iPhone 8 - Runtime: iOS 11.0 (15A372) - DeviceType: iPhone2017-A

Thread 0 Crashed:: tid_403  Dispatch queue: com.apple.main-thread
0   com.your-company.PDFNetiOSXamarinSample 0x000000010a7dc7a4 mono_thread_info_current + 4 (mono-threads.c:528)
1   com.your-company.PDFNetiOSXamarinSample 0x000000010a741b6c mono_reflection_type_handle_mono_type + 28 (sre.c:1617)
2   com.your-company.PDFNetiOSXamarinSample 0x000000010a742beb mono_reflection_type_get_handle + 75 (sre.c:1501)
3   com.your-company.PDFNetiOSXamarinSample 0x000000010a6a064f mono_reflection_get_custom_attrs_info_checked + 543 (custom-attrs.c:1571)
4   com.your-company.PDFNetiOSXamarinSample 0x000000010a6a08ce mono_reflection_get_custom_attrs_by_type + 30 (custom-attrs.c:1679)
5   com.your-company.PDFNetiOSXamarinSample 0x000000010a6b7728 custom_attrs_get_by_type + 104 (icall.c:7748)

Thread 1:
0   libsystem_kernel.dylib          0x00000001165dbdf6 __recvfrom + 10
1   com.your-company.PDFNetiOSXamarinSample 0x000000010a7fe822 recv_uninterrupted(int, void*, int) + 66 (monotouch-debug.m:732)
2   com.your-company.PDFNetiOSXamarinSample 0x000000010a7fead7 monotouch_process_connection(int) + 119 (monotouch-debug.m:1234)
3   com.your-company.PDFNetiOSXamarinSample 0x000000010a7fe352 monotouch_connect_wifi(NSMutableArray*) + 2706 (monotouch-debug.m:1018)
4   com.your-company.PDFNetiOSXamarinSample 0x000000010a7fcfd1 monotouch_configure_debugging + 3329 (monotouch-debug.m:676)
5   com.your-company.PDFNetiOSXamarinSample 0x000000010a7f2881 -[CocoaThreadInitializer entryPoint:] + 97 (shared.m:132)
6   com.apple.Foundation            0x000000010d3f68ac __NSThread__start__ + 1197
7   libsystem_pthread.dylib         0x000000011661093b _pthread_body + 180
8   libsystem_pthread.dylib         0x0000000116610887 _pthread_start + 286
9   libsystem_pthread.dylib         0x000000011661008d thread_start + 13

Thread 2:
0   libsystem_kernel.dylib          0x00000001165dc44e __workq_kernreturn + 10
1   libsystem_pthread.dylib         0x0000000116610621 _pthread_wqthread + 1426
2   libsystem_pthread.dylib         0x000000011661007d start_wqthread + 13

Thread 3:: SGen worker
0   libsystem_kernel.dylib          0x00000001165dbbf2 __psynch_cvwait + 10
1   libsystem_pthread.dylib         0x00000001166117fa _pthread_cond_wait + 712
2   com.your-company.PDFNetiOSXamarinSample 0x000000010a7c6fbe thread_func + 654 (mono-os-mutex.h:173)
3   libsystem_pthread.dylib         0x000000011661093b _pthread_body + 180
4   libsystem_pthread.dylib         0x0000000116610887 _pthread_start + 286
5   libsystem_pthread.dylib         0x000000011661008d thread_start + 13

Thread 4:: Finalizer
0   libsystem_kernel.dylib          0x00000001165d4386 semaphore_wait_trap + 10
1   com.your-company.PDFNetiOSXamarinSample 0x000000010a6b1f7f finalizer_thread + 271 (mono-os-semaphore.h:91)
2   com.your-company.PDFNetiOSXamarinSample 0x000000010a758963 start_wrapper + 675 (threads.c:829)
3   libsystem_pthread.dylib         0x000000011661093b _pthread_body + 180
4   libsystem_pthread.dylib         0x0000000116610887 _pthread_start + 286
5   libsystem_pthread.dylib         0x000000011661008d thread_start + 13

Thread 5:: Debugger agent
0   libsystem_kernel.dylib          0x00000001165dbdf6 __recvfrom + 10
1   com.your-company.PDFNetiOSXamarinSample 0x000000010a7fe822 recv_uninterrupted(int, void*, int) + 66 (monotouch-debug.m:732)
2   com.your-company.PDFNetiOSXamarinSample 0x000000010a7fe92e sdb_recv(void*, int) + 46 (monotouch-debug.m:762)
3   com.your-company.PDFNetiOSXamarinSample 0x000000010a59e726 debugger_thread + 566 (debugger-agent.c:1552)
4   com.your-company.PDFNetiOSXamarinSample 0x000000010a758963 start_wrapper + 675 (threads.c:829)
5   libsystem_pthread.dylib         0x000000011661093b _pthread_body + 180
6   libsystem_pthread.dylib         0x0000000116610887 _pthread_start + 286
7   libsystem_pthread.dylib         0x000000011661008d thread_start + 13

Thread 6:: tid_2c0b
0   libsystem_kernel.dylib          0x00000001165dbf46 __semwait_signal + 10
1   libsystem_c.dylib               0x00000001162baec0 nanosleep + 199
2   libsystem_c.dylib               0x00000001162badb4 usleep + 53
3   com.your-company.PDFNetiOSXamarinSample 0x000000010a7f5930 pump_gc(void*) + 64 (runtime.m:1053)
4   libsystem_pthread.dylib         0x000000011661093b _pthread_body + 180
5   libsystem_pthread.dylib         0x0000000116610887 _pthread_start + 286
6   libsystem_pthread.dylib         0x000000011661008d thread_start + 13

Thread 7:
0   libsystem_pthread.dylib         0x0000000116610070 start_wqthread + 0
1   ???                             0x000070000257fbd0 0 + 123145341631440

Thread 8:: com.apple.uikit.eventfetch-thread
0   libsystem_kernel.dylib          0x00000001165d434a mach_msg_trap + 10
1   libsystem_kernel.dylib          0x00000001165d3797 mach_msg + 55
2   com.apple.CoreFoundation        0x0000000110b07e85 __CFRunLoopServiceMachPort + 213
3   com.apple.CoreFoundation        0x0000000110b073c2 __CFRunLoopRun + 1730
4   com.apple.CoreFoundation        0x0000000110b06a89 CFRunLoopRunSpecific + 409
5   com.apple.Foundation            0x000000010d3e8e5e -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 274
6   com.apple.Foundation            0x000000010d4669b7 -[NSRunLoop(NSRunLoop) runUntilDate:] + 87
7   com.apple.UIKit                 0x000000010bec97e9 -[UIEventFetcher threadMain] + 118
8   com.apple.Foundation            0x000000010d3f68ac __NSThread__start__ + 1197
9   libsystem_pthread.dylib         0x000000011661093b _pthread_body + 180
10  libsystem_pthread.dylib         0x0000000116610887 _pthread_start + 286
11  libsystem_pthread.dylib         0x000000011661008d thread_start + 13

Thread 9:
0   libsystem_pthread.dylib         0x0000000116610070 start_wqthread + 0
1   ???                             0x0000f00000000005 0 + 263882790666245

Thread 10:
0   libsystem_kernel.dylib          0x00000001165dbbf2 __psynch_cvwait + 10
1   libsystem_pthread.dylib         0x00000001166117fa _pthread_cond_wait + 712
2   pdftron.com.PDFNet              0x000000010e891e41 0x10e5af000 + 3026497
3   pdftron.com.PDFNet              0x000000010e8986c6 0x10e5af000 + 3053254
4   pdftron.com.PDFNet              0x000000010e82acbd 0x10e5af000 + 2604221
5   libsystem_pthread.dylib         0x000000011661093b _pthread_body + 180
6   libsystem_pthread.dylib         0x0000000116610887 _pthread_start + 286
7   libsystem_pthread.dylib         0x000000011661008d thread_start + 13

Thread 11:
0   libsystem_kernel.dylib          0x00000001165dbbf2 __psynch_cvwait + 10
1   libsystem_pthread.dylib         0x00000001166117fa _pthread_cond_wait + 712
2   pdftron.com.PDFNet              0x000000010f170d45 0x10e5af000 + 12328261
3   pdftron.com.PDFNet              0x000000010f2ff7a4 0x10e5af000 + 13961124
4   pdftron.com.PDFNet              0x000000010f2ea91c 0x10e5af000 + 13875484
5   pdftron.com.PDFNet              0x000000010e82acbd 0x10e5af000 + 2604221
6   libsystem_pthread.dylib         0x000000011661093b _pthread_body + 180
7   libsystem_pthread.dylib         0x0000000116610887 _pthread_start + 286
8   libsystem_pthread.dylib         0x000000011661008d thread_start + 13

Thread 12:
0   libsystem_kernel.dylib          0x00000001165dbbf2 __psynch_cvwait + 10
1   libsystem_pthread.dylib         0x00000001166117fa _pthread_cond_wait + 712
2   pdftron.com.PDFNet              0x000000010f170d45 0x10e5af000 + 12328261
3   pdftron.com.PDFNet              0x000000010f3012dc 0x10e5af000 + 13968092
4   pdftron.com.PDFNet              0x000000010e82acbd 0x10e5af000 + 2604221
5   libsystem_pthread.dylib         0x000000011661093b _pthread_body + 180
6   libsystem_pthread.dylib         0x0000000116610887 _pthread_start + 286
7   libsystem_pthread.dylib         0x000000011661008d thread_start + 13

Thread 13:
0   libsystem_kernel.dylib          0x00000001165dbbf2 __psynch_cvwait + 10
1   libsystem_pthread.dylib         0x00000001166117fa _pthread_cond_wait + 712
2   pdftron.com.PDFNet              0x000000010f170d45 0x10e5af000 + 12328261
3   pdftron.com.PDFNet              0x000000010f3da989 0x10e5af000 + 14858633
4   pdftron.com.PDFNet              0x000000010e82acbd 0x10e5af000 + 2604221
5   libsystem_pthread.dylib         0x000000011661093b _pthread_body + 180
6   libsystem_pthread.dylib         0x0000000116610887 _pthread_start + 286
7   libsystem_pthread.dylib         0x000000011661008d thread_start + 13

Thread 14:
0   libsystem_kernel.dylib          0x00000001165dbbf2 __psynch_cvwait + 10
1   libsystem_pthread.dylib         0x00000001166117fa _pthread_cond_wait + 712
2   pdftron.com.PDFNet              0x000000010f170d45 0x10e5af000 + 12328261
3   pdftron.com.PDFNet              0x000000010f3daac1 0x10e5af000 + 14858945
4   pdftron.com.PDFNet              0x000000010e82acbd 0x10e5af000 + 2604221
5   libsystem_pthread.dylib         0x000000011661093b _pthread_body + 180
6   libsystem_pthread.dylib         0x0000000116610887 _pthread_start + 286
7   libsystem_pthread.dylib         0x000000011661008d thread_start + 13

Thread 0 crashed with X86 Thread State (64-bit):
  rax: 0x00007f8b2f805a28  rbx: 0x00007f8b30008000  rcx: 0x0000000000000000  rdx: 0x0000000000000000
  rdi: 0x00007f8b2f805a28  rsi: 0x00007fff54e9c140  rbp: 0x00007fff54e9c000  rsp: 0x00007fff54e9c000
   r8: 0x0000000000000040   r9: 0x00007f8b2f701338  r10: 0xffffffffffffffff  r11: 0x0000000000000000
  r12: 0x00007fff54e9c140  r13: 0x0000000124a49660  r14: 0x00007f8b2f805a28  r15: 0x00007fff54e9c140
  rip: 0x000000010a7dc7a4  rfl: 0x0000000000010202  cr2: 0x00007fff54e9bff8

Logical CPU:     2
Error Code:      0x00000006
Trap Number:     14```
Comment 1 Shirley Gong 2017-09-28 16:45:23 UTC
I tried to wrap the binded version of the UIToolbar in a Xamarin UIView, that worked well. Although I lost all the APIs for UIToolbar.
Any help is greatly appreciated. Thanks.
Comment 2 Timothy Risi 2017-09-28 18:13:01 UTC
Please include your full build logs, crash reports (if any), test case (to reproduce) and all version information.

To get full build logs just set the log verbosity to diagnostic at the following locations:
- On Visual Studio for Mac: Preferences > Projects > Build
- On Visual Studio for Windows: Tools > Options > Projects and Solutions > Build and Run

On Visual Studio Windows you also want to add `-v -v -v -v` to the mtouch additional arguments by right-clicking the project in the solution explorer and selecting `Properties`.
Note: this is done automatically on Visual Studio for Mac when the log verbosity is set to diagnostic.

Easiest way to get exact version information:
- On Visual Studio for Mac: "Visual Studio" menu, "About Visual Studio" item, "Show Details" button.
- On Visual Studio for Windows: "Help menu", "About Microsoft Visual Studio" item.
Then copy/paste the version information (you can use the "Copy Information" button).
Comment 3 Shirley Gong 2017-10-02 17:55:51 UTC
Created attachment 25055 [details]
build log info.
Comment 4 Shirley Gong 2017-10-02 17:57:23 UTC
Created attachment 25056 [details]
Visual Studio for Mac info.
Comment 5 Alex Soto [MSFT] 2017-11-07 06:09:21 UTC
Hello Shirley, this sounds like an Apple change, could you create a very minimal test case showing this issue in both Xcode and Xamarin?
Comment 6 Shirley Gong 2017-11-07 19:42:51 UTC
Hi Alex,

Thanks for your advice!

I tried to expose the selector, that did not work.
I am comparing the working vs the not working menu items now to see what I can find.

However, would it be possible if you could give me some hint on why the same binding project works fine in a pure Xamarin.iOS sample (which is just a simple UIViewController), but not working in Xamarin.Forms context?

Thanks very much for your help!
Comment 7 Alex Soto [MSFT] 2017-11-07 20:10:20 UTC
Hello Shirley

> why the same binding project works fine in a pure Xamarin.iOS sample
> (which is just a simple UIViewController), but not working in Xamarin.Forms context?

Because UIViewController is that, a plain UIViewController, no extra layer of anything, my guess is that X.F PageRenderer[1] which is a subclass of UIViewController is hooking up into something that PDFtron needs but since I do not know the internals of PDFTron I can't really pinpoint you onto something, I would suggest you to have a look at X.F PageRenderer source[1] and see if you find anything that could interfere with PDFTron's logic.

There is really nothing special about PageRenderer from the native perspective, it is just a UIViewController subclass FWICT.

[1]: https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Platform.iOS/Renderers/PageRenderer.cs
Comment 8 Shirley Gong 2017-11-07 23:40:03 UTC
(Sorry my previous message is in wrong thread. Was meant for https://bugzilla.xamarin.com/show_bug.cgi?id=60533)

Note You need to log in before you can comment on or make changes to this bug.