Unreal engine keeps crashing

The error message you have Unreal Engine is exiting due to D3D device being lost implies that this is related to your graphics card/drivers and is not necessarily a problem with UE4 itself. You can start by making sure that your graphics driver is up to date, and if the crash persists then try some of the fixes mentioned here: 1, 2, 3, 4