Три JS Map Material вызывают предупреждение WebGL

Я пытаюсь определить материал для ячеек, загруженных из OBJLoader с помощью следующей функции-оболочки:

function applyTexture(src){
    var texture = new THREE.Texture();
    var loader = new THREE.ImageLoader();
    loader.addEventListener( 'load', function ( event ) {
        texture.image = event.content;
        texture.needsUpdate = true;

        // find the meshes from the loaded OBJ and apply the texture to it.
        object.traverse( function ( child ) {
            if ( child instanceof THREE.Mesh ) {
                if(child.name.indexOf("Lens") < 0){
                    child.dynamic = true;

                   child.material = new THREE.MeshLambertMaterial( { color: 0xdddddd, shading: THREE.FlatShading, map : texture } );
                   // also tried:
                   //child.material = new THREE.MeshPhongMaterial( { color: 0x000000, specular: 0x666666, emissive: 0x000000, ambient: 0x000000, shininess: 10, shading: THREE.SmoothShading, map : texture} );
                   // and:
                   //child.material = new THREE.MeshBasicMaterial({map : texture});
                   child.material.map = texture; // won't throw the WebGL Warning, but won't show the texture either;
               } else {
                   // works just fine.
                   child.material = new THREE.MeshPhongMaterial( { color: 0x000000, specular: 0x666666, emissive: 0x000011, ambient: 0x000000, shininess: 10, shading: THREE.SmoothShading, opacity: 0.6, transparent: true } );
               }
            }
        });
    });
    loader.load( src );
}

Когда текстура загрузится иПришло время применить материал к сетке, и я начал получать на консоли следующее предупреждение:

.WebGLRenderingContext: GL ERROR :GL_INVALID_OPERATION : glDrawElements: attempt to access out of range vertices in attribute 0 

и сама сетка исчезает.

что я тут не так делаю?

ОБНОВИТЬ

Как отметил @WestLangley в комментариях: Никогда не пытайтесь применять текстуру / материалы после того, как что-то будет визуализировано. Создайте материалы перед рендерингом объекта на сцену, а затем измените их, используя:

obj.material.map = texture

Ответы на вопрос(2)

Ваш ответ на вопрос