-
Notifications
You must be signed in to change notification settings - Fork 491
Safe getTileBlock #5463
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
base: develop
Are you sure you want to change the base?
Safe getTileBlock #5463
Conversation
Under normal circumstances, (* - though such unallocated blocks seem to be exceedingly uncommon in the current version - back in 0.47.05 and earlier, blocks up in the Sky were often unallocated, and way back in 0.28.181.40d and earlier, nearly all underground blocks were unallocated until you placed a designation inside them). |
The custom renderer I'm working on makes many calls to getTileBlock (although I'm rewriting a few parts to cut back on it). You're right that the situation that the block is unallocated is rare, however, I'd think the check is still prudent. |
@myk002 |
I just reviewed DF's own code for interacting with I would not expect these indices to ever be invalid in fortress mode as the map is loaded at load and remains loaded throughouot. In adventure mode, maps are loaded and unloaded as the player moves around the world. If you attempt to access the At this point I'm not convinced that there is a problem to fix and would suggest that you share the code that is having problems so we can determine that there's not in fact an XY problem here. |
I'm writing a renderer that has to repeatedly access the getTileBlock() method in Maps.cpp. I've had my debugger show crashes here before at the return statement:
return world->map.block_index[x >> 4][y >> 4][z];
It seems that it is trying to access an invalid memory address even though the coordinates are valid. This indicates sometimes dfhack can hit the map_block data before it has updated, causing the crash. Adding a check for null pointers seems to have resolved the crashes on my end. Let me know if this is a prudent change or if I ought to be doing something else when having to make many calls to getTileBlock().