Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
RemoveConstraint error
#2
Hi!

There's a coupe problems with this code. First, you're mixing up actor batches and solver batches. You are iterating trough actor batches, but removing constraints from the solver batch. Not sure this is what you want to do. Since the amount of constraints in the actor doesn't change at all as you remove constraints from the solver, you will end up trying to remove a constraint that doesn't exist. Your code is equivalent to this:

Quote:for i = 0 to 5,
remove constraint (i);

You can clearly see the problem here: when you remove constraint 0, there's only 4 constraints left. Then you remove constraint 1, and there's 3 left. Then you remove constraint 2, there's 2 left. Then you try to remove constraint 3 (and later, 4 and 5) but there's only 2 left, so ArgumentOutOfRangeException.

The manual explains the difference between both types of batches and how to deal with them. See "Per-constraint parameters" in this page:
http://obi.virtualmethodstudio.com/manua...aints.html

Second issue is that you're removing constraints as you're iterating trough them. This will skip one constraint every time you remove any. As a rule of thumb in programming: never, ever remove stuff from a list or array while you're iterating trough it from start to end. Either store the indices of the stuff you need removed and then remove them later, or iterate backwards. See: https://www.techiedelight.com/remove-ele...ng-csharp/

kind regards,
Reply


Messages In This Thread
RemoveConstraint error - by Seahorse - 10-01-2023, 09:49 AM
RE: RemoveConstraint error - by josemendez - 10-01-2023, 10:26 AM
RE: RemoveConstraint error - by Seahorse - 10-01-2023, 11:53 AM
RE: RemoveConstraint error - by josemendez - 10-01-2023, 12:00 PM
RE: RemoveConstraint error - by Seahorse - 10-01-2023, 12:48 PM
RE: RemoveConstraint error - by josemendez - 10-01-2023, 02:05 PM
RE: RemoveConstraint error - by Seahorse - 10-01-2023, 02:24 PM