Skip to content

Issue with native UIView #359

@alexlarocca

Description

@alexlarocca

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions