Announcements

Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.

FBX access violation on Manager->destory() because of normals

phillipmobley2
Explorer
Explorer

FBX access violation on Manager->destory() because of normals

phillipmobley2
Explorer
Explorer

Hello all, I have a similar issue to this posting here on the forum . Link here

However, instead of it being on the material, the access violation occurs when I am computing/adding in the normal. When the code is removed, I am able to compute everything and the destroy function works. I am thinking that there is issue where an index goes out of bounds.  Anyways, here is the code snippet with the bug present. Could someone take a look at what I have an see if there is any issue with what I wrote?

 

if (!normal_indexes.empty() && !p_Context.batch_mode)
			{
				// get normals
				auto normal_element = shape->CreateElementNormal();
				normal_element->SetMappingMode(FbxGeometryElement::eByPolygonVertex);
				normal_element->SetReferenceMode(FbxGeometryElement::eIndexToDirect);

				auto& direct_array = normal_element->GetDirectArray();
				// set a base normals
				std::for_each(modelIterator.getNormals().begin(), modelIterator.getNormals().end(),
					[&direct_array](const Geometry::Vector3& elem)
					{
						direct_array.Add(FbxVector4(elem.x, elem.y, elem.z));
					});


				for (auto& morph_normal : morph.get_normals())
				{
					uint32_t idx = morph_normal.first;
					auto& offset = morph_normal.second;
					auto& base = modelIterator.getNormals().at(idx);
					direct_array[idx].Set(base.x + offset.x, base.y + offset.y, base.z + offset.z);
				}

				auto& index_array = normal_element->GetIndexArray();
				std::for_each(normal_indexes.begin(), normal_indexes.end(),
					[&index_array](const uint32_t& idx) { index_array.Add(idx); });

				std::cout << "Finished" << std::endl;
			}

 

 

0 Likes
Reply
217 Views
2 Replies
Replies (2)

phillipmobley2
Explorer
Explorer

Does anyone have any thoughts?

0 Likes

ilan.keshet
Enthusiast
Enthusiast

You must be doing something specifically that is breaking memory access of the arrays -- because I also call Destroy on manager, and it throws no exceptions.   -- I am using latest FBX SDK -- which FBX SDK do you use. 

 

You should slowly comment out code, and figure out the smallest amount of code that produces the error. 

0 Likes