Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught TypeError: Cannot read property 'length' of undefined #1907

Closed
Huck opened this issue May 14, 2012 · 15 comments
Closed

Uncaught TypeError: Cannot read property 'length' of undefined #1907

Huck opened this issue May 14, 2012 · 15 comments
Labels

Comments

@Huck
Copy link

Huck commented May 14, 2012

Hello,

i have a simple scene that simply creates 3 lights and adds a cube to the scene.

when i debug the code i get an exception in chrome:

Uncaught TypeError: Cannot read property 'length' of undefined in the function:

function initMeshBuffers ( geometryGroup, object ) {

        var geometry = object.geometry,
            faces3 = geometryGroup.faces3,
            faces4 = geometryGroup.faces4,

            nvertices = faces3.length * 3 + faces4.length * 4,
            ntris     = faces3.length * 1 + faces4.length * 2,
            nlines    = faces3.length * 3 + faces4.length * 4,

            material = getBufferMaterial( object, geometryGroup ),

            uvType = bufferGuessUVType( material ),
            normalType = bufferGuessNormalType( material ),
            vertexColorType = bufferGuessVertexColorType( material );

what seems to happen is the function scene.addObject goe son to loop on geometrygroups:

for ( g in geometry.geometryGroups ) {

the cube seems to have 2 geometry groups. the first iteration goes on by fine and has the properties "faces3" and "faces4". but the second call does not have them in the chrome debugger, and hence the error above.

hope this helps.

note: this is r49

scene code:

        var scene = new THREE.Scene();
    var camera = new THREE.PerspectiveCamera(45,js.Lib.window.innerWidth / js.Lib.window.innerHeight,1,10000);
    camera.position.set(-500,500,1500);
    scene.add(camera);
    var light = new THREE.DirectionalLight(16777215);
    light.position.set(0.5,0.5,1);
    scene.add(light);
    var geometry = new THREE.CubeGeometry(1,1,1,1,1,1);
    var cube = new THREE.Mesh(geometry,new THREE.MeshNormalMaterial());
    cube.position.set(0,0,0);
    cube.scale.set(100,100,100);
    scene.add(cube);
    var renderer = new THREE.WebGLRenderer({ clearColor : 10066329, clearAlpha : 1, alpha : false});
    renderer.setSize(js.Lib.window.innerWidth,js.Lib.window.innerHeight);
    js.Lib.document.body.appendChild(renderer.domElement);
    js.Lib.document.addEventListener("mousemove",function(event) {
        mouseX = event.clientX - js.Lib.window.innerWidth / 2;
        mouseY = event.clientY - js.Lib.window.innerHeight / 2;
    },false);

// olater the render loop:
{
        camera.position.x += (mouseX / 10 - camera.position.x) * 0.005;
        camera.position.y += (-mouseY / 10 - camera.position.y) * 0.005;
        camera.lookAt(cube.position);
        cube.rotation.y += 0.05;

        renderer.render(scene,camera);
    };
@mrdoob
Copy link
Owner

mrdoob commented May 14, 2012

geometryGroup.faces3, geometryGroup.faces4? Do these exist?

@Huck
Copy link
Author

Huck commented May 14, 2012

the loop iterates twice. the first iteration they do, the second they dont, causing the above exception.

@mrdoob
Copy link
Owner

mrdoob commented May 14, 2012

@alteredq
Copy link
Contributor

I'm not sure I understand what exactly is the problem reported here - does it work ok when you run it, just there are some troubles if you debug it?

@Huck
Copy link
Author

Huck commented May 14, 2012

yes it still works in the end, but it still gives an exception. you prefer to know than not right?

@alteredq
Copy link
Contributor

Could you please clarify - does it throw exception just when you debug it or also when you run it normally?

Also would it be possible to put somewhere complete example so that we could reproduce the issue?

This whole thing seems weird, we are speaking about some of the most used code in whole lib, virtually every example, every application uses this and so far there were no problems, so I would like to understand what's going on. Obviously you do something somewhere differently than anybody else so far.

@Huck
Copy link
Author

Huck commented May 14, 2012

ok, false alarm. i just tried to reproduce the bug with a very simple page and it doesn't happen. But i can reproduce it when i compile the same simple page in javascript from haxe. So i guess haxe must be breaking something with all the stuff it performs at initialization.

please ignore

@mrdoob mrdoob closed this as completed May 14, 2012
@mrdoob
Copy link
Owner

mrdoob commented May 14, 2012

Next time, mention the Haxe bit on the first post ;)

@Huck
Copy link
Author

Huck commented May 14, 2012

didn't think haxe init code interacted with three.js in any way. ;)

@pgailloud
Copy link

Hello,
I have actually the same problem, but without Haxe.
first iteration, it's ok, no exception.
Second iteration, it throw an exception but continue execution.
If you want a live exemple, you can check it here: http://dev.laurienis.ch/?driver=3d

Yes, it's still revision 48 but I have to modify heavely my code with the changes you made to the axis of the planeGeometry in revision 49.

if i look the code, the problem come from an empty THREE.Scene.__objectsAdded, but i don't know how to solve it.

@mrdoob
Copy link
Owner

mrdoob commented Jul 22, 2012

Yes, it's still revision 48 but I have to modify heavely my code with the changes you made to the axis of the planeGeometry in revision 49.

Why heavily? Shouldn't be an easy change?

@pgailloud
Copy link

not so heavily, now it is done. i have just some difficulties with the axis.

@gardenvarietyse
Copy link

I'm still having this issue with geometry generated using PlaneGeometry, both in R61 and R62.
No haxe or anything, just regular JS.

The error is only logged a single time. Execution continues and there seem to be no ill effects.

@gvsharma
Copy link

gvsharma commented Sep 23, 2016

am getting same issue while creating circle......any help?

@andrewvarga
Copy link

For me, this happened when I used the same geometry instance for 2 different webgl contexts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants