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

PLYLoader : RangeError: Offset is outside the bounds of the DataView #26229

Closed
ParanoidKevin opened this issue Jun 9, 2023 · 3 comments · Fixed by #26232
Closed

PLYLoader : RangeError: Offset is outside the bounds of the DataView #26229

ParanoidKevin opened this issue Jun 9, 2023 · 3 comments · Fixed by #26232

Comments

@ParanoidKevin
Copy link

Description

RangeError when adding a mesh into scene

Console:
RangeError: Offset is outside the bounds of the DataView
at DataView.getUint8 ()
at Object.read (PLYLoader.js:568:1)
at binaryReadElement (PLYLoader.js:543:1)
at parseBinary (PLYLoader.js:643:1)
at PLYLoader.parse (PLYLoader.js:710:1)
at Object.onLoad (PLYLoader.js:71:1)
at three.module.js:41507:1

.ply file
gripper.zip

Reproduction steps

Code

const PLYL = new PLYLoader();
PLYL.load(
  "path/to/gripper.ply",
  function (geometry) {
    this.scene.add(new THREE.Mesh(geometry));
  },
  function (xhr) {
    console.log((xhr.loaded / xhr.total) * 100 + "% loaded");
  },
  function (err) {
    console.error(err);
  }
);

Live example

https://codesandbox.io/s/quizzical-kepler-jjxj4f?file=/src/index.js

Screenshots

No response

Version

152

Device

Desktop

Browser

Chrome

OS

Windows

@Mugen87
Copy link
Collaborator

Mugen87 commented Jun 10, 2023

I can confirm the issue. The asset used to load correctly with r148. It starts failing with r149.

https://rawcdn.githack.com/mrdoob/three.js/r148/editor/index.html
https://rawcdn.githack.com/mrdoob/three.js/r149/editor/index.html

@aardgoose It seems this regression was introduced with the performance improvements added via #25210, #25248 and #25261. Maybe something in #25248 isn't right.

@aardgoose
Copy link
Contributor

I'll take a look.

@aardgoose
Copy link
Contributor

aardgoose commented Jun 10, 2023

OK, the problem is the example file has \r\n line endings and extractHeaderText() is removing the \n characters in the strings.

The header length is calculated in parseHeader() based on this data which is now incorrect.

As a result the header length is being calculated as 311 bytes long when including the \n characters it is actually 325 bytes. Hence the binary data isn't read correctly.

The following snippet replacing the section following the above line of code fixes the test case, but will obviously break with normal files.

			if ( result !== null ) {

				const newlineCount = result[ 0 ].match( /\r/g ).length;

				headerText = result[ 1 ];
				headerLength = new Blob( [ result[ 0 ] ] ).size + newlineCount;

			}

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

Successfully merging a pull request may close this issue.

3 participants