From bcd0c74c7392dd0b3f85f2d2d3cb659959090f9f Mon Sep 17 00:00:00 2001 From: Ferran Sole Date: Tue, 6 Dec 2016 09:33:51 +0000 Subject: [PATCH] Stop calling destroy methods of texture and FrameBuffers on RenderManager destructor Textures and FrameBuffers GL resources where being destroyed on RenderManager destructor which is called from event thread causing crashes on some GL drivers. Removed destruction of texture and framebuffer resources since they will be cleaned up automatically when the GL context is destroyed Change-Id: I8bd4d79399554179819e091e662ea0c9a6e0bc5f --- automated-tests/src/dali/utc-Dali-FrameBuffer.cpp | 23 ++++++++++++++++++++++ automated-tests/src/dali/utc-Dali-Texture.cpp | 20 +++++++++++++++++++ dali/internal/render/common/render-manager.cpp | 22 +++++++++++---------- .../render/renderers/render-frame-buffer.cpp | 5 +++++ .../render/renderers/render-frame-buffer.h | 5 +++++ dali/internal/render/renderers/render-texture.cpp | 5 +++++ dali/internal/render/renderers/render-texture.h | 5 +++++ 7 files changed, 75 insertions(+), 10 deletions(-) diff --git a/automated-tests/src/dali/utc-Dali-FrameBuffer.cpp b/automated-tests/src/dali/utc-Dali-FrameBuffer.cpp index f0e295b..6278193 100644 --- a/automated-tests/src/dali/utc-Dali-FrameBuffer.cpp +++ b/automated-tests/src/dali/utc-Dali-FrameBuffer.cpp @@ -312,3 +312,26 @@ int UtcDaliFrameBufferGetColorTexture02(void) END_TEST; } +int UtcDaliFramebufferContextLoss(void) +{ + tet_infoline("UtcDaliFramebufferContextLoss\n"); + TestApplication application; // Default config: DALI_DISCARDS_ALL_DATA + + //Create the texture + unsigned int width(64); + unsigned int height(64); + Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height ); + DALI_TEST_CHECK( texture ); + FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE ); + DALI_TEST_CHECK( frameBuffer ); + frameBuffer.AttachColorTexture( texture, 0u, 1u ); + + application.SendNotification(); + application.Render(16); + + // Lose & regain context (in render 'thread') + application.ResetContext(); + DALI_TEST_CHECK( frameBuffer ); + + END_TEST; +} diff --git a/automated-tests/src/dali/utc-Dali-Texture.cpp b/automated-tests/src/dali/utc-Dali-Texture.cpp index 8620381..8ae96f0 100644 --- a/automated-tests/src/dali/utc-Dali-Texture.cpp +++ b/automated-tests/src/dali/utc-Dali-Texture.cpp @@ -612,3 +612,23 @@ int UtcDaliTextureGetHeight(void) END_TEST; } +int UtcDaliTextureContextLoss(void) +{ + tet_infoline("UtcDaliTextureContextLoss\n"); + TestApplication application; // Default config: DALI_DISCARDS_ALL_DATA + + //Create the texture + unsigned int width(64); + unsigned int height(64); + Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height ); + DALI_TEST_CHECK( texture ); + + application.SendNotification(); + application.Render(16); + + // Lose & regain context (in render 'thread') + application.ResetContext(); + DALI_TEST_CHECK( texture ); + + END_TEST; +} diff --git a/dali/internal/render/common/render-manager.cpp b/dali/internal/render/common/render-manager.cpp index aac80f6..1e141d0 100644 --- a/dali/internal/render/common/render-manager.cpp +++ b/dali/internal/render/common/render-manager.cpp @@ -189,16 +189,6 @@ RenderManager::RenderManager() RenderManager::~RenderManager() { - for ( TextureOwnerIter iter = mImpl->textureContainer.Begin(); iter != mImpl->textureContainer.End(); ++iter ) - { - (*iter)->Destroy( mImpl->context ); - } - - for ( FrameBufferOwnerIter iter = mImpl->frameBufferContainer.Begin(); iter != mImpl->frameBufferContainer.End(); ++iter ) - { - (*iter)->Destroy( mImpl->context ); - } - delete mImpl; } @@ -229,6 +219,18 @@ void RenderManager::ContextDestroyed() // inform texture cache mImpl->textureCache.GlContextDestroyed(); // Clears gl texture ids + //Inform textures + for( TextureOwnerIter iter = mImpl->textureContainer.Begin(); iter != mImpl->textureContainer.End(); ++iter ) + { + (*iter)->GlContextDestroyed(); + } + + //Inform framebuffers + for( FrameBufferOwnerIter iter = mImpl->frameBufferContainer.Begin(); iter != mImpl->frameBufferContainer.End(); ++iter ) + { + (*iter)->GlContextDestroyed(); + } + // inform renderers RendererOwnerContainer::Iterator end = mImpl->rendererContainer.End(); RendererOwnerContainer::Iterator iter = mImpl->rendererContainer.Begin(); diff --git a/dali/internal/render/renderers/render-frame-buffer.cpp b/dali/internal/render/renderers/render-frame-buffer.cpp index b0cad27..2799893 100644 --- a/dali/internal/render/renderers/render-frame-buffer.cpp +++ b/dali/internal/render/renderers/render-frame-buffer.cpp @@ -47,6 +47,11 @@ void FrameBuffer::Destroy( Context& context ) } } +void FrameBuffer::GlContextDestroyed() +{ + mId = 0u; +} + void FrameBuffer::Initialize(Context& context) { context.GenFramebuffers( 1, &mId ); diff --git a/dali/internal/render/renderers/render-frame-buffer.h b/dali/internal/render/renderers/render-frame-buffer.h index e27e072..9240c69 100644 --- a/dali/internal/render/renderers/render-frame-buffer.h +++ b/dali/internal/render/renderers/render-frame-buffer.h @@ -62,6 +62,11 @@ public: void Destroy( Context& context ); /** + * Called by RenderManager to inform the framebuffer that the context has been destroyed + */ + void GlContextDestroyed(); + + /** * @brief Attach a texture for color rendering. Valid only for Framebuffers with COLOR attachments. * param[in] context The GL context * @param[in] texture The texture that will be used as output when rendering diff --git a/dali/internal/render/renderers/render-texture.cpp b/dali/internal/render/renderers/render-texture.cpp index 36df6f5..a1e6aae 100644 --- a/dali/internal/render/renderers/render-texture.cpp +++ b/dali/internal/render/renderers/render-texture.cpp @@ -633,6 +633,11 @@ void NewTexture::Destroy( Context& context ) } } +void NewTexture::GlContextDestroyed() +{ + mId = 0u; +} + void NewTexture::Initialize(Context& context) { if( mNativeImage ) diff --git a/dali/internal/render/renderers/render-texture.h b/dali/internal/render/renderers/render-texture.h index 8e3dc3d..74255cc 100644 --- a/dali/internal/render/renderers/render-texture.h +++ b/dali/internal/render/renderers/render-texture.h @@ -134,6 +134,11 @@ public: void Destroy( Context& context ); /** + * Called by RenderManager to inform the texture that the context has been destroyed + */ + void GlContextDestroyed(); + + /** * Uploads data to the texture. * @param[in] context The GL context * @param[in] pixelData A pixel data object -- 2.7.4