M
Mark
Hello, I've run into a strange bug and I'm not sure how to proceed
with fixing it. Any suggestions would be most appreciated.
Here is the relevant code:
template <class T>
class Mesh3d {
public:
// constructors and data access methods (not shown)
write_to_file(string filename);
private:
T * data;
}
Inside my write_to_file() method, I am invoking a library called SILO
to write the data to a .silo file, like this:
template <class T>
void Mesh3d<T>::write_to_file(string filename)
{
DBfile * file = NULL;
file = DBCreate(filename.c_str(), DB_CLOBBER, DB_LOCAL, NULL,
DB_PDB); //!!!!
DBPutQuadmesh(file, "SPH_data", NULL, coordinates, dims, ndims,
DB_FLOAT, DB_COLLINEAR, NULL);
DBPutQuadvar1(file, "density", "SPH_data", data, dims, ndims, NULL, 0,
DB_FLOAT, DB_NODECENT, NULL);
DBClose(file);
}
Note that every function starting with "DB" is a call to the SILO
library. I've double-checked the SILO documentation and as far as I
can tell I am invoking these methods properly (I've also double-
checked that against some sample SILO code, which when on its own
compiles and runs fine).
I invoke the above code from a main() like this:
Mesh3d<float> * mesh = new Mesh3d<float>(xmin, xmax, ymin, ymax, zmin,
zmax, xdim, ydim, zdim);
string fn("mesh.silo");
mesh->write_to_file(fn);
There are no compile or runtime errors. But when I watch the contents
of the private variable "data", they mysteriously change. I've
pinpointed the line at which they change, and it is the line I have
commented above with the //!!!! (ie: it's the DBCreate line).
Strangely, the DBCreate function is passed NO information pertaining
to "data", and as far as I can tell it has no pointers to "data" or
any other way in which "data" could be in scope inside the function
DBCreate().
However, when I run this in a debugger, just before calling DBCreate I
have:
(gdb) p data[614]
$1 = 0.904355466
And immediately after the DBCreate line I have:
(gdb) p data[614]
$2 = 4.17010799e-34
I just used the index 614 as an example... some entries in the "data"
array change, and some don't. 614 happens to be one of those that
changes.
How could the data at this memory location be changing? I get no
errors, no seg faults, or anything like that. And the DBCreate()
routine should have nothing to do with the "data" array, as far as I
can tell, and yet according to the debugger it seems to be the line
that is causing the memory contents to change.
Hopefully I am just overlooking something simple, but right now I am
quite baffled by this. Any insights would be very helpful!
Thanks,
Mark
with fixing it. Any suggestions would be most appreciated.
Here is the relevant code:
template <class T>
class Mesh3d {
public:
// constructors and data access methods (not shown)
write_to_file(string filename);
private:
T * data;
}
Inside my write_to_file() method, I am invoking a library called SILO
to write the data to a .silo file, like this:
template <class T>
void Mesh3d<T>::write_to_file(string filename)
{
DBfile * file = NULL;
file = DBCreate(filename.c_str(), DB_CLOBBER, DB_LOCAL, NULL,
DB_PDB); //!!!!
DBPutQuadmesh(file, "SPH_data", NULL, coordinates, dims, ndims,
DB_FLOAT, DB_COLLINEAR, NULL);
DBPutQuadvar1(file, "density", "SPH_data", data, dims, ndims, NULL, 0,
DB_FLOAT, DB_NODECENT, NULL);
DBClose(file);
}
Note that every function starting with "DB" is a call to the SILO
library. I've double-checked the SILO documentation and as far as I
can tell I am invoking these methods properly (I've also double-
checked that against some sample SILO code, which when on its own
compiles and runs fine).
I invoke the above code from a main() like this:
Mesh3d<float> * mesh = new Mesh3d<float>(xmin, xmax, ymin, ymax, zmin,
zmax, xdim, ydim, zdim);
string fn("mesh.silo");
mesh->write_to_file(fn);
There are no compile or runtime errors. But when I watch the contents
of the private variable "data", they mysteriously change. I've
pinpointed the line at which they change, and it is the line I have
commented above with the //!!!! (ie: it's the DBCreate line).
Strangely, the DBCreate function is passed NO information pertaining
to "data", and as far as I can tell it has no pointers to "data" or
any other way in which "data" could be in scope inside the function
DBCreate().
However, when I run this in a debugger, just before calling DBCreate I
have:
(gdb) p data[614]
$1 = 0.904355466
And immediately after the DBCreate line I have:
(gdb) p data[614]
$2 = 4.17010799e-34
I just used the index 614 as an example... some entries in the "data"
array change, and some don't. 614 happens to be one of those that
changes.
How could the data at this memory location be changing? I get no
errors, no seg faults, or anything like that. And the DBCreate()
routine should have nothing to do with the "data" array, as far as I
can tell, and yet according to the debugger it seems to be the line
that is causing the memory contents to change.
Hopefully I am just overlooking something simple, but right now I am
quite baffled by this. Any insights would be very helpful!
Thanks,
Mark