From e890ce989ce94226ca4381a2cdfcd68624418bb3 Mon Sep 17 00:00:00 2001 From: Gregory Hainaut Date: Thu, 5 May 2016 18:01:44 +0200 Subject: [PATCH] gsdx: throw oom exception + error Texture can't be NULL anymore, so we can remove a couples of check --- plugins/GSdx/GSDevice11.cpp | 3 +++ plugins/GSdx/GSDevice9.cpp | 6 ++++++ plugins/GSdx/GSDeviceOGL.cpp | 3 +++ plugins/GSdx/GSRendererHW.cpp | 24 +++++++++++------------- plugins/GSdx/GSTextureCache.cpp | 23 +++++------------------ 5 files changed, 28 insertions(+), 31 deletions(-) diff --git a/plugins/GSdx/GSDevice11.cpp b/plugins/GSdx/GSDevice11.cpp index a09ff0a351..073c4a8322 100644 --- a/plugins/GSdx/GSDevice11.cpp +++ b/plugins/GSdx/GSDevice11.cpp @@ -523,6 +523,9 @@ 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) { diff --git a/plugins/GSdx/GSDevice9.cpp b/plugins/GSdx/GSDevice9.cpp index 4d0a6ad446..13f52b052c 100644 --- a/plugins/GSdx/GSDevice9.cpp +++ b/plugins/GSdx/GSDevice9.cpp @@ -718,11 +718,17 @@ 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) diff --git a/plugins/GSdx/GSDeviceOGL.cpp b/plugins/GSdx/GSDeviceOGL.cpp index 23ffca7c06..ca241aa74d 100644 --- a/plugins/GSdx/GSDeviceOGL.cpp +++ b/plugins/GSdx/GSDeviceOGL.cpp @@ -142,6 +142,9 @@ GSTexture* GSDeviceOGL::CreateSurface(int type, int w, int h, bool msaa, int fmt // A wrapper to call GSTextureOGL, with the different kind of parameter GSTextureOGL* t = NULL; t = new GSTextureOGL(type, w, h, fmt, m_fbo_read); + if (t == NULL) { + throw GSDXErrorOOM(); + } // NOTE: I'm not sure RenderTarget always need to be cleared. It could be costly for big upscale. switch(type) diff --git a/plugins/GSdx/GSRendererHW.cpp b/plugins/GSdx/GSRendererHW.cpp index 578cff6532..4164e9a774 100644 --- a/plugins/GSdx/GSRendererHW.cpp +++ b/plugins/GSdx/GSRendererHW.cpp @@ -412,20 +412,22 @@ void GSRendererHW::Draw() TEX0.TBW = context->FRAME.FBW; TEX0.PSM = context->FRAME.PSM; - GSTextureCache::Target* rt = no_rt ? NULL : m_tc->LookupTarget(TEX0, m_width, m_height, GSTextureCache::RenderTarget, true); - GSTexture* rt_tex = rt ? rt->m_texture : NULL; + GSTextureCache::Target* rt = NULL; + GSTexture* rt_tex = NULL; + if (!no_rt) { + rt = m_tc->LookupTarget(TEX0, m_width, m_height, GSTextureCache::RenderTarget, true); + rt_tex = rt->m_texture; + } TEX0.TBP0 = context->ZBUF.Block(); TEX0.TBW = context->FRAME.FBW; TEX0.PSM = context->ZBUF.PSM; - GSTextureCache::Target* ds = no_ds ? NULL : m_tc->LookupTarget(TEX0, m_width, m_height, GSTextureCache::DepthStencil, context->DepthWrite()); - GSTexture* ds_tex = ds ? ds->m_texture : NULL; - - if(!(rt || no_rt) || !(ds || no_ds)) - { - ASSERT(0); - return; + GSTextureCache::Target* ds = NULL; + GSTexture* ds_tex = NULL; + if (!no_ds) { + ds = m_tc->LookupTarget(TEX0, m_width, m_height, GSTextureCache::DepthStencil, context->DepthWrite()); + ds_tex = ds->m_texture; } GSTextureCache::Source* tex = NULL; @@ -452,10 +454,6 @@ void GSRendererHW::Draw() tex = tex_psm.depth ? m_tc->LookupDepthSource(context->TEX0, env.TEXA, r) : m_tc->LookupSource(context->TEX0, env.TEXA, r); - if(!tex) { - return; - } - // FIXME: Could be removed on openGL if(tex_psm.pal > 0) { diff --git a/plugins/GSdx/GSTextureCache.cpp b/plugins/GSdx/GSTextureCache.cpp index 4099028506..0cf7df7727 100644 --- a/plugins/GSdx/GSTextureCache.cpp +++ b/plugins/GSdx/GSTextureCache.cpp @@ -87,7 +87,7 @@ void GSTextureCache::RemoveAll() GSTextureCache::Source* GSTextureCache::LookupDepthSource(const GIFRegTEX0& TEX0, const GIFRegTEXA& TEXA, const GSVector4i& r, bool palette) { - if (!CanConvertDepth()) return NULL; + if (!CanConvertDepth()) throw GSDXRecoverableError(); const GSLocalMemory::psm_t& psm_s = GSLocalMemory::m_psm[TEX0.PSM]; @@ -332,11 +332,6 @@ GSTextureCache::Source* GSTextureCache::LookupSource(const GIFRegTEX0& TEX0, con #endif src = CreateSource(TEX0, TEXA, dst, half_right); - if(src == NULL) - { - return NULL; - } - } else { GL_CACHE("TC: src hit: %d (0x%x, F:0x%x)", src->m_texture ? src->m_texture->GetID() : 0, @@ -432,9 +427,6 @@ GSTextureCache::Target* GSTextureCache::LookupTarget(const GIFRegTEX0& TEX0, int dst = CreateTarget(TEX0, w, h, type); - if(dst == NULL) - return NULL; - // In theory new textures contain invalidated data. Still in theory a new target // must contains the content of the GS memory. // In practice, TC will wrongly invalidate some RT. For example due to write on the alpha @@ -594,11 +586,6 @@ GSTextureCache::Target* GSTextureCache::LookupTarget(const GIFRegTEX0& TEX0, int dst = CreateTarget(TEX0, w, h, RenderTarget); - if(dst == NULL) - { - return NULL; - } - m_renderer->m_dev->ClearRenderTarget(dst->m_texture, 0); // new frame buffers after reset should be cleared, don't display memory garbage if (m_preload_frame) { @@ -1076,6 +1063,7 @@ 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; @@ -1370,9 +1358,8 @@ GSTextureCache::Source* GSTextureCache::CreateSource(const GIFRegTEX0& TEX0, con if(src->m_texture == NULL) { - ASSERT(0); delete src; - return NULL; + throw GSDXErrorOOM(); } if(psm.pal > 0) @@ -1388,6 +1375,7 @@ GSTextureCache::Source* GSTextureCache::CreateSource(const GIFRegTEX0& TEX0, con GSTextureCache::Target* GSTextureCache::CreateTarget(const GIFRegTEX0& TEX0, int w, int h, int type) { 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 @@ -1406,9 +1394,8 @@ GSTextureCache::Target* GSTextureCache::CreateTarget(const GIFRegTEX0& TEX0, int if(t->m_texture == NULL) { - ASSERT(0); delete t; - return NULL; + throw GSDXErrorOOM(); } m_dst[type].push_front(t);