VR Changing scene crashes UPBGE

I’m trying to do a multi level VR game, but when I set my game to change scene, Blender crashes, and using “blender_debug_log” doesn’t give me any errors. I’ve also tried to start the VR Session from within bge, but it crashes too. Using the script using “Alt-P” works inside blender, but when trying it in the game engine, it just crashes with no errors.

Here’s the script I’m using to toggle VR Session:

> import bpy
> 
> for area in bpy.context.screen.areas:
>     if area.type == "VIEW_3D":
>         region = next((region for region in area.regions if region.type == 'WINDOW'), None)
>         if region is not None:
>             try:
>                 xr = bpy.context.window_manager.xr_session_state
>                 print(xr.is_running(bpy.context))
>             except:
>                 pass
>             try:
>                 override = {"area": area, "region": region}
>                 bpy.ops.wm.xr_session_toggle(override)
>             except ValueError:
>                 print(ValueError)