Mac Game freezes when clicking cancel while Robin takes you to the farm

CandyNim

Tiller
Bug: Pressing any of the 4 buttons that send you to the farm on the carpentry menu and then pressing cancel quickly causes the game to freeze. The easiest way to replicate is to click on the edge of demolish and move your mouse slightly to the right and click again.

Code Analysis: The relevant code lives inside of `CarpenterMenu.receiveLeftClick`. When you click on one of those 4 buttons (paint, move, build, demolish), the following code gets run:
```c#
Game1.globalFadeToBlack(setUpForBuildingPlacement);
Game1.playSound("smallSelect");
this.onFarm = true;
this.Action = CarpentryAction.[relevant action name];
```
The `onFarm` variable is what determines whether or not the game thinks you're currently on the farm, and is set the moment you click on a button. The `onFarm` variable also disables the 4 buttons, thus stopping you from clicking multiple. However, it doesn't disable the cancel button. While visually the button is hidden, at the very start of the function it says
```c#
if (this.cancelButton.containsPoint(x, y))
{
if (this.onFarm)
{
if (this.Action == CarpentryAction.Move && this.buildingToMove != null)
{
Game1.playSound("cancel");
return;
}
this.returnToCarpentryMenu();
Game1.playSound("smallSelect");
return;
}
base.exitThisMenu();
Game1.player.forceCanMove();
Game1.playSound("bigDeSelect");
}
```
and when you click while this.onFarm is set to true it assumes you're on the farm - the same button gets reused twice, meaning it doesn't get disabled. Thus it calls `this.returnToCarpentryMenu()` *while* we still have the `globalFadeToBlack` happening. I'm not 100% sure on the exact behavior that leads to a freeze, but that's honestly irrelevant as we wouldn't want it to happen at all.
Suggested Solution: Disable the cancel button while the game is currently fading to black. I'm unsure as to how this would be best done - perhaps check `Game1.globalFade`? That should probably work?
(The ` are a sign that I copy pasted this from discord, and I checked and it hasn't been patched so far)
 
Top