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 packSamples calculating out-of-bounds #4862

Merged
merged 1 commit into from
Nov 18, 2022

Conversation

kungfooman
Copy link
Collaborator

Fixes #4860

Hi @slimbuck, you suggested i < numSamples / 4 and then keep the * 4, but getting rid of all these divisions/multiplications via a simple + feels a bit too tempting, are you okay rewriting the for-loop like this?

To make sure the functionality didn't change, I wrote a little test (requires src/index.js changes tho to export packSamples):

const { data } = pc.packSamples([
    0.1, 0.2, 0.3, 0.4, // row 1
    0.5, 0.6, 0.7, 0.8,
    0.1, 0.2, 0.3, 0.4, // same row 1 for control
]);
console.table([
    [...data.slice( 0, 16)],
    [...data.slice(16, 32)],
    [...data.slice(32, 48)],
]);
data;

Output for with and without PR is the same:

image

I confirm I have read the contributing guidelines and signed the Contributor License Agreement.

Copy link
Member

@slimbuck slimbuck left a comment

Choose a reason for hiding this comment

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

Yep looks good thanks!

@slimbuck slimbuck merged commit 13e9edb into playcanvas:main Nov 18, 2022
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.

reproject-texture packSamples overcalculates 4x + index out of bounds
3 participants