Are both Region and logicVacuum data members of your class? Are you sure that they are both set to non-null values when this function is called (i.e., after you’ve built your geometry)?
My program is compiling normally, after a while I managed to make it work by copying the same geometry from example B5, that uses G4Tubs, and creating my own MagneticField class. However, I am still having difficulties in realizing why in my program the magnetic field only works along with this specific geometry and how do I adapt to make it work with other types of geometry that I wish to choose.
As Michael wrote in the code segment which you showed it was not clear whether ‘Region’ and ‘logicVacuum’ were valid pointers: that they are NOT null, and that they point to valid objects of each type.
So, to check this, you can add a couple of lines to your program, such as
G4cout << " Value of Region= " << Region << G4endl;
G4cout << " and its name is " << Region->GetName() << G4endl;
G4cout << " Value of logicVacuum= " << logicVacuum << G4endl;
G4cout << " and its name is " << logicVacuum->GetName() << G4endl;
This will likely help you to identify whether one of these variables does not hold the value which you expect, and to correct it.