Skip to content

Commit

Permalink
Merge pull request #1711 from bryan-m-hughes/timob-8065
Browse files Browse the repository at this point in the history
[TIMOB-8065] Implemented checks against laying out destroyed children.
  • Loading branch information
cb1kenobi committed Mar 18, 2012
2 parents 7901edb + ef27093 commit f7a741b
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 36 deletions.
4 changes: 2 additions & 2 deletions mobileweb/titanium/Ti/UI/TableViewSection.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ define(["Ti/_/declare", "Ti/_/lang", "Ti/_/UI/Widget", "Ti/_/style","Ti/UI/Mobil
return;
}
this._rows.children[2 * index + 1]._tableViewSection = null;
this._rows.remove(this._rows.children[2 * index + 1]);
this._rows.remove(this._rows.children[2 * index + 1]);
this._rows.remove(this._rows.children[2 * index + 1]); // Remove the separator
this._rows.remove(this._rows.children[2 * index + 1]); // Remove the row

// Remove the last separator, if there are no rows left
if (this._rows.children.length === 1) {
Expand Down
1 change: 0 additions & 1 deletion mobileweb/titanium/Ti/UI/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ define(["Ti/_/declare", "Ti/_/dom", "Ti/_/UI/Element", "Ti/_/lang", "Ti/_/string
c = this.children.splice(0, 1);
c[0].destroy();
}
this._parent && View.prototype.remove.call(this._parent, this);
}
Element.prototype.destroy.apply(this, arguments);
},
Expand Down
5 changes: 2 additions & 3 deletions mobileweb/titanium/Ti/_/Evented.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ define(function() {
return {
destroy: function() {
for (var i in this) {
if (this.hasOwnProperty(i)) {
delete this[i];
}
delete this[i];
}
this._alive = 0;
},

addEventListener: function(name, handler) {
Expand Down
10 changes: 10 additions & 0 deletions mobileweb/titanium/Ti/_/Layouts/Base.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ define(["Ti/_/css", "Ti/_/declare", "Ti/_/style", "Ti/_/dom"], function(css, dec
css.remove(this.element.domNode, css.clean(this.declaredClass));
},

verifyChild: function(child, parent) {
if (!child._alive || !child.domNode) {
console.debug("WARNING: Attempting to layout element that has been destroyed.\n\t Removing the element from the parent.\n\t The parent has a widget ID of " + parent.widgetId + ".");
var children = parent.children;
children.splice(children.indexOf(child),1);
return;
}
return 1;
},

_computedSize: {width: 0, height: 0}

});
Expand Down
56 changes: 29 additions & 27 deletions mobileweb/titanium/Ti/_/Layouts/Composite.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,36 @@ define(["Ti/_/Layouts/Base", "Ti/_/declare"], function(Base, declare) {

// Layout the child
var child = element.children[i];
if (child._markedForLayout) {
child._doLayout({
origin: {
x: 0,
y: 0
},
isParentSize: {
width: isWidthSize,
height: isHeightSize
},
boundingSize: {
width: width,
height: height
},
alignment: {
horizontal: this._defaultHorizontalAlignment,
vertical: this._defaultVerticalAlignment
},
positionElement: true,
layoutChildren: true
});
if (this.verifyChild(child,element)) {
if (child._markedForLayout) {
child._doLayout({
origin: {
x: 0,
y: 0
},
isParentSize: {
width: isWidthSize,
height: isHeightSize
},
boundingSize: {
width: width,
height: height
},
alignment: {
horizontal: this._defaultHorizontalAlignment,
vertical: this._defaultVerticalAlignment
},
positionElement: true,
layoutChildren: true
});
}

// Update the size of the component
var rightMostEdge = child._measuredWidth + child._measuredLeft + child._measuredBorderSize.left + child._measuredBorderSize.right + child._measuredRightPadding;
var bottomMostEdge = child._measuredHeight + child._measuredTop + child._measuredBorderSize.top + child._measuredBorderSize.bottom + child._measuredBottomPadding;
rightMostEdge > computedSize.width && (computedSize.width = rightMostEdge);
bottomMostEdge > computedSize.height && (computedSize.height = bottomMostEdge);
}

// Update the size of the component
var rightMostEdge = child._measuredWidth + child._measuredLeft + child._measuredBorderSize.left + child._measuredBorderSize.right + child._measuredRightPadding;
var bottomMostEdge = child._measuredHeight + child._measuredTop + child._measuredBorderSize.top + child._measuredBorderSize.bottom + child._measuredBottomPadding;
rightMostEdge > computedSize.width && (computedSize.width = rightMostEdge);
bottomMostEdge > computedSize.height && (computedSize.height = bottomMostEdge);
}
return computedSize;
},
Expand Down
2 changes: 1 addition & 1 deletion mobileweb/titanium/Ti/_/Layouts/Horizontal.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ define(["Ti/_/Layouts/Base", "Ti/_/declare", "Ti/UI"], function(Base, declare, U
if (childrenWithFillWidth) {
for (var i = 0; i < children.length; i++) {
var child = children[i];
if (child.width !== UI.FILL) {
if (this.verifyChild(child,element) && child.width !== UI.FILL) {
var childWidth;
if (child._markedForLayout) {
childWidth = child._doLayout({
Expand Down
2 changes: 1 addition & 1 deletion mobileweb/titanium/Ti/_/Layouts/Vertical.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ define(["Ti/_/Layouts/Base", "Ti/_/declare", "Ti/UI"], function(Base, declare, U
if (childrenWithFillHeight) {
for (var i = 0; i < children.length; i++) {
var child = children[i];
if (child.height !== UI.FILL) {
if (this.verifyChild(child,element) && child.height !== UI.FILL) {
var childHeight;
if (child._markedForLayout) {
childHeight = child._doLayout({
Expand Down
5 changes: 4 additions & 1 deletion mobileweb/titanium/Ti/_/UI/Element.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ define(

destroy: function() {
if (this._alive) {
this.parent && this.parent.remove(this);
this._parent && this._parent.remove(this);
if (this.domNode) {
dom.destroy(this.domNode);
this.domNode = null;
Expand Down Expand Up @@ -916,6 +916,9 @@ define(
height: this._measuredHeight
};
}
},
parent: function() {
return this._parent;
}
},

Expand Down

0 comments on commit f7a741b

Please sign in to comment.