From e748e2294ebffa5a833fa34ae78eb5851bb003a8 Mon Sep 17 00:00:00 2001 From: "Seungho, Baek" Date: Mon, 1 Oct 2018 14:18:29 +0900 Subject: [PATCH] Revert "[Tizen] Path length check and coverity issue fix in Scene" This reverts commit 59901599941981c239b53b094a05e321efb06ad5. --- .../internal/controls/scene/gltf-loader.cpp | 63 ++++++++-------------- .../internal/controls/scene/scene-impl.cpp | 5 -- 2 files changed, 22 insertions(+), 46 deletions(-) diff --git a/dali-toolkit/internal/controls/scene/gltf-loader.cpp b/dali-toolkit/internal/controls/scene/gltf-loader.cpp index ebfdae4..f376939 100644 --- a/dali-toolkit/internal/controls/scene/gltf-loader.cpp +++ b/dali-toolkit/internal/controls/scene/gltf-loader.cpp @@ -14,7 +14,6 @@ * limitations under the License. * */ - // CLASS HEADER #include #include @@ -39,14 +38,6 @@ namespace Toolkit namespace Internal { -namespace -{ - -// Maximum path length of linux. -const unsigned int MAX_PATH_LENGTH = 4096; - -}//namespace - GltfLoader::GltfLoader() : mNodes( NULL ), mRoot( NULL ) @@ -72,22 +63,25 @@ bool GltfLoader::LoadScene( const std::string& filePath, Internal::Scene& scene } mRoot = mParser.GetRoot(); - if( mRoot && - LoadAssets() && - CreateScene( scene ) ) + if( !mRoot ) { - return true; + return false; } - return false; -} -bool GltfLoader::ParseGltf( const std::string& filePath ) -{ - if( filePath.length() > MAX_PATH_LENGTH ) + if( !LoadAssets() ) + { + return false; + } + + if( !CreateScene( scene ) ) { - DALI_LOG_ERROR( "File path is too long.\n" ); return false; } + return true; +} + +bool GltfLoader::ParseGltf( const std::string& filePath ) +{ std::ifstream fileStream( filePath.c_str() ); std::string fileBuffer( ( std::istreambuf_iterator( fileStream ) ), ( std::istreambuf_iterator() ) ); @@ -98,10 +92,10 @@ bool GltfLoader::ParseGltf( const std::string& filePath ) bool GltfLoader::LoadAssets() { - if( LoadBinaryData( mRoot ) && - LoadTextureArray( mRoot ) && - LoadMaterialSetArray( mRoot ) && - LoadMeshArray( mRoot ) + if( LoadBinaryData( mRoot ) && // pass a reference + LoadTextureArray( mRoot ) && // pass a reference + LoadMaterialSetArray( mRoot ) && // pass a reference + LoadMeshArray( mRoot ) // pass a reference ) { return true; @@ -361,17 +355,13 @@ bool GltfLoader::LoadTextureArray( const TreeNode* root ) Texture GltfLoader::LoadTexture( const char* imageUrl, bool generateMipmaps ) { Texture texture; - if( std::string( imageUrl ).length() > MAX_PATH_LENGTH ) - { - DALI_LOG_ERROR( "Image path is too long.\n" ); - return texture; - } Devel::PixelBuffer pixelBuffer = LoadImageFromFile( imageUrl ); if( pixelBuffer ) { texture = Texture::New( TextureType::TEXTURE_2D, pixelBuffer.GetPixelFormat(), pixelBuffer.GetWidth(), pixelBuffer.GetHeight() ); PixelData pixelData = Devel::PixelBuffer::Convert( pixelBuffer ); texture.Upload( pixelData ); + if( generateMipmaps ) { texture.GenerateMipmaps(); @@ -1125,6 +1115,7 @@ Actor GltfLoader::AddNode( Scene& scene, int index ) if( ( tempNode = node->GetChild( "mesh" ) ) ) { MeshInfo meshInfo = mMeshArray[tempNode->GetInteger()]; + GLTF::MaterialInfo materialInfo = mMaterialArray[meshInfo.materialsIdx]; bool isMaterial = ( meshInfo.materialsIdx >= 0 ); TextureSet textureSet; @@ -1147,7 +1138,6 @@ Actor GltfLoader::AddNode( Scene& scene, int index ) bool useIBL = ( scene.GetLightType() >= Toolkit::Scene::LightType::IMAGE_BASED_LIGHT ); if( isMaterial ) { - GLTF::MaterialInfo materialInfo = mMaterialArray[meshInfo.materialsIdx]; if( SetTextureAndSampler( textureSet, materialInfo.baseColorTexture.index, FRAGMENT_SHADER, DEFINE_BASECOLOR_TEXTURE, addIdx ) ) { shaderTypeIndex += static_cast( ShaderType::BASECOLOR_SHADER ); @@ -1234,7 +1224,6 @@ Actor GltfLoader::AddNode( Scene& scene, int index ) actor.RegisterProperty( "uIsColor", meshInfo.attribute.COLOR.size() > 0 ); if( isMaterial ) { - GLTF::MaterialInfo materialInfo = mMaterialArray[meshInfo.materialsIdx]; actor.RegisterProperty( "uBaseColorFactor", materialInfo.baseColorFactor ); actor.RegisterProperty( "uMetallicRoughnessFactors", Vector2( materialInfo.metallicFactor, materialInfo.roughnessFactor ) ); @@ -1514,22 +1503,14 @@ bool GltfLoader::LoadAnimationSamplers( const TreeNode& animation, AnimationInfo template bool GltfLoader::ReadBinFile( Vector &dataBuffer, std::string url, int offset, int count ) { - if( url.length() > MAX_PATH_LENGTH ) - { - DALI_LOG_ERROR( "Binary file path is too long.\n" ); - return false; - } dataBuffer.Resize( count ); FILE* fp = fopen( url.c_str(), "rb" ); - if( fp == NULL ) + if( NULL == fp ) { return false; } - ssize_t result = -1; - if( !fseek( fp, offset, SEEK_SET ) ) - { - result = fread( &dataBuffer[0], sizeof( T ), count, fp ); - } + fseek( fp, offset, SEEK_SET ); + ssize_t result = fread( &dataBuffer[0], sizeof( T ), count, fp ); fclose( fp ); return ( result >= 0 ); diff --git a/dali-toolkit/internal/controls/scene/scene-impl.cpp b/dali-toolkit/internal/controls/scene/scene-impl.cpp index c09f21c..2c70685 100644 --- a/dali-toolkit/internal/controls/scene/scene-impl.cpp +++ b/dali-toolkit/internal/controls/scene/scene-impl.cpp @@ -14,7 +14,6 @@ * limitations under the License. * */ - // CLASS HEADER #include "scene-impl.h" @@ -178,10 +177,6 @@ void Scene::UploadTextureFace( Texture& texture, Devel::PixelBuffer pixelBuffer, { faceSize = imageWidth / 6; } - else - { - return; - } unsigned int xOffset = cubeMap_index_x[cubeType][faceIndex] * faceSize; unsigned int yOffset = cubeMap_index_y[cubeType][faceIndex] * faceSize; -- 2.7.4