From 8b35685a21c6df5ab3c4dc13d17289e1e7ecc95b Mon Sep 17 00:00:00 2001 From: Glenn Waldron Date: Thu, 10 Oct 2024 13:42:54 -0400 Subject: [PATCH] VideoLayer: add some protection against open failures and bad textures --- src/osgEarth/VideoLayer.cpp | 68 ++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/src/osgEarth/VideoLayer.cpp b/src/osgEarth/VideoLayer.cpp index dfb981c4b8..54ade2c3a6 100644 --- a/src/osgEarth/VideoLayer.cpp +++ b/src/osgEarth/VideoLayer.cpp @@ -47,7 +47,7 @@ OE_LAYER_PROPERTY_IMPL(VideoLayer, URI, URL, url); void VideoLayer::init() { - ImageLayer::init(); + super::init(); // Configure the layer to use createTexture() to return data setUseCreateTexture(); @@ -56,51 +56,51 @@ VideoLayer::init() Status VideoLayer::openImplementation() { - if (!isOpen()) - { - Status parent = ImageLayer::openImplementation(); - if (parent.isError()) - return parent; + Status parent = super::openImplementation(); + if (parent.isError()) + return parent; - if (!options().url().isSet()) - { - return Status(Status::ConfigurationError, "Missing required url"); - } + if (!options().url().isSet()) + { + return Status(Status::ConfigurationError, "Missing required url"); + } - osg::ref_ptr< osg::Image > image = options().url()->readImage().getImage(); - if (image.valid()) - { - osg::ImageStream* is = dynamic_cast< osg::ImageStream*>( image.get() ); - if (is) - { - is->setLoopingMode(osg::ImageStream::LOOPING); - is->play(); - } - - _texture = new osg::Texture2D( image ); - _texture->setResizeNonPowerOfTwoHint( false ); - _texture->setFilter(osg::Texture::MIN_FILTER, osg::Texture2D::LINEAR); - _texture->setFilter(osg::Texture::MAG_FILTER, osg::Texture2D::LINEAR); - _texture->setWrap( osg::Texture::WRAP_S, osg::Texture::REPEAT ); - _texture->setWrap( osg::Texture::WRAP_T, osg::Texture::REPEAT ); - _texture->setUnRefImageDataAfterApply(false); - } - else + osg::ref_ptr< osg::Image > image = options().url()->readImage().getImage(); + if (image.valid()) + { + osg::ImageStream* is = dynamic_cast(image.get()); + if (is) { - std::stringstream buf; - buf << "Failed to load " << options().url()->full(); - return Status(Status::ServiceUnavailable, buf.str()); + is->setLoopingMode(osg::ImageStream::LOOPING); + is->play(); } - setProfile(Profile::create(Profile::GLOBAL_GEODETIC)); + _texture = new osg::Texture2D(image); + _texture->setResizeNonPowerOfTwoHint(false); + _texture->setFilter(osg::Texture::MIN_FILTER, osg::Texture2D::LINEAR); + _texture->setFilter(osg::Texture::MAG_FILTER, osg::Texture2D::LINEAR); + _texture->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT); + _texture->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT); + _texture->setUnRefImageDataAfterApply(false); + } + else + { + std::stringstream buf; + buf << "Failed to load " << options().url()->full(); + return Status(Status::ServiceUnavailable, buf.str()); } + setProfile(Profile::create(Profile::GLOBAL_GEODETIC)); + return getStatus(); } TextureWindow VideoLayer::createTexture(const TileKey& key, ProgressCallback* progress) const -{ +{ + OE_SOFT_ASSERT_AND_RETURN(isOpen(), {}); + OE_SOFT_ASSERT_AND_RETURN(_texture.valid(), {}); + osg::Matrix textureMatrix; bool flip = _texture->getImage()->getOrigin() == osg::Image::TOP_LEFT; key.getExtent().createScaleBias(key.getProfile()->getExtent(), textureMatrix);