I use the following method and it always works without errors:

To show it I use:

inventory_main.flags = SHOW;

To hide it I use:

inventory_main.flags &= ~SHOW;