fixed handling of lost d3d device

This commit is contained in:
aap 2020-04-16 23:09:47 +02:00
parent ba7070f6e8
commit 7bd6d4649e
5 changed files with 41 additions and 7 deletions

View File

@ -1,11 +1,13 @@
#include <rw.h>
#include "skeleton.h"
namespace sk {
Globals globals;
Args args;
bool
InitRW(void)
{
@ -22,13 +24,15 @@ InitRW(void)
for(i = 0; i < n; i++)
if(Engine::getSubSystemInfo(&info, i))
printf("subsystem: %s\n", info.name);
Engine::setSubSystem(n-1);
int want = -1;
VideoMode mode;
n = Engine::getNumVideoModes();
for(i = 0; i < n; i++)
if(Engine::getVideoModeInfo(&mode, i)){
if(mode.width == 640 && mode.height == 480 && mode.depth == 32)
// if(mode.width == 640 && mode.height == 480 && mode.depth == 32)
if(mode.width == 1920 && mode.height == 1080 && mode.depth == 32)
want = i;
printf("mode: %dx%dx%d %d\n", mode.width, mode.height, mode.depth, mode.flags);
}

View File

@ -898,8 +898,7 @@ destroyNativeRaster(void *object, int32 offset, int32)
Raster *raster = (Raster*)object;
D3dRaster *natras = PLUGINOFFSET(D3dRaster, raster, offset);
#ifdef RW_D3D9
if(raster->type == Raster::CAMERATEXTURE)
removeVidmemRaster(raster);
destroyD3D9Raster(raster);
#endif
if(natras->texture)
deleteObject(natras->texture);

View File

@ -244,6 +244,18 @@ resetD3d9Device(void)
d3ddevice->SetMaterial(&d3dmaterial);
}
void
destroyD3D9Raster(Raster *raster)
{
int i;
if(raster->type == Raster::CAMERATEXTURE)
removeVidmemRaster(raster);
// Make sure we're not still referencing this raster
for(i = 0; i < MAXNUMSTAGES; i++)
if(rwStateCache.texstage[i].raster == raster)
rwStateCache.texstage[i].raster = nil;
}
// RW render state
static void
@ -744,12 +756,14 @@ clearCamera(Camera *cam, RGBA *col, uint32 mode)
Raster *ras = cam->frameBuffer;
if(!icon &&
(r.right != d3d9Globals.present.BackBufferWidth || r.bottom != d3d9Globals.present.BackBufferHeight)){
releaseVidmemRasters();
d3d9Globals.present.BackBufferWidth = r.right;
d3d9Globals.present.BackBufferWidth = r.right;
d3d9Globals.present.BackBufferHeight = r.bottom;
// TODO: check result
releaseVidmemRasters();
d3d::d3ddevice->Reset(&d3d9Globals.present);
// important that we get all raster back before restoring state
recreateVidmemRasters();
resetD3d9Device();
}
@ -763,7 +777,19 @@ showRaster(Raster *raster)
// not used but we want cameras to have rasters
assert(raster);
d3ddevice->Present(nil, nil, 0, nil);
HRESULT res = d3ddevice->Present(nil, nil, 0, nil);
if(res == D3DERR_DEVICELOST){
res = d3ddevice->TestCooperativeLevel();
// lost while being minimized, not reset once we're back
if(res == D3DERR_DEVICENOTRESET){
releaseVidmemRasters();
d3d::d3ddevice->Reset(&d3d9Globals.present);
// important that we get all raster back before restoring state
recreateVidmemRasters();
resetD3d9Device();
}
}
}
static bool32
@ -960,6 +986,8 @@ startD3D(void)
// Use window size in windowed mode, otherwise get size from video mode
if(d3d9Globals.modes[d3d9Globals.currentMode].flags & VIDEOMODEEXCLUSIVE){
// this will be much better for restoring after iconification
SetWindowLong(d3d9Globals.window, GWL_STYLE, WS_POPUP);
width = d3d9Globals.modes[d3d9Globals.currentMode].mode.Width;
height = d3d9Globals.modes[d3d9Globals.currentMode].mode.Height;
}else{

View File

@ -44,6 +44,7 @@ struct D3d9Globals
extern D3d9Globals d3d9Globals;
int findFormatDepth(uint32 format);
void destroyD3D9Raster(Raster *raster);
#endif
void rasterCreate(Raster *raster);

View File

@ -27,6 +27,8 @@ void genIm3DEnd(void);
void initFont(void);
void printScreen(const char *s, float x, float y);
//#include <Windows.h>
void
Init(void)
{