question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

LineSegmentsGeometry: Calling "setPositions" twice does not update the lines correctly

See original GitHub issue

Describe the bug

Calling LineSegmentsGeometry.setPositions a second time with more line segments still only renders the amount of line segments specified in the first call. Everything works as expected if you call “dispose” before calling “setPositions” again.

I’m not exactly sure why it’s happening. Perhaps it’s an issue related to instanced geometry rendering?

To Reproduce

Steps to reproduce the behavior:

  1. Create a LineSegments2 object
  2. Call line.geometry.setPositions with 1 line segment
  3. See that it renders 1 line
  4. 1 second later call line.geometry.setPositions with 2 line segments
  5. See that it only renders the first of the two lines

Code

line = new LineSegments2();
line.geometry.setPositions( [ 0, -0.5, 0, 0, 0.5, 0 ] );

setTimeout( () => {

  // uncomment to display both lines
  // line.geometry.dispose();
  line.geometry.setPositions( [
    0, -0.5, 0, -0.5, 0.5, 0,
    0, 0, 0, 0.5, 0, 0,
  ] );

}, 1000 );

Live example

https://jsfiddle.net/rhjeL01n/

Expected behavior

The correct amount of lines are rendered after calling “setPositions”.

Screenshots

If applicable, add screenshots to help explain your problem (drag and drop the image).

Platform:

  • Device: Desktop
  • OS: Windows
  • Browser: Chrome
  • Three.js version: latest (r126)

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
WestLangleycommented, Mar 22, 2021

@gkjohnson

  1. Could you create a sufficiently-large buffer and then set InstancedBufferGeometry.instanceCount? That would be one way to resize.

  2. Yes, _maxInstanceCount is a bit hacky. We knew that when it was added.

  3. I agree it is hard to update the values in the buffers because the indexing is complex. I would welcome API improvements in that regard.

1reaction
Mugen87commented, Mar 22, 2021

Is it the position of the project that setting or removing BufferAttributes on BufferGeometry between renders without calling dispose is not allowed?

You should modify the existing buffers. Not overwrite them (with new sizes). Nowhere in the examples is your pattern demonstrated.

If you need to change the size, dispose the geometry (since you can’t dispose buffer attributes) and create a new one. Feel free to clarify this in the documentation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

threejs linewidth property with LineSegmentsGeometry and ...
I'm trying to make lines that are wider than one pixel using the LineMaterial and LineSegments2 classes that are included with the threejs ......
Read more >
[SOLVED ] Problem with Line Renderer Positions? - Unity Forum
In short the line renderer isn't drawing a line in the correct place and it appears ... Start is called before the first...
Read more >
Out of control memory when updating position of lines within ...
Hello, I was wondering if the following problem is a result of user error or if it is a bug. When updating the...
Read more >
three Float32BufferAttribute JavaScript Examples
You can vote up the ones you like or vote down the ones you don't like, ... probably can't create line materials correctly,...
Read more >
Multiplayer racing game for AP CSP Create task - Jonathan Lam
socketId === socket.id).name = name; // tell sockets to update names ... false) { // only do if room exists (room may not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found