Forge Viewer 3.2.x版本Document.load在移动设备抛异常问题咨询
Alright, let's tackle this Forge Viewer 3.2.x issue you're facing—super tricky when the docs say a parameter is required but desktop browsers let you get away with skipping it, right? Let's break down what's happening and fix that mobile error.
First, let's recap the key details:
- You're using
Autodesk.Viewing.Document.load(documentId, onSuccessCallback, onErrorCallback, accessControlProperties)where the official docs markaccessControlPropertiesas required. - Skipping this parameter works fine on Chrome/Firefox desktop, but throws a
TypeError: Cannot read property 'id' of nullin mobile browsers, specifically in thePinchRecognizerlogic. - You can't switch to
Viewer.loadDocument()because you need to load multiple models.
The error stack points directly to the viewer's gesture handler initialization on mobile—unlike desktop, mobile doesn't have a fallback for missing accessControlProperties, so the pinch recognition logic tries to read an id property from a null value.
Even without official examples for this parameter, we can construct a minimal valid object to satisfy the SDK's internal checks:
1. Quick Fix: Pass an Empty Object
Start with the simplest approach—pass an empty object as the accessControlProperties parameter. Most SDKs handle empty configurations gracefully:
Autodesk.Viewing.Document.load( documentId, onSuccessCallback, onErrorCallback, {} // Empty access control config );
2. More Robust Fix: Pass a Basic Config Object
If the empty object doesn't work, explicitly include the id field (since the error is about reading 'id' of null) using your model's documentId:
const accessControlProps = { id: documentId, // Reuse your existing document ID here permissions: [] // Empty permissions array (adjust if you need specific access rules) }; Autodesk.Viewing.Document.load( documentId, onSuccessCallback, onErrorCallback, accessControlProps );
Why This Works
The mobile gesture recognition module in Forge Viewer 3.2.x expects accessControlProperties to exist to initialize properly—desktop browsers have a hidden fallback that mobile doesn't. By passing even a minimal valid object, you prevent the SDK from trying to access properties on a null value, which resolves the pinch recognizer error.
内容的提问来源于stack exchange,提问作者Marion

