Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FrameRange : Prevent creation of FrameRanges with negative steps #1372

Merged
merged 1 commit into from
Jul 14, 2023

Conversation

ivanimanishi
Copy link
Member

Previously, you could create a FrameRange object with a negative step, but it would go into an infinite loop if you tried to get the frame list

Given that we have the ReversedFrameList that achieves the same as a negative step, it felt like using that was the correct approach.

Note that we still include the support for the negative step in the parse method, so that we can provide a more useful error message during init.

Generally describe what this PR will do, and why it is needed.

  • List specific new features and changes to project components

Related Issues

Creating a FrameRange object with a negative frame range would cause an infinite loop when trying to fetch the list of frames.

Dependencies

None.

Breaking Changes

Negative steps were already not supported, since they caused the infinite loop.

Checklist

  • I have read the contribution guidelines.
  • I have updated the documentation, if applicable.
  • I have tested my change(s) in the test suite, and added new test cases where necessary.
  • My code follows the Cortex project's prevailing coding style and conventions.

Copy link
Member

@johnhaddon johnhaddon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth adding a test to test/IECore/FrameList.py as well?

Comment on lines +61 to +64
if ( step < 0 )
{
throw Exception( "FrameRange step cannot be negative. Consider using the reverse suffix instead." );
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rejecting negative steps (rather than updating asList() to support them) is consistent with the start > end checks we're already doing, so this seems like the right fix. Looks like we also need to apply the step < 0 check in setStep() though, in which case maybe having the constructor call setStep() is simpler than duplicating the checks?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the extra check on setStep() as well.
I decided against changing the constructor to call setStep() as I thought it would also imply we should do the same for setStart() and setEnd(), but then you get into a bunch of details on whether we should pre-initialize the values before calling those methods, and things actually became quite difficult to read.
In the current PR, yes, you end up with duplicated checks, but at least it's fully consistent and readable.

Previously, you could create a FrameRange object with a negative step,
but it would go into an infinite loop if you tried to get the frame list

Given that we have the ReversedFrameList that achieves the same as a
negative step, it felt like using that was the correct approach.

Note that we still include the support for the negative step in the
parse method, so that we can provide a more useful error message during
init.
@ivanimanishi
Copy link
Member Author

Might be worth adding a test to test/IECore/FrameList.py as well?

I didn't create the tests before because there were nearly no tests (as indicated by Andrew's comment) in that FrameList.py file, and I didn't want to create all the missing tests :)

I limited myself now to add what I think is a reasonable list of tests specifically for the FrameRange, including the negative step.

Note that the set calls, like setStep(), and setStart() are not available in python, so I couldn't call them directly.

@johnhaddon johnhaddon merged commit 5fb3e51 into ImageEngine:RB-10.4 Jul 14, 2023
4 checks passed
@ivanimanishi ivanimanishi deleted the blockNegativeSteps branch July 14, 2023 19:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants