SafelyLoadingRenderSystems         How to safely load rendersystems without a crash (as in, fail gracefully on systems that lack DirectX or GL)
Print

Having your application crash on loading is pretty sad. It's slightly unprofessional and is tedious to debug with an user. One thing that can fail in a great number of ways is loading the rendersystems, especially the DX variants.

This is the solution I use in ShortHike(external link). I have disable the plugins.cfg file and load the plugins manually instead. I use this snippet of code to check for the DirectX version and to load the rendersystem. The GetDXVersion is included with the DirectX SDK.

This snippet guards against two common situations:

  • The computer is running an older version of DirectX (5, 6, 7 etc). Loading the DX9 plugin would crash your application with a missing DLL call (NB. you really crash. No exceptions or anything. Just plain crash.)
  • You have compiled OGRE on 9.0c and the user has 9.0b. The versions aren't compatible so the we need an inner try/catch

 
Take care! Kai

void 
 Main::loadRenderSystems() 
 { 
   Root* ogreRoot = Root::getSingletonPtr(); 
 
 #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 
   HRESULT hr; 
   DWORD dwDirectXVersion = 0; 
   TCHAR strDirectXVersion[10]; 
 
   hr = GetDXVersion( &dwDirectXVersion, strDirectXVersion, 10 ); 
   if( SUCCEEDED(hr) ) { 
     ostringstream dxinfoStream; 
     dxinfoStream << "DirectX version: " << strDirectXVersion; 
     LogManager::getSingleton().logMessage(dxinfoStream.str()); 
 
     if(dwDirectXVersion >= 0x00090000) { 
       try { 
         ogreRoot->loadPlugin("RenderSystem_Direct3D9"); 
       } 
       catch(Exception& e) { 
         LogManager::getSingleton().logMessage(String("Unable to create D3D9 RenderSystem: ") + e.getFullDescription()); 
        } 
     } 
   } 
 #endif
   try {  
     ogreRoot->loadPlugin("RenderSystem_GL");  
   } 
   catch(Exception& e) { 
     LogManager::getSingleton().logMessage(String("Unable to create OpenGL RenderSystem: ") + e.getFullDescription()); 
   } 
 
   try { 
     ogreRoot->loadPlugin("Plugin_CgProgramManager");  
   } 
   catch(Exception& e) { 
     LogManager::getSingleton().logMessage(String("Unable to create CG Program manager RenderSystem: ") + e.getFullDescription()); 
   } 
 }

--Kai Backman? 15:26, 4 Apr 2005 (CDT)


Contributors to this page: sarcacid719 points  , OgreWikiBot and jacmoe133512 points  .
Page last modified on Monday 19 of July, 2010 01:33:32 UTC by sarcacid719 points .


The content on this page is licensed under the terms of the Creative Commons Attribution-ShareAlike License.
As an exception, any source code contributed within the content is released into the Public Domain.