Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with native UIView #359

Open
alexlarocca opened this issue Nov 20, 2021 · 1 comment
Open

Issue with native UIView #359

alexlarocca opened this issue Nov 20, 2021 · 1 comment

Comments

@alexlarocca
Copy link
Sponsor

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
Copy link
Sponsor Author

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);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant