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 raycasting errors on unloaded chunks #88

Closed
wants to merge 1 commit into from

Conversation

extremeheat
Copy link
Member

Fix raycasting exceptions in async world when a chunk is unloaded, would previously result in undefined.getBlock(). Return undefined on getters where no cc is present.

https://github.com/PrismarineJS/prismarine-world/blob/master/src/world.js#L64

Fix raycasting exceptions in async world when a chunk is unloaded, would previously result in `undefined.getBlock()`. Return undefined on getters where no cc is present.

https://github.com/PrismarineJS/prismarine-world/blob/master/src/world.js#L64
@rom1504
Copy link
Member

rom1504 commented Dec 3, 2021

This doesn't make sense to me.
The async API can never have unloaded chunks because they're generated or read from disk
The sync API can

Mineflayer uses sync, flying squid uses async

Raycast is defined based on the async API

Is raycast used in mineflayer? If yes it should had the sync API, or there should be a separate sync version

@extremeheat
Copy link
Member Author

Yes so when reading chunks off of disk through prismarine-provider-anvil without a chunk generator the raycasting can fail on movement if you move the cursor somewhere where there isn’t a generated chunk. This can happen for example when reading a vanilla world through prismarine-viewer (reproducible through the electron prismarine viewer example)

@rom1504
Copy link
Member

rom1504 commented Jan 20, 2022

this is a breaking API change, currently the async api cannot return null
it should at least be documented

@extremeheat
Copy link
Member Author

extremeheat commented Jan 20, 2022

To make it not breaking what about returning air or 0? The alternative here is crashing on undefined property which is probably slower to handle. I believe the issue is with the raycast function below which is used in pviewer, it checks for undefined blocks but it doesn't catch the error in the getBlock() call

@rom1504
Copy link
Member

rom1504 commented Jan 20, 2022

something that would make this easier is doing #64
ie having only the sync API and handling null returns properly

if we merge this, we would need to change all calls to getBlock to handle null even with the async API, it doesn't seem like the best path

@rom1504
Copy link
Member

rom1504 commented Jan 20, 2022

returning air/0 might be ok I guess

@rom1504
Copy link
Member

rom1504 commented Jan 20, 2022

just to clarify: today getBlock() async is supposed to never error out and never return null
if this assumption is broken because we don't define generators then we need to change this assumption and this is a big change

@extremeheat extremeheat marked this pull request as draft February 16, 2022 07:13
@rom1504
Copy link
Member

rom1504 commented Aug 7, 2022

seems too old

@extremeheat
Copy link
Member Author

yeah I don't remember the full context behind this, so if I visit anvil-provider again I'll revisit this

@extremeheat extremeheat closed this Aug 7, 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.

2 participants