[英]Why isn´t the for loop accessed in release mode, but in debug it works fine
[英]Release mode causes infinite looping in loop that works in debug mode
所以下面是一個 while 循環,它在調試模式下工作,但在發布模式下無限循環。
Ans FindMaxProj(PolyShape& S,Matrix<float,3,1>& N, Matrix<float,3,1>& cg, int StartInd){
MaxFound=false;
MaxIndInit=StartInd;
MaxValue=(cg+S.Verts.col(MaxIndInit)).transpose()*N;
while(!MaxFound){ //Infinitely loops in release mode, works in debug
MaxFound=true;
MaxInd=MaxIndInit;
for(int i=0; i<S.EdgeLinks[MaxInd].size();i++){
proj=(cg+S.Verts.col(S.EdgeLinks[MaxInd][i])).transpose()*N;
if(proj>MaxValue){
MaxFound=false; //Causes infinite looping in release mode
MaxValue=proj;
MaxIndInit=S.EdgeLinks[MaxInd][i];
}
}
MaxInd=MaxIndInit;
}
MaxCall.Value=MaxValue;
MaxCall.Ind=MaxInd;
return MaxCall;
}
我知道它無限循環,因為如果我為發布模式添加迭代上限,循環將成功結束。 S.EdgeLinks 是 int 向量的向量。 我正在使用 Eigen 進行矩陣數學運算。 另外,傳入的 S 是一個外部變量。 我還使用默認編譯器設置的 CodeBlocks。 如果我應該提供更多信息,請告訴我。
這是花車上的舍入錯誤。 我將浮點變量“proj”四舍五入到小數點后 5 位,這樣 if 檢查就不會錯誤觸發,現在它可以工作了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.