As far as I understand, bmap_zbuffer only resizes the engine internal buffers, so it has to be called only once.

Do you wait a frame between setting the variable that breaks the last loop and the new level load? If not, the last code block will never be executed since level_load deletes the entity from the scene and the action from the scheduler.

You have to set scan_view.bmap to NULL. Otherway it points to a removed bmap.

Both problems could be the cause of that ZTARG error you wrote about.

Morover, you are deleting scan_bmp and it is an entity skin. You should not do such a thing. It will be removed with the entity.