From fcfbcca49a4589fe63a63714fd79fc2ee624992a Mon Sep 17 00:00:00 2001 From: Ulysse Martin Date: Fri, 3 Mar 2017 23:13:19 +0100 Subject: [PATCH] UPBGE: Fix a crash on Windows when mipmap is True with VideoFFmpeg up to date with master 03/03/2017 --- source/gameengine/VideoTexture/ImageBase.cpp | 3 ++- source/gameengine/VideoTexture/ImageBase.h | 9 +++++++++ source/gameengine/VideoTexture/ImageRender.cpp | 2 ++ source/gameengine/VideoTexture/ImageViewport.cpp | 1 + source/gameengine/VideoTexture/Texture.cpp | 15 ++++++++++++--- source/gameengine/VideoTexture/VideoFFmpeg.cpp | 1 + 6 files changed, 27 insertions(+), 4 deletions(-) diff --git a/source/gameengine/VideoTexture/ImageBase.cpp b/source/gameengine/VideoTexture/ImageBase.cpp index cfa37162f42e..a6c2bfe71627 100644 --- a/source/gameengine/VideoTexture/ImageBase.cpp +++ b/source/gameengine/VideoTexture/ImageBase.cpp @@ -64,7 +64,8 @@ ImageBase::ImageBase (bool staticSrc) : m_image(nullptr), m_imgSize(0), m_intern m_avail(false), m_scale(false), m_scaleChange(false), m_flip(false), m_zbuff(false), m_depth(false), -m_staticSources(staticSrc), m_pyfilter(nullptr) +m_type(IMAGE_NONE), +m_staticSources(staticSrc), m_pyfilter(NULL) { m_size[0] = m_size[1] = 0; m_exports = 0; diff --git a/source/gameengine/VideoTexture/ImageBase.h b/source/gameengine/VideoTexture/ImageBase.h index fff2cadaa666..b5b0a5316d70 100644 --- a/source/gameengine/VideoTexture/ImageBase.h +++ b/source/gameengine/VideoTexture/ImageBase.h @@ -120,6 +120,15 @@ class ImageBase /// number of buffer pointing to m_image, public because not handled by this class int m_exports; + /// type of the image + enum { + IMAGE_RENDER, + IMAGE_VIEWPORT, + IMAGE_VIDEO, + IMAGE_MIRROR, + IMAGE_NONE + } m_type; + protected: /// image buffer unsigned int * m_image; diff --git a/source/gameengine/VideoTexture/ImageRender.cpp b/source/gameengine/VideoTexture/ImageRender.cpp index f0d26acefa9a..8a72211ca4b6 100644 --- a/source/gameengine/VideoTexture/ImageRender.cpp +++ b/source/gameengine/VideoTexture/ImageRender.cpp @@ -91,6 +91,7 @@ ImageRender::ImageRender (KX_Scene *scene, KX_Camera * camera, unsigned int widt m_engine = KX_GetActiveEngine(); m_rasterizer = m_engine->GetRasterizer(); m_canvas = m_engine->GetCanvas(); + m_type = IMAGE_RENDER; GPUHDRType type; if (hdr == RAS_IRasterizer::RAS_HDR_HALF_FLOAT) { @@ -878,6 +879,7 @@ ImageRender::ImageRender (KX_Scene *scene, KX_GameObject *observer, KX_GameObjec m_mirror(mirror), m_clip(100.f) { + m_type = IMAGE_MIRROR; GPUHDRType type; if (hdr == RAS_IRasterizer::RAS_HDR_HALF_FLOAT) { type = GPU_HDR_HALF_FLOAT; diff --git a/source/gameengine/VideoTexture/ImageViewport.cpp b/source/gameengine/VideoTexture/ImageViewport.cpp index df825d2ac893..761494fc1eea 100644 --- a/source/gameengine/VideoTexture/ImageViewport.cpp +++ b/source/gameengine/VideoTexture/ImageViewport.cpp @@ -72,6 +72,7 @@ ImageViewport::ImageViewport() m_viewportImage = new BYTE [4 * getViewportSize()[0] * getViewportSize()[1]]; // set attributes setWhole(true); + m_type = IMAGE_VIEWPORT; } // constructor diff --git a/source/gameengine/VideoTexture/Texture.cpp b/source/gameengine/VideoTexture/Texture.cpp index d7bdd5a45764..cb9c7e842ea0 100644 --- a/source/gameengine/VideoTexture/Texture.cpp +++ b/source/gameengine/VideoTexture/Texture.cpp @@ -479,10 +479,19 @@ int Texture::pyattr_set_mipmap(PyObjectPlus *self_v, const KX_PYATTRIBUTE_DEF *a PyErr_SetString(PyExc_TypeError, "The value must be a bool"); return -1; } + if (!self->m_source) { + PyErr_SetString(PyExc_ValueError, "The texture source must be set before setting mipmap"); + return -1; + } // set mipmap - self->m_mipmap = value == Py_True; - // success - return 0; + if (self->m_source->m_image && + self->m_source->m_image->m_type != ImageBase::IMAGE_VIDEO) { + self->m_mipmap = value == Py_True; + // success + return 0; + } + PyErr_SetString(PyExc_TypeError, "Videos can't have mipmap"); + return -1; } // get source object diff --git a/source/gameengine/VideoTexture/VideoFFmpeg.cpp b/source/gameengine/VideoTexture/VideoFFmpeg.cpp index 2f85b48899e6..26baf3b158e3 100644 --- a/source/gameengine/VideoTexture/VideoFFmpeg.cpp +++ b/source/gameengine/VideoTexture/VideoFFmpeg.cpp @@ -80,6 +80,7 @@ m_isThreaded(false), m_isStreaming(false), m_stopThread(false), m_cacheStarted(f BLI_listbase_clear(&m_frameCacheBase); BLI_listbase_clear(&m_packetCacheFree); BLI_listbase_clear(&m_packetCacheBase); + m_type = IMAGE_VIDEO; } // destructor