title: Three JS Map Material causes WebGL Warning
body: <p>I'm trying to define a material to meshes I loaded in from OBJLoader through the following wrapper function:</p>
  
  <pre><code>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") &lt; 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 );
  }
  </code></pre>
  
  <p>When the texture has loaded and it's time to apply the material to the mesh, I start getting the following warning on the console: </p>
  
  <pre><code>.WebGLRenderingContext: GL ERROR :GL_INVALID_OPERATION : glDrawElements: attempt to access out of range vertices in attribute 0 
  </code></pre>
  
  <p>and the mesh itself disappears.</p>
  
  <p>what am I doing wrong here?</p>
  
  <h1>UPDATE</h1>
  
  <p>As @WestLangley pointed on the comments: Never try to apply texture/materials after things have been rendered. Create the materials before rendering the object to the scene and then change them using:</p>
  
  <pre><code>obj.material.map = texture
  </code></pre>