gsdx: by default new will throw std::bad_alloc

So catch/use it and don't bother with GSDXErrorOOM
This commit is contained in:
Gregory Hainaut 2016-10-13 20:44:59 +02:00
parent c440c7c93a
commit fbf7ccbdda
8 changed files with 15 additions and 32 deletions

View File

@ -526,9 +526,6 @@ GSTexture* GSDevice11::CreateSurface(int type, int w, int h, bool msaa, int form
if(SUCCEEDED(hr))
{
t = new GSTexture11(texture);
if (t == NULL) {
throw GSDXErrorOOM();
}
switch(type)
{
@ -540,6 +537,10 @@ GSTexture* GSDevice11::CreateSurface(int type, int w, int h, bool msaa, int form
break;
}
}
else
{
throw std::bad_alloc();
}
return t;
}

View File

@ -718,17 +718,11 @@ GSTexture* GSDevice9::CreateSurface(int type, int w, int h, bool msaa, int forma
if(surface)
{
t = new GSTexture9(surface);
if (t == NULL) {
throw GSDXErrorOOM();
}
}
if(texture)
{
t = new GSTexture9(texture);
if (t == NULL) {
throw GSDXErrorOOM();
}
}
if(t)
@ -743,6 +737,10 @@ GSTexture* GSDevice9::CreateSurface(int type, int w, int h, bool msaa, int forma
break;
}
}
else
{
throw std::bad_alloc();
}
return t;
}

View File

@ -229,11 +229,7 @@ GSTexture* GSDeviceOGL::CreateSurface(int type, int w, int h, bool msaa, int fmt
GL_PUSH("Create surface");
// A wrapper to call GSTextureOGL, with the different kind of parameter
GSTextureOGL* t = NULL;
t = new GSTextureOGL(type, w, h, fmt, m_fbo_read, m_mipmap > 1 || m_filter > 2);
if (t == NULL) {
throw GSDXErrorOOM();
}
GSTextureOGL* t = new GSTextureOGL(type, w, h, fmt, m_fbo_read, m_mipmap > 1 || m_filter > 2);
// NOTE: I'm not sure RenderTarget always need to be cleared. It could be costly for big upscale.
// FIXME: it will be more logical to do it in FetchSurface. This code is only called at first creation

View File

@ -50,7 +50,7 @@ bool GSDeviceSW::Reset(int w, int h)
GSTexture* GSDeviceSW::CreateSurface(int type, int w, int h, bool msaa, int format)
{
if(format != 0) return NULL; // there is only one format
ASSERT(format == 0);
return new GSTextureSW(type, w, h);
}

View File

@ -1590,7 +1590,7 @@ void GSState::FlushPrim()
Draw();
} catch (GSDXRecoverableError&) {
// could be an unsupported draw call
} catch (GSDXErrorOOM&) {
} catch (const std::bad_alloc& e) {
// Texture Out Of Memory
PurgePool();
fprintf(stderr, "GSDX OUT OF MEMORY\n");

View File

@ -1110,7 +1110,6 @@ GSTextureCache::Source* GSTextureCache::CreateSource(const GIFRegTEX0& TEX0, con
{
const GSLocalMemory::psm_t& psm = GSLocalMemory::m_psm[TEX0.PSM];
Source* src = new Source(m_renderer, TEX0, TEXA, m_temp);
if (src == NULL) throw GSDXErrorOOM();
int tw = 1 << TEX0.TW;
int th = 1 << TEX0.TH;
@ -1431,11 +1430,7 @@ GSTextureCache::Source* GSTextureCache::CreateSource(const GIFRegTEX0& TEX0, con
src->m_texture = m_renderer->m_dev->CreateTexture(tw, th);
}
if(src->m_texture == NULL)
{
delete src;
throw GSDXErrorOOM();
}
ASSERT(src->m_texture);
if(psm.pal > 0)
{
@ -1449,8 +1444,9 @@ GSTextureCache::Source* GSTextureCache::CreateSource(const GIFRegTEX0& TEX0, con
GSTextureCache::Target* GSTextureCache::CreateTarget(const GIFRegTEX0& TEX0, int w, int h, int type)
{
ASSERT(type == RenderTarget || type == DepthStencil);
Target* t = new Target(m_renderer, TEX0, m_temp, CanConvertDepth());
if (t == NULL) throw GSDXErrorOOM();
// FIXME: initial data should be unswizzled from local mem in Update() if dirty
@ -1467,12 +1463,6 @@ GSTextureCache::Target* GSTextureCache::CreateTarget(const GIFRegTEX0& TEX0, int
t->m_texture = m_renderer->m_dev->CreateDepthStencil(w, h, true);
}
if(t->m_texture == NULL)
{
delete t;
throw GSDXErrorOOM();
}
m_dst[type].push_front(t);
return t;
@ -1880,7 +1870,6 @@ void GSTextureCache::Target::Update()
TEXA.TA1 = 0x80;
GSTexture* t = m_renderer->m_dev->CreateTexture(w, h);
if (t == NULL) return;
const GSOffset* off = m_renderer->m_mem.GetOffset(m_TEX0.TBP0, m_TEX0.TBW, m_TEX0.PSM);

View File

@ -246,7 +246,7 @@ GSTextureOGL::GSTextureOGL(int type, int w, int h, int format, GLuint fbo_read,
fprintf(stderr, "Available VRAM is very low (%lld), a crash is expected ! Disable Larger framebuffer or reduce upscaling!\n", GLState::available_vram);
every_512++;
// Pull emergency break
throw GSDXErrorOOM();
throw std::bad_alloc();
}
// Only 32 bits input texture will be supported for mipmap

View File

@ -84,6 +84,5 @@ public:
struct GSDXError {};
struct GSDXRecoverableError : GSDXError {};
struct GSDXErrorOOM : GSDXError {};
extern GSdxApp theApp;