TypeError: Cannot read property ‘array’ of undefined

Description of the problem

I am getting a TypeError when constructing an instance of Geometry from an instance of BufferGeometry.

TypeError: Cannot read property 'array' of undefined
    at Geometry.fromBufferGeometry (/path/three.js:12675:39)

Here is a simple test case to reproduce that

var bufferGeometry = new THREE.BufferGeometry();
bufferGeometry.addAttribute('color', new THREE.BufferAttribute(new Float32Array( [0, 0, 0, 0.5, 0.5, 0.5, 1, 1, 1] ), 3 ) );
bufferGeometry.addAttribute('normal', new THREE.BufferAttribute(new Float32Array( [0, 1, 0, 1, 0, 1, 1, 1, 0] ), 3 ) );
bufferGeometry.addAttribute('uv', new THREE.BufferAttribute(new Float32Array( [0, 0, 0, 1, 1, 1] ), 2 ) );
bufferGeometry.addAttribute('uv2', new THREE.BufferAttribute(new Float32Array( [0, 0, 0, 1, 1, 1] ), 2 ) );
var geometry = new THREE.Geometry().fromBufferGeometry(bufferGeometry);

It seems that the problem occurs when the attribute ‘position’ is missing. If we change line 231 of Geometry.js to the following, we can create an instance of Geometry successfully.

var positions = attributes.position !== undefined ? attributes.position.array : [];
Three.js version
  • Dev
  • r82
Browser
  • All of them
  • Chrome
  • Firefox
  • Internet Explorer
OS
  • All of them
  • Windows
  • Linux
  • Android
  • IOS
Hardware Requirements (graphics card, VR Device, …)

Author: Fantashit

2 thoughts on “TypeError: Cannot read property ‘array’ of undefined

  1. Users may need Geometry for adjacency information, for example. Who knows…

    I also think it would be wise to identify where users use Geometry so we are prepared to offer work-arounds when we deprecate it.

    We will stop rendering Geometry at some point, I expect. But I would retain the conversion utilities.

    And I would not close this PR for the reason you stated — maybe some other reason, but not that one. JMHO :).

Comments are closed.