Skip to content

Attempting to create a zero length buffer #8

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

Open
DevianKeno opened this issue Feb 14, 2025 · 1 comment
Open

Attempting to create a zero length buffer #8

DevianKeno opened this issue Feb 14, 2025 · 1 comment

Comments

@DevianKeno
Copy link

DevianKeno commented Feb 14, 2025

first of all, thanks for this code!

I got an error: 'Attempting to create a zero length compute buffer' on the line
_trsBuffer = new ComputeBuffer(_trueInstanceCount, sizeof(float) * 4 * 4);
which then breaks and fails to initialize the _visibleBuffer
maybe I have set the values wrong?
Image

I'm using approach 5: occlusion culling + high performance. Here's my settings.
Image

My terrain size is 512x512.
Image

Unity version: 2022.3.23f1
URP version: 14.0.10

@MangoButtermilch
Copy link
Owner

MangoButtermilch commented Feb 15, 2025

This happens because _trueInstanceCount variable is 0 after the instances have been initialized. Meaning that the conditions for creating all instances failed.
These are the conditions for skipping a possible instance:

  1. The grass is to small and below minGrassHeight - which it can't be since you've set the height to be 1 and min height to 0.15.
  2. The grass color is lower than grassThreshhold. The color is defined via the red channel of the Splatmap. You can see that I'm setting the texure value to the first element in the alphamapTextures array see here and here

So it could be and issue with your terrain layers (maybe try change the order) or the grassThreshhold slider value. Also try to increase the instances to something higher. This increases the chance for instances to be created.

Another thing I noticed: the instancer should have the same size as the terrain be placed in the middle of it but from your screenshot it looks like you're using multiple instancers (?). The approach isn't suited for that, so try it with a single one first.
I'm working on publishing a new approach that is able to handle this though.

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

No branches or pull requests

2 participants