<commit_before>/**
 A **CubeTexture** specifies a cube texture map.

 ## Overview

 See {{#crossLink "Lights"}}{{/crossLink}} for an example of how to use CubeTextures for light and reflection mapping.

 @class CubeTexture
 @module xeogl
 @submodule lighting
 @constructor
 @param [scene] {Scene} Parent {{#crossLink "Scene"}}Scene{{/crossLink}} - creates this CubeTexture in the default
 {{#crossLink "Scene"}}Scene{{/crossLink}} when omitted.
 @param [cfg] {*} Configs
 @param [cfg.id] {String} Optional ID for this CubeTexture, unique among all components in the parent scene, generated automatically when omitted.
 @param [cfg.meta] {String:Object} Optional map of user-defined metadata to attach to this CubeTexture.
 @param [cfg.src=null] {Array of String} Paths to six image files to load into this CubeTexture.
 @param [cfg.flipY=false] {Boolean} Flips this CubeTexture's source data along its vertical axis when true.
 @extends Component
 */
(function () {

    "use strict";

    xeogl.CubeTexture = xeogl.Component.extend({

        type: "xeogl.CubeTexture",

        _init: function (cfg) {

            this._state = new xeogl.renderer.CubeTexture({
                texture: null
            });

            this._src = [];
            this._images = [];

            this._srcDirty = false;
            this._imageDirty = false;

            this._webglContextRestored = this.scene.canvas.on("webglContextRestored", this._webglContextRestored, this);

            this.flipY = cfg.flipY;
            this.src = cfg.src; // Image file}

            xeogl.stats.memory.textures++;
        },

        _webglContextRestored: function () {

            this._state.texture = null;

            if (this._src) {
                this._srcDirty = true;
            }

            this._needUpdate();
        },

        _update: function () {

            if (this._srcDirty) {
                if (this._src) {
                    this._loadSrc(this._src); // _imageDirty is set when the image has loaded
                    this._srcDirty = false;
                    return;
                }
            }

            if (this._imageDirty) {
                this._createTexture();
                this._renderer.imageDirty = true;
            }
        },

        _loadSrc: function (src) {

            var self = this;

            var spinner = this.scene.canvas.spinner;
            var spinnerTextures = spinner.textures;

            this._images = [];

            var loadFailed = false;

            for (var i = 0; i < src.length; i++) {

                var image = new Image();

                image.onload = (function () {

                    var _image = image;
                    var index = i;

                    return function () {

                        if (loadFailed) {
                            return;
                        }

                        _image = xeogl.renderer.webgl.ensureImageSizePowerOfTwo(_image);

                        self._images[index] = _image;

                        if (self._images.length === src.length) {

                            self._imageDirty = true;
<commit_msg>Fix CubeTexture image loading<commit_after>/**
 A **CubeTexture** specifies a cube texture map.

 ## Overview

 See {{#crossLink "Lights"}}{{/crossLink}} for an example of how to use CubeTextures for light and reflection mapping.

 @class CubeTexture
 @module xeogl
 @submodule lighting
 @constructor
 @param [scene] {Scene} Parent {{#crossLink "Scene"}}Scene{{/crossLink}} - creates this CubeTexture in the default
 {{#crossLink "Scene"}}Scene{{/crossLink}} when omitted.
 @param [cfg] {*} Configs
 @param [cfg.id] {String} Optional ID for this CubeTexture, unique among all components in the parent scene, generated automatically when omitted.
 @param [cfg.meta] {String:Object} Optional map of user-defined metadata to attach to this CubeTexture.
 @param [cfg.src=null] {Array of String} Paths to six image files to load into this CubeTexture.
 @param [cfg.flipY=false] {Boolean} Flips this CubeTexture's source data along its vertical axis when true.
 @extends Component
 */
(function () {

    "use strict";

    xeogl.CubeTexture = xeogl.Component.extend({

        type: "xeogl.CubeTexture",

        _init: function (cfg) {

            this._state = new xeogl.renderer.CubeTexture({
                texture: null
            });

            this._src = [];
            this._images = [];

            this._srcDirty = false;
            this._imageDirty = false;

            this._webglContextRestored = this.scene.canvas.on("webglContextRestored", this._webglContextRestored, this);

            this.flipY = cfg.flipY;
            this.src = cfg.src; // Image file}

            xeogl.stats.memory.textures++;
        },

        _webglContextRestored: function () {

            this._state.texture = null;

            if (this._src) {
                this._srcDirty = true;
            }

            this._needUpdate();
        },

        _update: function () {

            if (this._srcDirty) {
                if (this._src) {
                    this._loadSrc(this._src); // _imageDirty is set when the image has loaded
                    this._srcDirty = false;
                    return;
                }
            }

            if (this._imageDirty) {
                this._createTexture();
                this._renderer.imageDirty = true;
            }
        },

        _loadSrc: function (src) {

            var self = this;

            var spinner = this.scene.canvas.spinner;
            var spinnerTextures = spinner.textures;

            this._images = [];

            var loadFailed = false;
            var numLoaded = 0;

            for (var i = 0; i < src.length; i++) {

                var image = new Image();

                image.onload = (function () {

                    var _image = image;
                    var index = i;

                    return function () {

                        if (loadFailed) {
                            return;
                        }

                        _image = xeogl.renderer.webgl.ensureImageSizePowerOfTwo(_image);

                        self._images[index] = _image;

                        numLoaded++;

                        if (numLoaded === 6) {

                            self._imageDirty = true;

{'fraction_non_alphanumeric': 0.10204081632653061, 'fraction_numerical': 0.0006279434850863422, 'mean_word_length': 1.6035962402942379, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5257915', 'n_tokens_mistral': 1782, 'n_tokens_neox': 1629, 'n_words': 463}