Community
FBX Forum
Welcome to Autodesk’s FBX Forums. Share your knowledge, ask questions, and explore popular FBX topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Access Violation on Manager->Destroy() becuase I get material index array

2 REPLIES 2
Reply
Message 1 of 3
Anonymous
659 Views, 2 Replies

Access Violation on Manager->Destroy() becuase I get material index array

So a the end of my program, I call Manager->Destroy() for cleanup. This code works fine and gives me no problems until I added new code to get the index array of associated with material mapping. 

 

This is the line where I get the element material to eventually get the index array. As far as I can tell, this is not the problem line 

 FbxGeometryElementMaterial* geoElement = mesh->GetElementMaterial(); 

After getting geoElement, I check the mapping mode. Again, this is not the problem code, so I'm not going to include. 

After getting the mapping mode, I get the index array from geo element for information about how the variety of materials is mapped to the mesh with the following code. This is the problematic code, as including this code is what causes my program to get an access violation on cleanup. If i comment out this code, there is no access violation

  FbxLayerElementArray indArray = geoElement->GetIndexArray();
  int mapIndex;
  for (int i = 0; i < indArray.GetCount(); ++i)
  {
    indArray.GetAt(i, &mapIndex);
    std::cout << "Map " << i << ": " << mapIndex << std::endl;
  }

 

In case it helps, the error occurs on :

manager->Destroy();

And the specific error message is: 

Unhandled exception at 0x018BA7D1 in FbxConverter.exe: 0xC0000005: Access violation reading location 0xFEEEFEF6.

 

 

Any help with this issue would be appreciated. 

 

2 REPLIES 2
Message 2 of 3
vincent.haubruge
in reply to: Anonymous

Hi,

 

Could you specify your FBX SDK version?

 

Thank you,

 

Vincent



Vincent Haubruge
Message 3 of 3
regalir
in reply to: vincent.haubruge

Hi c.lavelle,

 

the problem is in the statement:

FbxLayerElementArray indArray = geoElement->GetIndexArray();

indArray is a local variable that will be destroyed when it goes out of scope. However, the FbxLayerElementArray objects have an internal pointer to their implementation data and although the = operator above will effectively create a new object, both indArray and the index array in the geoElement will share the same implementation so when indArray goes out of scope, the data in the geoElement becomes invalid as well.

 

I suggest you just declare indArray as a reference

FbxLayerElementArray& indArray = geoElement->GetIndexArray();

(this is what the GetIndexArray() returns anyway ;-)) or, if you really want a copy of the indices, then loop through each element and copy them to a completely new instance of an FbxLayerElementArray<int>

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report