Here goes the relevant parts of the DLL:
I see that in my first post above, I stated that on losing the surfaces, I do a restoreAllSurfaces. Actually, I just do something like
It's a brute force way but I feel more at ease just tearing everything down, and building it all back up.
HTH,
David
// Blitz3D ==================================================================== //----------------------------------------------------------------------------- .lib "B3D_AppBase.dll" app_DDHook%(pDD7%):"_app_DDHook@4" app_DDUnHook():"_app_DDUnHook@0" app_DDWasLost%():"_app_DDWasLost@0" // C++ ======================================================================== //----------------------------------------------------------------------------- #include <windows.h> #define DIRECTDRAW_VERSION 0x0700 #include <ddraw.h> //----------------------------------------------------------------------------- #define BBDECL extern "C" _declspec(dllexport) #define BBCALL _stdcall //----------------------------------------------------------------------------- static LPDIRECTDRAW7 _b3d_pdd; // pointer to DirectDraw object static LPDIRECTDRAWSURFACE7 _b3d_pddsPrim; // pointer to primary DirectDraw surface //----------------------------------------------------------------------------- BOOL APIENTRY DllMain( HANDLE /*hModule*/, DWORD ul_reason_for_call, LPVOID /*lpReserved*/ ) { switch( ul_reason_for_call ) { case DLL_PROCESS_ATTACH: break; case DLL_THREAD_ATTACH: break; case DLL_THREAD_DETACH: break; case DLL_PROCESS_DETACH: break; } return TRUE; } //----------------------------------------------------------------------------- // called by 'app_DDHook()' HRESULT WINAPI _surfaceEnumCallback_GetPrimary( LPDIRECTDRAWSURFACE7 lpDDSurface, LPDDSURFACEDESC2 lpDDSurfaceDesc, LPVOID /*lpContext*/ ) { if( lpDDSurfaceDesc->ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE ) { _b3d_pddsPrim = lpDDSurface; return DDENUMRET_CANCEL; } lpDDSurface->Release(); return DDENUMRET_OK; } //----------------------------------------------------------------------------- // Should be called after B3D graphics mode has been set BBDECL BOOL BBCALL app_DDHook( LPDIRECTDRAW7 pDD ) { if( pDD ) { _b3d_pdd = pDD; return (DD_OK == _b3d_pdd->EnumSurfaces( DDENUMSURFACES_DOESEXIST | DDENUMSURFACES_ALL, NULL, NULL, _surfaceEnumCallback_GetPrimary )); } return FALSE; } //----------------------------------------------------------------------------- // Should be called before B3D graphics mode is cleared BBDECL void BBCALL app_DDUnHook() { if( _b3d_pddsPrim ) { _b3d_pddsPrim->Release(); _b3d_pddsPrim = NULL; _b3d_pdd = NULL; } } //----------------------------------------------------------------------------- // Should be called each time through Blitz3D main-loop BBDECL BOOL BBCALL app_DDWasLost() { return (_b3d_pddsPrim && (DD_OK != _b3d_pddsPrim->IsLost())); } // Usage ==================================================================== // On Start Up -------------------------------------------------------------- Graphics3D ... SetBuffer BackBuffer() If Not app_DDHook( SystemProperty( "DirectDraw7" ) ) Then /* Error */ // On Shut Down ------------------------------------------------------------- app_DDUnHook() EndGraphics // During Main Loop --------------------------------------------------------- If app_DDWasLost() Then /* reset display, reload graphics */ UpdateWorld: RenderWorld: Flip
I see that in my first post above, I stated that on losing the surfaces, I do a restoreAllSurfaces. Actually, I just do something like
app_DDUnHook() EndGraphics Graphics3D ... SetBuffer BackBuffer() app_DDHook( SystemProperty( "DirectDraw7" ) ; Reload all graphics
It's a brute force way but I feel more at ease just tearing everything down, and building it all back up.
HTH,
David