are blocks always available? or should I wait for them to be loaded (from the server) #100
-
|
E.g. this worked once (a bit; half of the blocks did not appear) but since then every getBlock() returns NULL: |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Only loaded blocks are available, if you get null it's probably that they're not loaded yet. However, I can see in your code that your A simple thing you could do is something like that (you could add a while loop to be sure you get all blocks): std::shared_ptr<Blockstate> blockstate;
{
std::lock_guard<std::mutex> world_guard(world->GetMutex());
const Block *block = world->GetBlock(v);
if (block)
{
blockstate = block->GetBlockstate();
}
}
if (!blockstate)
{
// sleep without keeping the world locked
}PS : if you're not familiar with |
Beta Was this translation helpful? Give feedback.
Only loaded blocks are available, if you get null it's probably that they're not loaded yet.
However, I can see in your code that your
world_guardlockking the world mutex is in the same scope than your sleep. So you wait for more blocks to be loaded but you also block (pun not intended) any chunk data to be loaded in the world during this time.A simple thing you could do is something like that (you could add a while loop to be sure you get all blocks):
std::shared_ptr<Blockstate> blockstate; { std::lock_guard<std::mutex> world_guard(world->GetMutex()); const Block *block = world->GetBlock(v); if (block) { blockstate = block->GetBlockstate(); } } if (!bloc…