PixarAnimationStudios / OpenUSD

Universal Scene Description
http://www.openusd.org
Other
6.03k stars 1.2k forks source link

UsdImagingMeshAdapter::GetTopology crashes on some meshes with UsdGeomSubset #1748

Open eliotsmyrl opened 2 years ago

eliotsmyrl commented 2 years ago

As mentioned by @zanazakaryaie in #329 (https://github.com/PixarAnimationStudios/USD/issues/329#issuecomment-997849502) if you call UsdImagingMeshAdapter::GetTopology on meshes that use UsdGeomSubset, it crashes when attempting to convert them to HdGeomSubset. Many (but not all) of the USDZ files provided by Apple in their ARKit examples have this problem. Some of the crashing ones:

https://developer.apple.com/augmented-reality/quick-look/models/vintagerobot2k/toy_robot_vintage.usdz https://developer.apple.com/augmented-reality/quick-look/models/biplane/toy_biplane.usdz

I also hit this same problem when trying to use these examples to test my triangulation code.

jilliene commented 2 years ago

Filed as internal issue #USD-7149

tcauchois commented 2 years ago

We're closing since we haven't been able to reproduce this issue, but if you run into it again (especially after 22.08), please re-open with new repro steps!

Thanks!

johltn commented 3 months ago

Hi! I'm using 24.05 and still run into this issue.

   auto stage = pxr::UsdStage::Open("toy_drummer_idle.usdz");

   std::string meshPathString = "/toy_drummer_idle/toy_drummer_rig/toy_drummer_skinned_mesh/toy_drummer/polySurface186";
   pxr::SdfPath meshPath(meshPathString);
   pxr::UsdPrim meshPrim = stage->GetPrimAtPath(meshPath);
   std::cout << meshPrim.GetName() << std::endl;

   auto adapter = pxr::UsdImagingMeshAdapter{};
   auto topology = adapter.GetTopology(meshPrim, meshPrim.GetPrimPath(), pxr::UsdTimeCode::Default());

Output:

Exception thrown at 0x00007FFAB3E7152F (usd_sdf.dll) in ftl_usd_converter.exe: 0xC0000005: Access violation reading location 0x0000000000000EF0.
tcauchois commented 3 months ago

Hi John,

The adapters in the pxr/usdImaging/usdImaging directory are really meant to be used in conjunction with either UsdImagingDelegate or UsdImagingStageSceneIndex. The issue you're running into is that the GetTopology() call will try to update the geom subsets with a resolved material path, and references the per-stage material binding cache, which is a nullptr due to your nonstandard use of the adapter.

Can you let me know what you're trying to do with this code?

Thanks! Tom

johltn commented 3 months ago

Hi Tom, thanks for your answer.

I'm interested in the ComputeTriangleIndices and ComputeTriangulatedFaceVaryingPrimvar methods belonging to the HdMeshUtil class. Since the HdMeshUtil constructor requires a HdMeshTopology pointer, I'm using adapter.GetTopology(meshPrim, meshPrim.GetPrimPath(), pxr::UsdTimeCode::Default()); to get it and construct my HdMeshUtil object.

Would you suggest another approach?