Hi! I’m having problems with my simple COLLADA DOM based model loader.
Here’s my code. I verified that it loads and parses the file without error messages, and it prints out the correct number of meshes.
Beyond that point I have however been unable to make it work. When I added the two lines below the comment “THESE TWO LINES CAUSE SEGMENTATION FAULT” below, the app crashed on the line “delete collada_dom;”, after working properly before they were added.
How can I fix this? Did I screw up something with the reference counts when I called “thisMesh->getSource_array()”? I tried to acquire the source array in order to get the info stored within the tags <source> inside the <mesh> tag in the document I was parsing (a model exported from Blender). Is there another way of getting the info within <source> </source> within <mesh> </mesh>?
//////////////////////////////////////
//LOAD FILE
DAE *collada_dom = NULL;
collada_dom = new DAE();
char *file_ptr;
file_ptr = textFileRead("test1.dae");
daeInt result = collada_dom->load("TEST1.dae", file_ptr);
if(result != DAE_OK) {
std::cout << result << std::endl;
return 0;
}
delete file_ptr; //release temp memory allocated by textFileRead
//////////////////////////////////////
//READ FILE CONTENTS
daeUInt meshCount = collada_dom->getDatabase()->getElementCount(NULL, COLLADA_TYPE_MESH, NULL);
std::cout << "Num meshes: " << meshCount << std::endl;
//////////////////////////////////////
//GET THE FIRST MESH
domMesh *thisMesh;
daeInt el_number = 0;
daeInt error = collada_dom->getDatabase()->getElement((daeElement**)&thisMesh, el_number, NULL, COLLADA_TYPE_MESH, NULL);
if(error!=DAE_OK) {
std::cout << "error getting mesh" << std::endl;
return 0;
}
//////////////////////////////////////
//READ CONTENTS OF THE MESH
//THESE TWO LINES CAUSE SEGMENTATION FAULT:
domSource_Array sourceArr = thisMesh->getSource_array();
std::cout << "Num sources: " << sourceArr.getCount();
//cleanup
collada_dom->unload("TEST1.dae");
delete collada_dom;