Question

I'm now studying vcglib (http://vcg.sf.net)

My problem is that the following code crashes VS 2013 when I try to inspect variables in 'Locals' or 'Auto' windows.

std::vector<cl_float4> cloud;
std::vector<cl_uchar4> colors;
std::vector<cl_int> valid;

fetchCloud(cloud);
fetchColors(cloud, colors, valid);


class CFace;
class CVertex;
struct MyUsedTypes : public vcg::UsedTypes< 
    vcg::Use<CVertex>       ::AsVertexType,
    vcg::Use<CFace>         ::AsFaceType> {};

/// compositing wanted proprieties
class CVertex : public vcg::Vertex< MyUsedTypes, vcg::vertex::Coord3f, vcg::vertex::Normal3f, vcg::vertex::Color4b, vcg::vertex::BitFlags> {};
class CFace : public vcg::Face< MyUsedTypes, vcg::face::VertexRef, vcg::face::Normal3f, vcg::face::BitFlags > {};
class CMesh : public vcg::tri::TriMesh< std::vector<CFace>, std::vector<CVertex> > {};

CMesh m;
for (size_t k = 0; k < cloud.size(); ++k) {
    if (valid[k]) {
        vcg::tri::Allocator<CMesh>::AddVertex(m,
                                              CMesh::CoordType(cloud[k].s[0], cloud[k].s[1], cloud[k].s[2]), 
                                              vcg::Color4b(colors[k].s[0], colors[k].s[1], colors[k].s[2], 255)
                                              );
    }
}

cout << "saving to file...";
vcg::tri::io::PlyInfo info;
info.mask |= vcg::tri::io::Mask::IOM_VERTCOLOR;
vcg::tri::io::ExporterPLY<CMesh>::Save(m, (base_name + ".ply").c_str(), false, info);
cout << "saved" << endl;

cloud in the above has from 50000 to 100000 elements. This point cloud is calculated in the GPU memory using OpenCL. Functions fetchCloud and fetchColors download respective data to the host memory.

I've copied the code above from the trimesh_ant_freeglut sample, supplied with the vcglib.

I've also successfully compiled and run this sample in VS2013. It runs fine, and I can pause it in the debugger at any moment and inspect all variables of interest.

I've also added a code to the sample, generating a cloud of 1000000 random points. VS2013 displays mesh variable, when I pause the running sample in the debugger and inspect variables.

Both my source code and the sample code included in the same solution as different projects. The solution is generated using CMake. The main difference between the projects is that one uses OpenCL.

How could I debug this issue? I'm ready to supply additional information, which could be required. I simply don't know currently what I should supply.

Update: tried disabling all extensions - still no luck.

Update2: asked a colleague to compile, run and debug my code - his Visual Studio installation also crashes.

Update3: Downloaded Visual Studio Update RC2 - again, crashes

Update4: Tried moving the code, related to class CMesh in the source file. Result is unstable. Visual Studio crashes sometimes, and sometimes doesn't. No crashes if the code is right after the opening bracket of main. If some instructions appear between this code and int main(int argc, char **argv) {, crashes can happen.

Am I right in thinking that this code corrupts stack somewhere?

Was it helpful?

Solution

Solved! By moving class declarations outside of main():

That is

class CFace;
class CVertex;
struct MyUsedTypes : public vcg::UsedTypes <
                           vcg::Use<CVertex>       ::AsVertexType,
                           vcg::Use<CFace>         ::AsFaceType > {};

/// compositing wanted proprieties
class CVertex : public vcg::Vertex < MyUsedTypes, vcg::vertex::Coord3f, vcg::vertex::Normal3f,     vcg::vertex::Color4b, vcg::vertex::BitFlags > {};
class CFace : public vcg::Face < MyUsedTypes, vcg::face::VertexRef, vcg::face::Normal3f, vcg::face::BitFlags > {};
class CMesh : public vcg::tri::TriMesh < std::vector<CFace>, std::vector<CVertex> > {};

int main (int argc, char* argv[])
{
    // blah-blah-blah
    CMesh m;

    //  fill m
}

Now no crashes!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top