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

Fix segfault for large bases in perlin noise #36

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mwshinn
Copy link

@mwshinn mwshinn commented Jan 4, 2022

The current code segfaults for large bases because it reads past the end of the _PERM array. There are a few possible fixes with advantages and disadvantages. This fix accepts all bases, but it cycles with a period of 256. An alternative method is to throw an error for bases larger than 256.

k = ((k + base) & 255);
ii = ((ii + base) & 255);
jj = ((jj + base) & 255);
kk = ((kk + base) & 255);

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I understand you're capping the result to 255. This can be misleading to the user since it's a hidden operation : the user could expect different results with larger values for base and not get them.

I'd recommend throwing an error or at least a warning.

@mwshinn
Copy link
Author

mwshinn commented Feb 20, 2022

I think you're right, this commit throws errors for bases that have the potential to be non-unique.

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

Successfully merging this pull request may close these issues.

2 participants