The root of the issue was that while reading a new blendfile, the current `G_MAIN` is still the old one, not the one in which new data is being read. Since the remapping callback taking care of UI data during ID remapping is using `G_MAIN`, it is processing the wrong data, so when deleting the invalid shapekey (from `BLO_main_validate_shapekeys`), the UI data of the new bmain would not be properly remapped, causing invalid memory access later when recomputing user counts (calls to `BKE_main_id_refcount_recompute`). This is fixed by adding a new `BKE_id_delete_ex` function that takes extra remapping options parameter, and calling it from `BLO_main_validate_shapekeys` with extra option to enforce handling of UI data by remapping code. NOTE: At some point we have to check if that whole UI-callback thing is still needed, would be good to get rid of it and systematically process UI-related ID pointers like any others. Current situation is... fragile to say the least.