|
In my application, I have volumes that I allow my users to turn on and off at run time through the Messenger framework. Works fine.
For some of those volumes, there are additional commands that should be present in the command hierarchy when the volume is enabled, and which I want to remove if the volume is disabled. So in one of my messengers, I have items like the following:
void octupoleMessenger::enable_field_messenger() {
if( ofmess_ == 0 )
ofmess_ = new octupoleFieldMessenger(this);
}
void octupoleMessenger::disable_field_messenger() {
if( ofmess_ != 0 ){
// FIXME ... this deletes the entire g2MIGTRACE hierarchy!
delete ofmess_;
ofmess_ = 0;
}
}
The enable_field_messenger call works just fine ... the whole sub-hierarchy appears as expected, and all the commands in it work fine.
The problem is the disable_field_messenger() call. For testing purposes, the destructor of ofmess_ is
octupoleFieldMessenger::~octupoleFieldMessenger(){
delete ofDirectory_;
}
now, the constructor sets up ofDirectory_ as
ofDirectory_ = new G4UIdirectory( "/g2MIGTRACE/octupole_coil/field/" );
When the destructor is called, the directory "/g2MIGTRACE" (and all its subdirectories and commands, of course) disappears entirely!
I'm using 4.9.2.p02, but I tried this back in the 4.8 days with the same results. Incidentally, this doesn't seem to be restricted to G4UIdirectory, but to the deletion of ANY G4UIcommand.
Am I doing something wrong, or is this a bug in the library?
|