Skip to content

some strange 'margin of undefined' error I'm getting #52

Description

@kylebakerio

the library looks for 'childGuiItem' and tries to get the margin values for it, and fails, because childGuiItem is undefined. Throws several errors in my console. Library keeps working ok, though, just don't want the errors showing up.

in aframe-gui-component init for: command-menu-container
aframe-gui.js:1086 Uncaught TypeError: Cannot read property 'margin' of undefined
    at NewComponent.init (aframe-gui.js:1086)
    at HTMLElement.<anonymous> (aframe-gui.js:1158)
    at HTMLElement.emit (a-node.js:263)
    at emitLoaded (a-node.js:128)
} else if (this.data.flexDirection == 'column') {
            // first figure out cursor position on main Y axis
            if (this.data.justifyContent == 'flexStart') {
                cursorY = 0;
            } else if (this.data.justifyContent == 'center' || this.data.justifyContent == 'flexEnd') {
                var columnHeight = 0;
                for (var i = 0; i < this.children.length; i++) {
                    var childElement = this.children[i];
                    //console.log("childElement: "+childElement);
                    var childGuiItem = childElement.getAttribute("gui-item");
                    //console.log("childGuiItem: "+childGuiItem);
                    columnHeight = columnHeight + childGuiItem.margin.x + childGuiItem.height + childGuiItem.margin.z;
                }
                if (this.data.justifyContent == 'center') {
                    cursorY = (containerGuiItem.height - columnHeight) * 0.5;
                } else if (this.data.justifyContent == 'flexEnd') {
                    cursorY = containerGuiItem.height - columnHeight;
                }
            }
            // then figure out baseline / cursor position on cross X axis
            if (this.data.alignItems == 'flexStart') {
                cursorX = 0; // baseline is left
            } else if (this.data.alignItems == 'center') {
                cursorX = containerGuiItem.width * 0.5; // baseline is center
            } else if (this.data.alignItems == 'flexEnd') {
                cursorX = 0; // baseline is right
            }
        }

This is the line out of the above that fails:

columnHeight = columnHeight + childGuiItem.margin.x + childGuiItem.height + childGuiItem.margin.z;

my code is dynamically generating all menu content, in this case my 'command menu' looks like this:

command-menu

Can give more detailed info if requested

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions