Valgrind fix for uninitialized values in Render::Sampler 71/117271/2
authorNick Holland <nick.holland@partner.samsung.com>
Fri, 3 Mar 2017 12:23:06 +0000 (12:23 +0000)
committerNick Holland <nick.holland@partner.samsung.com>
Fri, 3 Mar 2017 12:35:56 +0000 (12:35 +0000)
commit90bcaa8fcf23f54fa0876f1edbf071c4867627dd
treeee7a8694c02a33731be70f83573d5ad22f77998e
parent78f33f00abde38801e76509b624fde9226005634
Valgrind fix for uninitialized values in Render::Sampler

Valgrind reported conditional jump depends on uninit values in:
  if( mSampler.mBitField != oldSampler.mBitField ) // Texture::ApplySampler

Problem was down to Sampler having a anonymous union:

  union
  {
    unsigned int mBitfield;

    struct
    {
      FilterMode  mMinificationFilter   : 4;    ///< The minify filter
      FilterMode  mMagnificationFilter  : 4;    ///< The magnify filter
      WrapMode    mSWrapMode            : 4;    ///< The horizontal wrap mode
      WrapMode    mTWrapMode            : 4;    ///< The vertical wrap mode
      WrapMode    mRWrapMode            : 4;    ///< The vertical wrap mode
    };
  };

Fundamentally the size of the bit field struct
can be larger than the size of the unsigned int mBitfield, so using mBitfield to compare Samplers
isn't reliable.

The issue valgrind picked up on is, only 20 bits of the
mBitfield are being set in the sampler constructor
  Sampler()
  :mMinificationFilter(FilterMode::DEFAULT),
   mMagnificationFilter(FilterMode::DEFAULT),
   mSWrapMode(WrapMode::DEFAULT),
   mTWrapMode(WrapMode::DEFAULT),
   mRWrapMode(WrapMode::DEFAULT)
  {}

Solution is to remove the union

Change-Id: Id66afc05d21377a1363448ef10654cd1ab4bb365
dali/internal/render/renderers/render-sampler.h
dali/internal/render/renderers/render-texture.cpp