max-mapper / max-mapper/voxel-engine
"TypeError: Cannot read property 'position' of undefined" with setBlock() if the position is greater than chunkSize
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 1.3k
- Forks
- 217
- PR merge metrics
- No merged PRs in 30d
Description
Cannot use game.setBlock(...) to create blocks outside of visible chunk range.
Game config:
{
chunkDistance: 1,
chunkSize: 16,
...
}
To reproduce:
// tower with different textures
var tower = [
1, 2, 1, 3, 1, 2, 3, 1, 2, 1, 2, 3, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 2, 2, 2, 1, 1, 1, 1, 1,
1, 2, 1, 3, 1, 2, 3, 1, 2, 1, 2, 3, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 2, 2, 2, 1, 1, 1, 1, 1,
1, 2, 1, 3, 1, 2, 3, 1, 2, 1, 2, 3, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 2, 2, 2, 1, 1, 1, 1, 1,
1, 2, 1, 3, 1, 2, 3, 1, 2, 1, 2, 3, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 2, 2, 2, 1, 1, 1, 1, 1
]
tower.forEach(function (item, i) {
var pos = [1,i,2]
console.log(pos)
game.setBlock(pos, item)
})
The last log prints [1, 16, 2], then error:
TypeError: Cannot read property 'position' of undefined
This can also be reproduced via the console after the game has been fully initialized.
See https://github.com/vladikoff/voxel-test-playground for an example of this issue.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue with game.setBlock() using chunkSize 16 and positions beyond the visible chunk range, including [1,16,2]. Trace the setBlock() path to find why it accesses an undefined object; done means blocks outside the visible range no longer cause the TypeError and the supplied tower example completes successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- game-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100