robovm icon indicating copy to clipboard operation
robovm copied to clipboard

Obtaining NSAttributedString causes crash on next GC

Open MrStahlfelge opened this issue 3 years ago • 0 comments

Issue details

When using an NSAttributedString, app crashes on next garbage collection. Until then, everything (also using the string) works as intended.

Reproduction steps/code

Use the example project and change the marked lines:

    public MyViewController() {
        // Get the view of this view controller.
        UIView view = getView();

        // Setup background.
        view.setBackgroundColor(UIColor.white());

        // Setup label.
        label = new UITextView(new CGRect(20, 250, 280, 44));
        label.setFont(UIFont.getSystemFont(24));
        label.setTextAlignment(NSTextAlignment.Center);

// added code that causes a crash on GC
        NSAttributedStringDocumentAttributes attribs = new NSAttributedStringDocumentAttributes();
        attribs.setDocumentType(NSDocumentType.HTML);
        try {
            NSAttributedString attributedString = new NSAttributedString(
                    new NSString("Just a <a href=\"https://www.google.com\">Link</a>")
                            .toData(NSStringEncoding.Unicode),
                    attribs);
// Using the string works, but the crash is reproducible even without using it.
            //label.setAttributedText(attributedString);
        } catch (NSErrorException e) {
            e.printStackTrace();
        }
// end of added code

        view.addSubview(label);

        // Setup button.
        button = new UIButton(UIButtonType.RoundedRect);
        button.setFrame(new CGRect(110, 150, 100, 40));
        button.setTitle("Click me!", UIControlState.Normal);
        button.getTitleLabel().setFont(UIFont.getBoldSystemFont(22));

// Crash on garbage collection
        button.addOnTouchUpInsideListener((control, event) -> System.gc());
        view.addSubview(button);

    }

The crash is reproducible without actually using the attributed string.

Configuration

Build Tools:

  • [X] IDEA plugin

Versions:

  • Robovm: tried with 2.3.12 and 2.3.14
  • JDK: tried with 8 and 11

Build Targets:

Tried with x86-64 Simulators for iOS 13.0, 14.0, 15.0, 14.4


Stacktrace

There is no Java stack trace, but a native crash.

Crashed Thread:        14

Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       EXC_I386_GPFLT
Exception Note:        EXC_CORPSE_NOTIFY

Application Specific Information:
objc_msgSend() selector name: release
CoreSimulator 732.18.6 - Device: iPhone 8 (75AA5440-3576-4C69-961F-29FDCFE01FB5) - Runtime: iOS 14.4 (18D46) - DeviceType: iPhone 8


Thread 14 Crashed:
0   libobjc.A.dylib               	0x00007fff2017378b objc_msgSend + 11
1   com.mycompany.myapp           	0x00000001059c31b7 0x104e61000 + 11936183
2   com.mycompany.myapp           	0x00000001059bf3ac 0x104e61000 + 11920300
3   com.mycompany.myapp           	0x0000000105541e37 [J]org.robovm.apple.foundation.NSObject.release(J)V + 60 (NSObject.java:228)
4   com.mycompany.myapp           	0x0000000105541d5c [J]org.robovm.apple.foundation.NSObject.doDispose()V + 68 (NSObject.java:212)
5   com.mycompany.myapp           	0x00000001059b9fbf [J]org.robovm.objc.ObjCObject.dispose(Z)V + 164 (ObjCObject.java:139)
6   com.mycompany.myapp           	0x00000001059b9ed1 [J]org.robovm.objc.ObjCObject.finalize()V + 22 (ObjCObject.java:126)
7   com.mycompany.myapp           	0x000000010517c90b [J]java.lang.Daemons$FinalizerDaemon.doFinalize(Ljava/lang/ref/FinalizerReference;)V + 595 (Daemons$FinalizerDaemon.java:187)
8   com.mycompany.myapp           	0x000000010517c676 [J]java.lang.Daemons$FinalizerDaemon.run()V + 176 (Daemons$FinalizerDaemon.java:170)
9   com.mycompany.myapp           	0x00000001051a158a [J]java.lang.Thread.run()V + 28 (Thread.java:837)
10  com.mycompany.myapp           	0x00000001059fcbde 0x104e61000 + 12172254
11  com.mycompany.myapp           	0x00000001059f2384 0x104e61000 + 12129156
12  com.mycompany.myapp           	0x00000001059f1fb7 0x104e61000 + 12128183
13  com.mycompany.myapp           	0x00000001059fc1a4 0x104e61000 + 12169636
14  com.mycompany.myapp           	0x0000000105a166d7 0x104e61000 + 12277463
15  com.mycompany.myapp           	0x0000000105a13828 0x104e61000 + 12265512
16  com.mycompany.myapp           	0x0000000105a17a7f 0x104e61000 + 12282495
17  libsystem_pthread.dylib       	0x00007fff6116b954 _pthread_start + 224
18  libsystem_pthread.dylib       	0x00007fff611674a7 thread_start + 15

MrStahlfelge avatar Nov 16 '21 09:11 MrStahlfelge