tidev / hyperloop.next

Hyperloop Next version (we forgot the version number at this point)
Other
7 stars 4 forks source link

Issue with native UIView #359

Open alexlarocca opened 2 years ago

alexlarocca commented 2 years ago

The following code draws some shapes using Hyperloop and add them to a view. If I add and remove the shapes a couple of times, the app suddenly crashes. I do not see any error on the console.

Tested with both simulator and physical iPad with iOS 15. Ti SDK 10.1.0.GA

import {
    UIView,
    UIColor,
    UIBezierPath,
} from 'UIKit';

import {
    CoreGraphics
} from 'CoreGraphics';

import {
    CAShapeLayer
} from 'QuartzCore';

function createView() {
    const SIZE = 50;

    var bezier = UIBezierPath.alloc().init();
    bezier.moveToPoint(CoreGraphics.CGPointMake(Math.round(SIZE / 2), 0));
    bezier.addLineToPoint(CoreGraphics.CGPointMake(0, SIZE));
    bezier.addLineToPoint(CoreGraphics.CGPointMake(SIZE, SIZE));
    bezier.closePath();

    var shape = CAShapeLayer.layer();
    shape.fillColor = UIColor.redColor.CGColor;
    shape.path = bezier.CGPath;

    var view = Ti.UI.createView({width: SIZE, height: SIZE, left: 20, top: 20})
    var nativeView = UIView.cast(view);
    nativeView.layer.addSublayer(shape);

    return view;
}

var win = Ti.UI.createWindow();

var addButton = Ti.UI.createButton({top: 50, left: 100, title: 'Add'});
win.add(addButton);

var removeButton = Ti.UI.createButton({top: 50, right: 100, title: 'Remove'});
win.add(removeButton);

var container = Ti.UI.createView({
    top: 100, bottom: 0, width: Ti.UI.FILL,
    backgroundColor: 'green', layout: 'horizontal',
});
win.add(container);

addButton.addEventListener('click', function() {
    for (var i=0; i < 100; i++) {
        container.add(createView());
    }
});

removeButton.addEventListener('click', function() {
    container.removeAllChildren();
});

win.open();
alexlarocca commented 2 years ago

This is the error:

[ERROR] can't find selector layer for <null>
[ERROR] -[NSNull layer]: unrecognized selector sent to instance 0x1f48fbaa0
[ERROR] /hyperloop/uikit/uiview.js:242
[ERROR]                                 return new $imports.CALayer($dispatch(this.$native, 'layer'));
[ERROR]                                           ^
[ERROR] : -[NSNull layer]: unrecognized selector sent to instance 0x1f48fbaa0
[ERROR]     at dispatch ([native code])
[ERROR]     at get (/hyperloop/uikit/uiview.js:242:42)

And this is the code causing it:

nativeView.layer.addSublayer(shape);