minetest/minetest — pull request #1153 by CiaranG (2014-02-20 18:01:58+00:00)
Title: Fix for unloaded but active block problem

This is the bug: firstly a map block becomes inactive, and then 29 seconds (by default) later it becomes active again, but at the same time the server async thread unloads the block, because it's been inactive for long enough to do so.

In other words, when a block becomes active, aside from making it load, nothing actually updates the 'last used' time, so there is still a short window when it can be unloaded. This results in all manner of strange behaviour. From the player's perspective, placing blocks and having them disappear, occasionally, randomly, etc. For a lua entity that moves at looks at the map nodes around it, complete breakage, because once a block is in this state, it stays that way potentially indefinitely.

This fix just resets the usage timer as soon as a block is activated. I think that still leaves a tiny window (microseconds) for a race condition allowing the block to be unloaded before the usage timer gets reset, but that's a whole lot better than the several seconds as it is now.

I can reproduce this problem regularly and frequently (not to order, but within 15 minutes of play), but with this change it hasn't happened in 10 hours of constant testing.