Software Restart After Failure

If HOOPS Luminate is initialized in hardware mode or in hybrid mode, then the first window that is created will initialize the OpenGL rendering layer of the system. If the creation of this window fails, then we can use the code below to overcome the failure and force HOOPS Luminate startup whenever possible:

// Create the resource manager unique instance:
RED::Object* resmgr = RED::Factory::CreateInstance( CID_REDResourceManager );
if( !resmgr )
    exit( 1 );

RED::IResourceManager *iresmgr = resmgr->As< RED::IResourceManager >();
RED::IOptions* iresopt = resmgr->As< RED::IOptions >();

// Let's start in hardware mode for instance (it could be hybrid too):
RC_TEST( iresopt->SetOptionValue( RED::OPTIONS_RAY_ENABLE_SOFT_TRACER, 0, iresmgr->GetState() ) );

// Create a width x height window ('hwnd' is our windows handler here):
RED_RC rc;
RED::Object* window = RED::Factory::CreateREDWindow( *resmgr, hwnd, width, height, NULL, rc );
if( window == NULL )
{
    // Critical failure. We can't continue here. The window object has not been allocated indicating a severe error.
    exit( 1 );
}

// Try to restart in full CPU mode if we have failed to initialize the window:
if( rc != RED_OK )
{
    if( rc == RED_DRV_UNSUPPORTED_GPU )
    {
        // Cleanup our previously created window. As it was not properly initialized, do a direct destruction:
        if( window )
            rdelete window;

        // Setup the resource manager in software mode:
        RC_TEST( iresopt->SetOptionValue( RED::OPTIONS_RAY_ENABLE_SOFT_TRACER, 2, iresmgr->GetState() ) );

        window = RED::Factory::CreateREDWindow( *resmgr, hwnd, width, height, NULL, rc );
        if( window == NULL )
            exit( 1 );

        if( rc != RED_OK )
        {
            // Restart attempt has failed. Exit now.
            exit( 1 );
        }
    }
    else
    {
        // Other failures for which we can't restart. Exit now.
        exit( 1 );
    }
}

Please that we may not be able to restart if a severe error has occurred; This never happens, or the system is badly damaged, as on the second attempt, the startup procedure is purely software, and does not rely on any other piece of software.