Ruby Operation left Open
-
I've had this bug in my plugin for a while. My code is:
# Get handles to our model and the Entities collection it contains. @model1 = Sketchup.active_model entities = @model1.entities if @Trusstype == "King Post" @Model_operation = 'Draw King Post Truss' draw_status = @model1.start_operation(@Model_operation) .... lots of code here .... end .... more code here .... draw_status = @model1.commit_operation
Everything looks good but I keep getting this error:
warning; Ruby operation left open; "Draw King Post Truss"
-
It's always best to add a second argument
, true
to the.start_operation
.
Also ensure there's nothing in your code that skips out before you get to do the.commit_operation
at the end.If you do have some methods with code that might bale-out ensure that any '
rescue
' also includes the.commit_operation
and areturn
, alternatively use.abort_operation
and areturn
so nothing is done at all... -
I think this may be the hint that I need. For some reason it never occurred to me that the program might be somehow terminating before it got to the final commit command, duh. Looking at it again now.
-
Also remember that your code as we can see it ALWAYS does a commit - even if there was never an operation started.
But since we only see some of your code it's unclear if there's always an operation to be committed !
One way round that is initially to set**@**draw_status = false
, then within the 'tests' use**@**draw_status = @model1.start_operation(@Model_operation, true)
e.g. inif @Trusstype...
Always remembering to set in each 'test':and then in your unshown code, for each commit you need to use:
draw_status = @model1.commit_operation if **@**draw_status
So you don't commit anything unless an operation is been started...
Advertisement