max-mapper / max-mapper/voxel-engine

"TypeError: Cannot read property 'position' of undefined" with setBlock() if the position is greater than chunkSize

Open
#70 4 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.