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

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

Open
vladikoff opened this issue Apr 16, 2013 · 4 comments

Comments

@vladikoff
Copy link

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.

@max-mapper
Copy link
Owner

Thanks, I have actually been thinking about how to handle this case. The current way voxel.js is set up is:

  • voxel-engine emits events that ask for chunks
  • chunks are given to voxel-engine
  • voxel-engine throws away the chunks when you move away from them in the game
  • when you go back, this process repeats

There is no caching/buffer mechanism right now in voxel-engine. I think this kind of logic should live in an external module, e.g. voxel-network-storage, voxel-indexeddb-storage, voxel-png-storage, voxel-localstorage, etc and the storage modules would listen to game events like:

engine.on('set', saveToDatabase)

Then when voxel-engine requests data:

engine.on('needsChunk', function(position){
  getChunkFromDatabase(position, engine.showChunk)
})

... or something like this.

In the short term I suppose I could make voxel-engine emit the .on('set)` events instead of throwing an error

@vladikoff
Copy link
Author

Really appreciate the quick response!
Are these the events: https://github.com/maxogden/voxel-engine#gamechunkregiononchange-functionpos- that I can use for the time being?

@max-mapper
Copy link
Owner

Yea .on('missingChunk' is the event for voxel-engine emits events that ask for chunks

@vladikoff
Copy link
Author

Thanks so much! I shall use that for the time being.

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