The role of cancelling magnetic fields in the buildup to erupting filaments and flares