Message: Double-delete with G4AssemblyVolume Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

None Double-delete with G4AssemblyVolume 

Keywords: G4AssemblyVolume double-delete
Forum: Geometry
Date: 01 Feb, 2008
From: James Odegaard <James Odegaard>


I'm having a problem deleting G4AssemblyVolume objects. I am using Geant4.9.1 and compiling on both Linux (gcc 4.1.2) and OS X (gcc 4.0.1). Below, I have included a short test-programme that highlights where the problem occurs. When it comes time to delete the G4AssemblyVolume object, I get an error message alerting me to a freeing of previously deleted memory. When debugging, it look as if the error occurs in at line 85:

   delete fPVStore[j];

Has anyone else encountered this, or could anyone point out something that I'm doing incorrectly?

 - James.

===== Source code: =====

#include <G4Box.hh>
#include <G4LogicalVolume.hh>
#include <G4VPhysicalVolume.hh>
#include <G4PVPlacement.hh>
#include <G4AssemblyVolume.hh>
#include <G4RotationMatrix.hh>

#include "GMaterials.h"

int main() {

    GMaterials mat; // A number of material definitions

    G4Box* worldBox = new G4Box( "WorldBox", 10.0*m, 10.0*m, 10.0*m );
    G4LogicalVolume* worldLog = new G4LogicalVolume( worldBox, mat.mAir, "WorldLog" );
    G4VPhysicalVolume* worldPhy = new G4PVPlacement( 0, G4ThreeVector(), "WPhys", worldLog, 0, false, 0);

    G4Box* box = new G4Box( "Box", 5.0*cm, 5.0*cm, 5.0*cm );
    G4LogicalVolume* boxLog = new G4LogicalVolume( box, mat.mPlastic, "BoxLog" );

    G4AssemblyVolume* aVol = new G4AssemblyVolume();

    G4RotationMatrix rot1;
    rot1.rotateZ( 35*degree );
    G4ThreeVector xlate1( 0.0, 1.0, 0.0 );

    aVol->AddPlacedVolume( boxLog, xlate1, &rot1 );

    G4RotationMatrix rot2;
    rot2.rotateZ( -10*degree );
    G4ThreeVector xlate2( 1.0, 0.0, 0.0 );

    aVol->MakeImprint( worldLog, xlate2, &rot2 );

    delete aVol; // This causes the error displayed below.
    delete worldPhy;

    return 0;


===== Error message (Linux): =====

*** glibc detected *** /home/james/meshCode/bin/arrayTest: double free or corruption (top): 0x08212da0 ***

Inline Depth:
 1 1
 All All
Outline Depth:
 1 1
 2 2
 All All
Add message: (add)

1 None: Re: Double-delete with G4AssemblyVolume   (Ivana Hrivnacova - 04 Feb, 2008)
 Add Message Add Message
to: "Double-delete with G4AssemblyVolume"

 Subscribe Subscribe

This site runs SLAC HyperNews version 1.11-slac-98, derived from the original HyperNews

[ Geant 4 Home | Geant 4 HyperNews | Search | Request New Forum | Feedback ]