Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics

It even happens if I don't click too quickly (I've had it happen on the very first click). It's when there's a ton of stuff going on in the background, which seems to drag frames out a bit.

For example, say I amass just enough ore to purchase 'anchovy cove'. The upgrade menu then updates to show the upgrade as purchasable, but just as I click, the iron lored finishes its task and reduces the available ore to below the cost. I've even seen the menu item go dark gray right as I click, and then the game crashes.

I suspect what's going on is that both events manage to trigger, i.e., they both first check if enough resources are available, and then, seeing that they are (because neither has deducted any yet), they both deduct their share of resources, resulting in a negative number (which presumably breaks something, e.g., the display routine or some other computation). If you have actual concurrent programming going on, where one thread can be doing *anything* while another thread is running, you'll have to use mutex to prevent that kind of thing from happening. If not, you can just check again right before you actually change the value to make sure it doesn't go negative. Alternately, you can find the code that's actually crashing (probably a log() or something similar) and adjust it to permit negative numbers. (Assuming my suspicion is correct, anyway).