Fix: Use of uninitialized variables in Mantaflow

A constructor of the MANTA() constructor is only default-initializing
some of the fields, while initializeRNAMap() access to all of the fields,
causing access to uninitialized variables.

For example, mResXMesh is only initialized within some conditions about
mUsingLiquid and mUsingMesh but is always used to set value in the map.

Additionally fixed re-reference of iterator which equals to end(): the
iterator in such case does not contain value and it should not be accessed.

Pull Request: https://projects.blender.org/blender/blender/pulls/144502
This commit is contained in:
Sergey Sharybin
2025-08-14 10:57:27 +02:00
committed by Sergey Sharybin
parent 7d384b4a01
commit 3c4e48e8ca
2 changed files with 101 additions and 102 deletions

View File

@@ -1143,8 +1143,7 @@ string MANTA::getRealValue(const string &varName)
it = mRNAMap.find(varName); it = mRNAMap.find(varName);
if (it == mRNAMap.end()) { if (it == mRNAMap.end()) {
cerr << "Fluid Error -- variable " << varName << " not found in RNA map " << it->second cerr << "Fluid Error -- variable " << varName << " not found in RNA map" << endl;
<< endl;
return ""; return "";
} }

View File

@@ -722,123 +722,123 @@ struct MANTA {
private: private:
/* Simulation constants. */ /* Simulation constants. */
size_t mTotalCells; size_t mTotalCells = -1;
size_t mTotalCellsHigh; size_t mTotalCellsHigh = -1;
size_t mTotalCellsMesh; size_t mTotalCellsMesh = -1;
size_t mTotalCellsParticles; size_t mTotalCellsParticles = -1;
unordered_map<string, string> mRNAMap; unordered_map<string, string> mRNAMap;
/* The ID of the solver objects will be incremented for every new object. */ /* The ID of the solver objects will be incremented for every new object. */
const int mCurrentID; const int mCurrentID;
bool mUsingHeat; bool mUsingHeat = false;
bool mUsingColors; bool mUsingColors = false;
bool mUsingFire; bool mUsingFire = false;
bool mUsingObstacle; bool mUsingObstacle = false;
bool mUsingGuiding; bool mUsingGuiding = false;
bool mUsingFractions; bool mUsingFractions = false;
bool mUsingInvel; bool mUsingInvel = false;
bool mUsingOutflow; bool mUsingOutflow = false;
bool mUsingNoise; bool mUsingNoise = false;
bool mUsingMesh; bool mUsingMesh = false;
bool mUsingDiffusion; bool mUsingDiffusion = false;
bool mUsingViscosity; bool mUsingViscosity = false;
bool mUsingMVel; bool mUsingMVel = false;
bool mUsingLiquid; bool mUsingLiquid = false;
bool mUsingSmoke; bool mUsingSmoke = false;
bool mUsingDrops; bool mUsingDrops = false;
bool mUsingBubbles; bool mUsingBubbles = false;
bool mUsingFloats; bool mUsingFloats = false;
bool mUsingTracers; bool mUsingTracers = false;
bool mFlipFromFile; bool mFlipFromFile = false;
bool mMeshFromFile; bool mMeshFromFile = false;
bool mParticlesFromFile; bool mParticlesFromFile = false;
bool mSmokeFromFile; bool mSmokeFromFile = false;
bool mNoiseFromFile; bool mNoiseFromFile = false;
int mResX; int mResX = -1;
int mResY; int mResY = -1;
int mResZ; int mResZ = -1;
const int mMaxRes; const int mMaxRes;
int mResXNoise; int mResXNoise = -1;
int mResYNoise; int mResYNoise = -1;
int mResZNoise; int mResZNoise = -1;
int mResXMesh; int mResXMesh = -1;
int mResYMesh; int mResYMesh = -1;
int mResZMesh; int mResZMesh = -1;
int mResXParticle; int mResXParticle = -1;
int mResYParticle; int mResYParticle = -1;
int mResZParticle; int mResZParticle = -1;
int *mResGuiding; int *mResGuiding = nullptr;
int mUpresMesh; int mUpresMesh = -1;
int mUpresParticle; int mUpresParticle = -1;
/* Fluid grids. */ /* Fluid grids. */
float *mVelocityX; float *mVelocityX = nullptr;
float *mVelocityY; float *mVelocityY = nullptr;
float *mVelocityZ; float *mVelocityZ = nullptr;
float *mObVelocityX; float *mObVelocityX = nullptr;
float *mObVelocityY; float *mObVelocityY = nullptr;
float *mObVelocityZ; float *mObVelocityZ = nullptr;
float *mGuideVelocityX; float *mGuideVelocityX = nullptr;
float *mGuideVelocityY; float *mGuideVelocityY = nullptr;
float *mGuideVelocityZ; float *mGuideVelocityZ = nullptr;
float *mInVelocityX; float *mInVelocityX = nullptr;
float *mInVelocityY; float *mInVelocityY = nullptr;
float *mInVelocityZ; float *mInVelocityZ = nullptr;
float *mForceX; float *mForceX = nullptr;
float *mForceY; float *mForceY = nullptr;
float *mForceZ; float *mForceZ = nullptr;
int *mFlags; int *mFlags = nullptr;
float *mNumObstacle; float *mNumObstacle = nullptr;
float *mNumGuide; float *mNumGuide = nullptr;
float *mPressure; float *mPressure = nullptr;
/* Smoke grids. */ /* Smoke grids. */
float *mDensity; float *mDensity = nullptr;
float *mHeat; float *mHeat = nullptr;
float *mFlame; float *mFlame = nullptr;
float *mFuel; float *mFuel = nullptr;
float *mReact; float *mReact = nullptr;
float *mColorR; float *mColorR = nullptr;
float *mColorG; float *mColorG = nullptr;
float *mColorB; float *mColorB = nullptr;
float *mShadow; float *mShadow = nullptr;
float *mDensityIn; float *mDensityIn = nullptr;
float *mHeatIn; float *mHeatIn = nullptr;
float *mFuelIn; float *mFuelIn = nullptr;
float *mReactIn; float *mReactIn = nullptr;
float *mEmissionIn; float *mEmissionIn = nullptr;
float *mColorRIn; float *mColorRIn = nullptr;
float *mColorGIn; float *mColorGIn = nullptr;
float *mColorBIn; float *mColorBIn = nullptr;
float *mDensityHigh; float *mDensityHigh = nullptr;
float *mFlameHigh; float *mFlameHigh = nullptr;
float *mFuelHigh; float *mFuelHigh = nullptr;
float *mReactHigh; float *mReactHigh = nullptr;
float *mColorRHigh; float *mColorRHigh = nullptr;
float *mColorGHigh; float *mColorGHigh = nullptr;
float *mColorBHigh; float *mColorBHigh = nullptr;
float *mTextureU; float *mTextureU = nullptr;
float *mTextureV; float *mTextureV = nullptr;
float *mTextureW; float *mTextureW = nullptr;
float *mTextureU2; float *mTextureU2 = nullptr;
float *mTextureV2; float *mTextureV2 = nullptr;
float *mTextureW2; float *mTextureW2 = nullptr;
/* Liquid grids. */ /* Liquid grids. */
float *mPhiIn; float *mPhiIn = nullptr;
float *mPhiStaticIn; float *mPhiStaticIn = nullptr;
float *mPhiObsIn; float *mPhiObsIn = nullptr;
float *mPhiObsStaticIn; float *mPhiObsStaticIn = nullptr;
float *mPhiGuideIn; float *mPhiGuideIn = nullptr;
float *mPhiOutIn; float *mPhiOutIn = nullptr;
float *mPhiOutStaticIn; float *mPhiOutStaticIn = nullptr;
float *mPhi; float *mPhi = nullptr;
/* Mesh fields. */ /* Mesh fields. */
vector<Node> *mMeshNodes; vector<Node> *mMeshNodes;