From 3c4e48e8caa0777ec315846d5df2535a04e405d5 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Thu, 14 Aug 2025 10:57:27 +0200 Subject: [PATCH] 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 --- intern/mantaflow/intern/MANTA_main.cpp | 3 +- intern/mantaflow/intern/MANTA_main.h | 200 ++++++++++++------------- 2 files changed, 101 insertions(+), 102 deletions(-) diff --git a/intern/mantaflow/intern/MANTA_main.cpp b/intern/mantaflow/intern/MANTA_main.cpp index 2217e45268b..411bc3a8459 100644 --- a/intern/mantaflow/intern/MANTA_main.cpp +++ b/intern/mantaflow/intern/MANTA_main.cpp @@ -1143,8 +1143,7 @@ string MANTA::getRealValue(const string &varName) it = mRNAMap.find(varName); if (it == mRNAMap.end()) { - cerr << "Fluid Error -- variable " << varName << " not found in RNA map " << it->second - << endl; + cerr << "Fluid Error -- variable " << varName << " not found in RNA map" << endl; return ""; } diff --git a/intern/mantaflow/intern/MANTA_main.h b/intern/mantaflow/intern/MANTA_main.h index 3f7b75e2cba..7a2cb4c88f1 100644 --- a/intern/mantaflow/intern/MANTA_main.h +++ b/intern/mantaflow/intern/MANTA_main.h @@ -722,123 +722,123 @@ struct MANTA { private: /* Simulation constants. */ - size_t mTotalCells; - size_t mTotalCellsHigh; - size_t mTotalCellsMesh; - size_t mTotalCellsParticles; + size_t mTotalCells = -1; + size_t mTotalCellsHigh = -1; + size_t mTotalCellsMesh = -1; + size_t mTotalCellsParticles = -1; unordered_map mRNAMap; /* The ID of the solver objects will be incremented for every new object. */ const int mCurrentID; - bool mUsingHeat; - bool mUsingColors; - bool mUsingFire; - bool mUsingObstacle; - bool mUsingGuiding; - bool mUsingFractions; - bool mUsingInvel; - bool mUsingOutflow; - bool mUsingNoise; - bool mUsingMesh; - bool mUsingDiffusion; - bool mUsingViscosity; - bool mUsingMVel; - bool mUsingLiquid; - bool mUsingSmoke; - bool mUsingDrops; - bool mUsingBubbles; - bool mUsingFloats; - bool mUsingTracers; + bool mUsingHeat = false; + bool mUsingColors = false; + bool mUsingFire = false; + bool mUsingObstacle = false; + bool mUsingGuiding = false; + bool mUsingFractions = false; + bool mUsingInvel = false; + bool mUsingOutflow = false; + bool mUsingNoise = false; + bool mUsingMesh = false; + bool mUsingDiffusion = false; + bool mUsingViscosity = false; + bool mUsingMVel = false; + bool mUsingLiquid = false; + bool mUsingSmoke = false; + bool mUsingDrops = false; + bool mUsingBubbles = false; + bool mUsingFloats = false; + bool mUsingTracers = false; - bool mFlipFromFile; - bool mMeshFromFile; - bool mParticlesFromFile; - bool mSmokeFromFile; - bool mNoiseFromFile; + bool mFlipFromFile = false; + bool mMeshFromFile = false; + bool mParticlesFromFile = false; + bool mSmokeFromFile = false; + bool mNoiseFromFile = false; - int mResX; - int mResY; - int mResZ; + int mResX = -1; + int mResY = -1; + int mResZ = -1; const int mMaxRes; - int mResXNoise; - int mResYNoise; - int mResZNoise; - int mResXMesh; - int mResYMesh; - int mResZMesh; - int mResXParticle; - int mResYParticle; - int mResZParticle; - int *mResGuiding; + int mResXNoise = -1; + int mResYNoise = -1; + int mResZNoise = -1; + int mResXMesh = -1; + int mResYMesh = -1; + int mResZMesh = -1; + int mResXParticle = -1; + int mResYParticle = -1; + int mResZParticle = -1; + int *mResGuiding = nullptr; - int mUpresMesh; - int mUpresParticle; + int mUpresMesh = -1; + int mUpresParticle = -1; /* Fluid grids. */ - float *mVelocityX; - float *mVelocityY; - float *mVelocityZ; - float *mObVelocityX; - float *mObVelocityY; - float *mObVelocityZ; - float *mGuideVelocityX; - float *mGuideVelocityY; - float *mGuideVelocityZ; - float *mInVelocityX; - float *mInVelocityY; - float *mInVelocityZ; - float *mForceX; - float *mForceY; - float *mForceZ; - int *mFlags; - float *mNumObstacle; - float *mNumGuide; - float *mPressure; + float *mVelocityX = nullptr; + float *mVelocityY = nullptr; + float *mVelocityZ = nullptr; + float *mObVelocityX = nullptr; + float *mObVelocityY = nullptr; + float *mObVelocityZ = nullptr; + float *mGuideVelocityX = nullptr; + float *mGuideVelocityY = nullptr; + float *mGuideVelocityZ = nullptr; + float *mInVelocityX = nullptr; + float *mInVelocityY = nullptr; + float *mInVelocityZ = nullptr; + float *mForceX = nullptr; + float *mForceY = nullptr; + float *mForceZ = nullptr; + int *mFlags = nullptr; + float *mNumObstacle = nullptr; + float *mNumGuide = nullptr; + float *mPressure = nullptr; /* Smoke grids. */ - float *mDensity; - float *mHeat; - float *mFlame; - float *mFuel; - float *mReact; - float *mColorR; - float *mColorG; - float *mColorB; - float *mShadow; - float *mDensityIn; - float *mHeatIn; - float *mFuelIn; - float *mReactIn; - float *mEmissionIn; - float *mColorRIn; - float *mColorGIn; - float *mColorBIn; - float *mDensityHigh; - float *mFlameHigh; - float *mFuelHigh; - float *mReactHigh; - float *mColorRHigh; - float *mColorGHigh; - float *mColorBHigh; - float *mTextureU; - float *mTextureV; - float *mTextureW; - float *mTextureU2; - float *mTextureV2; - float *mTextureW2; + float *mDensity = nullptr; + float *mHeat = nullptr; + float *mFlame = nullptr; + float *mFuel = nullptr; + float *mReact = nullptr; + float *mColorR = nullptr; + float *mColorG = nullptr; + float *mColorB = nullptr; + float *mShadow = nullptr; + float *mDensityIn = nullptr; + float *mHeatIn = nullptr; + float *mFuelIn = nullptr; + float *mReactIn = nullptr; + float *mEmissionIn = nullptr; + float *mColorRIn = nullptr; + float *mColorGIn = nullptr; + float *mColorBIn = nullptr; + float *mDensityHigh = nullptr; + float *mFlameHigh = nullptr; + float *mFuelHigh = nullptr; + float *mReactHigh = nullptr; + float *mColorRHigh = nullptr; + float *mColorGHigh = nullptr; + float *mColorBHigh = nullptr; + float *mTextureU = nullptr; + float *mTextureV = nullptr; + float *mTextureW = nullptr; + float *mTextureU2 = nullptr; + float *mTextureV2 = nullptr; + float *mTextureW2 = nullptr; /* Liquid grids. */ - float *mPhiIn; - float *mPhiStaticIn; - float *mPhiObsIn; - float *mPhiObsStaticIn; - float *mPhiGuideIn; - float *mPhiOutIn; - float *mPhiOutStaticIn; - float *mPhi; + float *mPhiIn = nullptr; + float *mPhiStaticIn = nullptr; + float *mPhiObsIn = nullptr; + float *mPhiObsStaticIn = nullptr; + float *mPhiGuideIn = nullptr; + float *mPhiOutIn = nullptr; + float *mPhiOutStaticIn = nullptr; + float *mPhi = nullptr; /* Mesh fields. */ vector *mMeshNodes;