Archived issue #0026832
TFunction_Iterator won't work if ExecutionStatus is Standard_False.
Description
There are several functions created, but the loop of below will never be entered. "iterator.More()" always returns false.
for(TFunction_Iterator iterator(aLabel); iterator.More(); iterator.Next())
{
// This loop never entered
}
if change the usage as below, it will work:
TFunction_Iterator iterator;
iterator.SetUsageOfExecutionStatus(Standard_True);
for(iterator.Init(aLabel); iterator.More(); iterator.Next())
{
// Works well
}
for(TFunction_Iterator iterator(aLabel); iterator.More(); iterator.Next())
{
// This loop never entered
}
if change the usage as below, it will work:
TFunction_Iterator iterator;
iterator.SetUsageOfExecutionStatus(Standard_True);
for(iterator.Init(aLabel); iterator.More(); iterator.Next())
{
// Works well
}
Steps to reproduce
Dear Szy, could you please review the modification: CR26832.
Public activity
18 archived notes
Participants are labeled by their role within this record.
The simplest way to reproduce this bug is to create just one function and iterate the function with TFunction_Iterator.
Could you check it.
It seems it is not truth... the method More() of the function iterator returns true while the graph of functions is not iterated completely. If the execution status is used, it takes into account the status of the function and iterates only through not executed yet functions. Otherwise, it iterates the whole graph of functions.
You may look at a sample here : #0024665 Insert your iteration code at the end of createDefaultModel1() or createDefaultModel2() methods of MainWindow.cpp and check how it behaves. Any questions are welcome!
You may look at a sample here : #0024665 Insert your iteration code at the end of createDefaultModel1() or createDefaultModel2() methods of MainWindow.cpp and check how it behaves. Any questions are welcome!
Dear vro,
The sample is different about the iterator usage. The bug just occurs in for loop form, it works well if using like below, i'm sure it will be reproducible use in for loop.
while (!fIterator.Current().IsEmpty())
{
const TDF_LabelList& funcs = fIterator.Current();
if (funcs.Extent() > nbx)
nbx = funcs.Extent();
nby++;
fIterator.Next();
}
The sample is different about the iterator usage. The bug just occurs in for loop form, it works well if using like below, i'm sure it will be reproducible use in for loop.
while (!fIterator.Current().IsEmpty())
{
const TDF_LabelList& funcs = fIterator.Current();
if (funcs.Extent() > nbx)
nbx = funcs.Extent();
nby++;
fIterator.Next();
}
for(TFunction_Iterator iterator(aLabel); iterator.More(); iterator.Next())
{
// This loop never entered
}
{
// This loop never entered
}
So, if there is no bugs, we may close the issue, I suppose. Any proposals for improvement of the code are welcome!
Dear vro,
Below for look desn't work as my previous stated. This does not align with OCCT methodnology. OCCT iterator might work in style as below:
for(TFunction_Iterator iterator(aLabel); iterator.More(); iterator.Next())
{
// This loop never entered
}
Actually, there is a bug, but the sample escape it. For a normal user, there should be no way to make it work.
Below for look desn't work as my previous stated. This does not align with OCCT methodnology. OCCT iterator might work in style as below:
for(TFunction_Iterator iterator(aLabel); iterator.More(); iterator.Next())
{
// This loop never entered
}
Actually, there is a bug, but the sample escape it. For a normal user, there should be no way to make it work.
I propose to implement the TFunction_Iterator::More() by just returning {!fIterator.Current().IsEmpty()} if it doesn't consider the executing status.
If you add your code-snippet to the sample application and run it in debug mode, you would see that the iterator perfectly works in spite of the execution status.
I don't see any reason to change the method More() of the iterator. It works as expected. And it works fine. Did you check it in the sample application?
I don't see any reason to change the method More() of the iterator. It works as expected. And it works fine. Did you check it in the sample application?
Dear vro,
please check your implementation as below, if there is just one function, the last line "myPassedFunctions.Extent() < myScope->GetFunctions().Extent();" should never be true, becasue there are equal.
Standard_Boolean TFunction_Iterator::More() const
{
if (myUsageOfExecutionStatus)
{
TFunction_DoubleMapIteratorOfDoubleMapOfIntegerLabel itrm(myScope->GetFunctions());
for (; itrm.More(); itrm.Next())
{
const TDF_Label& L = itrm.Key2();
if (GetStatus(L) == TFunction_ES_NotExecuted)
return Standard_True;
}
return Standard_False;
}
return myPassedFunctions.Extent() < myScope->GetFunctions().Extent();
}
please check your implementation as below, if there is just one function, the last line "myPassedFunctions.Extent() < myScope->GetFunctions().Extent();" should never be true, becasue there are equal.
Standard_Boolean TFunction_Iterator::More() const
{
if (myUsageOfExecutionStatus)
{
TFunction_DoubleMapIteratorOfDoubleMapOfIntegerLabel itrm(myScope->GetFunctions());
for (; itrm.More(); itrm.Next())
{
const TDF_Label& L = itrm.Key2();
if (GetStatus(L) == TFunction_ES_NotExecuted)
return Standard_True;
}
return Standard_False;
}
return myPassedFunctions.Extent() < myScope->GetFunctions().Extent();
}
Hello Vico! Many thanks! Now I see the bug. Indeed, for the case of one function the iterator doesn't return it. I will fix it, thanks again!
Branch [archived branch] has been created by Commenter 2.
[revision removed]
Detailed log of new commits:
Author: Commenter 2
Date: Fri Feb 19 12:21:43 2016 +0300
0026832: TFunction_Iterator won't work if ExecutionStatus is Standard_False.
The method TFunction_Iterator::More() is corrected().
[revision removed]
Detailed log of new commits:
Author: Commenter 2
Date: Fri Feb 19 12:21:43 2016 +0300
0026832: TFunction_Iterator won't work if ExecutionStatus is Standard_False.
The method TFunction_Iterator::More() is corrected().
There is no test-case or a draw-command. Testing is possible only through a new FuncDemo application.
Reviewed.
Branch [archived branch] has been updated forcibly by Participant.
[revision removed]
[revision removed]
Branch [archived branch] has been rebased on the current master
Dear Commenter 1,
Branch CR26832 from occt git-repository (and master from products git-repository) was compiled on Linux, MacOS and Windows platforms and tested.
[revision removed]
Number of compiler warnings:
occt component:
Linux: 0 (0 on master)
Windows: 0 (0 on master)
MacOS: 0 (0 on master)
products component:
Linux: 68
Windows: 0
MacOS: 1133
Regressions/Differences:
Not detected
Testing cases:
Not needed
Testing on Linux:
Total MEMORY difference: 89390901 / 90308255 [-1.02%]
Total CPU difference: 19330.12000000004 / 19527.04000000009 [-1.01%]
Testing on Windows:
Total MEMORY difference: 57456303 / 57486237 [-0.05%]
Total CPU difference: 17932.82975329875 / 17687.752182298846 [+1.39%]
Branch CR26832 from occt git-repository (and master from products git-repository) was compiled on Linux, MacOS and Windows platforms and tested.
[revision removed]
Number of compiler warnings:
occt component:
Linux: 0 (0 on master)
Windows: 0 (0 on master)
MacOS: 0 (0 on master)
products component:
Linux: 68
Windows: 0
MacOS: 1133
Regressions/Differences:
Not detected
Testing cases:
Not needed
Testing on Linux:
Total MEMORY difference: 89390901 / 90308255 [-1.02%]
Total CPU difference: 19330.12000000004 / 19527.04000000009 [-1.01%]
Testing on Windows:
Total MEMORY difference: 57456303 / 57486237 [-0.05%]
Total CPU difference: 17932.82975329875 / 17687.752182298846 [+1.39%]
Branch [archived branch] has been deleted by Participant.
[revision removed]
[revision removed]