Skip to content

Commit

Permalink
fixed handling of lost d3d device
Browse files Browse the repository at this point in the history
  • Loading branch information
aap committed Apr 16, 2020
1 parent ba7070f commit 7bd6d46
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 7 deletions.
6 changes: 5 additions & 1 deletion skeleton/skeleton.cpp
@@ -1,11 +1,13 @@
#include <rw.h>
#include "skeleton.h"


namespace sk {

Globals globals;
Args args;


bool
InitRW(void)
{
Expand All @@ -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);
}
Expand Down
3 changes: 1 addition & 2 deletions src/d3d/d3d.cpp
Expand Up @@ -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);
Expand Down
36 changes: 32 additions & 4 deletions src/d3d/d3ddevice.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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();
}

Expand All @@ -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
Expand Down Expand Up @@ -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{
Expand Down
1 change: 1 addition & 0 deletions src/d3d/rwd3dimpl.h
Expand Up @@ -44,6 +44,7 @@ struct D3d9Globals
extern D3d9Globals d3d9Globals;

int findFormatDepth(uint32 format);
void destroyD3D9Raster(Raster *raster);
#endif

void rasterCreate(Raster *raster);
Expand Down
2 changes: 2 additions & 0 deletions tools/clumpview/main.cpp
Expand Up @@ -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)
{
Expand Down

0 comments on commit 7bd6d46

Please sign in to comment.