Thank you for reporting this bug. We will make it our priority to review this report.
  1. #1
    Sencha User ThorstenSuckow's Avatar
    Join Date
    Sep 2007
    Location
    Aachen, Germany
    Posts
    597
    Vote Rating
    2
    ThorstenSuckow is on a distinguished road

      0  

    Default [FIXED][3.0] Ext.Container.removeAll() results in infinite loop

    [FIXED][3.0] Ext.Container.removeAll() results in infinite loop


    What steps will reproduce the problem?
    Create a container and add various components to it. Now add a "beforeremove" listener to the container and return for at least one component "false", which basically tells the container to not remove this component. Now call "removeAll()" on the container.

    What is the expected output?
    All components except for the one where the "beforeremove" listener returned "false" get removed from the container.

    What do you see instead?
    The "removeAll()" gets stuck in an infinite loop, due to

    PHP Code:
        removeAll: function(autoDestroy){
            
    this.initItems();
            var 
    itemitems = [];
            while((
    item this.items.last())){
                
    items.unshift(this.remove(itemautoDestroy));
            }
            return 
    items;
        }, 
    The condition for the while loop will always equal to true, since "this.items.last()" will reference the component for which the "beforeremove" listener returned "false".

  2. #2
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    16,995
    Vote Rating
    649
    evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute

      0  

    Default


    Fair enough, try the following patch + test case:

    Code:
    Ext.override(Ext.Container, {
        removeAll: function(autoDestroy){
            this.initItems();
            var item, rem = [], items = [];
            this.items.each(function(i){
                rem.push(i)
            });
            for (var i = 0, len = rem.length; i < len; ++i){
                item = rem[i];
                this.remove(item, autoDestroy);
                if(item.ownerCt !== this){
                    items.push(item);
                }
            }
            return items;
        }
    });
    Code:
    Ext.onReady(function(){
        var tabs = new Ext.TabPanel({
            width: 400,
            height: 400,
            renderTo: document.body,
            items: [{
                title: 'Item 1'
            },{
                title: 'Item 2'
            },{
                title: 'Item 3'
            },{
                title: 'Item 4'
            }],
            listeners: {
                beforeremove: function(ct, c){
                    return c.title != 'Item 2';
                }
            }
        });
        console.log(tabs.removeAll());
    });
    Evan Trimboli
    Sencha Developer
    Twitter - @evantrimboli
    Don't be afraid of the source code!

Thread Participants: 1