This is my first attempt in fixing T83592. There might be a better solution, but at least this shows where the problem is.
There are two issues:
- BKE_library_id_can_use_idtype reported that the window manager cannot point to any IDs. This is wrong, because the window manager contains windows, which point to scene data blocks.
- Remapping a scene that is active in some window to null, results in a window without a scene, which no (almost no?) code seems to handle.
Fixing the BKE_library_id_can_use_idtype part of this is quite straight forward.
Fixing the remapping is a bit more tricky. I implemented the active-scene-update in a post processing step of id remapping, because I don't know a better place. Suggestions are welcome.
I also found that we can still get to zero scenes when first deleting the scene in the current blend file, and deleting the linked library (which also contains a scene) afterwards.
The code to update the active scene also seems a bit brittle, because it just updates the pointer instead of calling WM_window_set_active_scene.