Problem 1087

Summary: G4UIcommandTree::RemoveCommand() incorrectly deletes directories
Product: Geant4 Reporter: Kevin Lynch <krlynch>
Component: intercomsAssignee: Koichi Murakami <Koichi.Murakami>
Status: CLOSED FIXED    
Severity: normal    
Priority: P5    
Version: 9.2   
Hardware: All   
OS: All   
URL: http://hypernews.slac.stanford.edu/HyperNews/geant4/get/userinterface/66.html
Attachments: diff -u patch against intercoms/src/G4UIcommandTree.cc

Description Kevin Lynch 2009-10-30 03:16:04 CET
Created attachment 54 [details]
diff -u patch against intercoms/src/G4UIcommandTree.cc

G4UIcommandTree::RemoveCommand() incorrectly deletes "empty" directories because of an incorrect definition of "empty".  The definition used in the distribution is "directory contains no commands"; the definition should also require "directory contains no sub-directories".  

Consider the following simple directory structure

/a/b/c/D
/a/b/e/F

For clarity, lowercase letters denote directories, and capitalized letters denote "true" commands.  In the 9.2.p02 distribution, if you delete the G4UIcommand associated with "D", G4UIcommandTree::RemoveCommand() will first delete "D"

/a/b/c/
/a/b/e/F

"c" is now empty, so lines 135-153 will remove it from the commandTree

/a/b/
/a/b/e/F

and next check "b".  "b" still has "e" as a member, but "e" is not counted, as the test is only for "commands" not "trees", so /a/b/ is considered empty and removed, leaving

/a/

which is clearly empty.  Deleting "D" has immolated the entire hierarchy!

Removal of hierarchies at run time is a useful behavior, so this bug, while pretty trivial, is really annoying.  I have a number of volumes that can be added by the user through a G4UIcommand at runtime.  These volumes have additional commands associated with them that I don't want to appear unless the volumes exist; similarly, I want the commands to go away if the volumes are removed.

The attached patch corrects this problem without changing the interface; see also the referenced hypernews postings.
Comment 1 Koichi Murakami 2009-11-06 07:19:32 CET
Thanks for your kind report.

It will be fixed in the 9.3 release as you suggested.