Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PhysX adapter should reject if it failed to load #16236

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 12 additions & 15 deletions cocos/physics/physx/physx-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,23 @@
// Init physx libs when engine init.
game.onPostInfrastructureInitDelegate.add(InitPhysXLibs);

export function InitPhysXLibs (): any {
export function InitPhysXLibs (): Promise<void> {
if (USE_BYTEDANCE) {
if (!EDITOR && !TEST) console.debug('[PHYSICS]:', `Use PhysX Libs in BYTEDANCE.`);
Object.assign(PX, globalThis.nativePhysX);
Object.assign(_pxtrans, new PX.Transform(_v3, _v4));
_pxtrans.setPosition = PX.Transform.prototype.setPosition.bind(_pxtrans);
_pxtrans.setQuaternion = PX.Transform.prototype.setQuaternion.bind(_pxtrans);
initConfigAndCacheObject(PX);
return Promise.resolve();
} else {
if (WASM_SUPPORT_MODE === WebAssemblySupportMode.MAYBE_SUPPORT) {

Check failure on line 70 in cocos/physics/physx/physx-adapter.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

The two values in this comparison do not have a shared enum type
if (sys.hasFeature(sys.Feature.WASM)) {
return initWASM();
} else {
return initASM();
}
} else if (WASM_SUPPORT_MODE === WebAssemblySupportMode.SUPPORT) {

Check failure on line 76 in cocos/physics/physx/physx-adapter.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

The two values in this comparison do not have a shared enum type
return initWASM();
} else {
return initASM();
Expand All @@ -80,31 +81,30 @@
}
}

function initASM (): any {
function initASM (): Promise<void> {
globalThis.PhysX = globalThis.PHYSX ? globalThis.PHYSX : asmFactory;
if (globalThis.PhysX != null) {
return globalThis.PhysX().then((Instance: any): void => {
if (!EDITOR && !TEST) console.debug('[PHYSICS]:', `${USE_EXTERNAL_PHYSX ? 'External' : 'Internal'} PhysX asm libs loaded.`);
initAdaptWrapper(Instance);
initConfigAndCacheObject(Instance);
Object.assign(PX, Instance);
}, (reason: any): void => { console.error('[PHYSICS]:', `PhysX asm load failed: ${reason}`); });
} else {
if (!EDITOR && !TEST) console.error('[PHYSICS]:', 'Failed to load PhysX js libs, package may be not found.');
return new Promise<void>((resolve, reject): void => {
resolve();
});
} else {
return Promise.reject(new Error('Unable to load PhysX asm.js.'));
}
}

function initWASM (): any {
function initWASM (): Promise<void> {
globalThis.PhysX = globalThis.PHYSX ? globalThis.PHYSX : wasmFactory;
if (globalThis.PhysX != null) {
return globalThis.PhysX({
instantiateWasm (importObject: WebAssembly.Imports,
receiveInstance: (instance: WebAssembly.Instance, module: WebAssembly.Module) => void): any {
instantiateWasm (
importObject: WebAssembly.Imports,
receiveInstance: (instance: WebAssembly.Instance, module: WebAssembly.Module) => void,
): any {
return instantiateWasm(PhysXWasmUrl, importObject).then((result: any): void => {
receiveInstance(result.instance, result.module);

Check failure on line 107 in cocos/physics/physx/physx-adapter.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `Instance`

Check failure on line 107 in cocos/physics/physx/physx-adapter.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `Module`
});
},
}).then((Instance: any): void => {
Expand All @@ -112,12 +112,9 @@
initAdaptWrapper(Instance);
initConfigAndCacheObject(Instance);
Object.assign(PX, Instance);
}, (reason: any): void => { console.error('[PHYSICS]:', `PhysX wasm load failed: ${reason}`); });
} else {
if (!EDITOR && !TEST) console.error('[PHYSICS]:', 'Failed to load PhysX wasm libs, package may be not found.');
return new Promise<void>((resolve, reject): void => {
resolve();
});
} else {
return Promise.reject(new Error('Unable to load PhysX webassembly.'));
}
}

Expand Down Expand Up @@ -260,17 +257,17 @@
const dontUpdate = physXEqualsCocosVec3(transform, wp) && physXEqualsCocosQuat(transform, wr);
if (dontUpdate) return;
if (USE_BYTEDANCE) {
node.setWorldPosition(transform.p);

Check failure on line 260 in cocos/physics/physx/physx-adapter.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `Vec3`
node.setWorldRotation(transform.q);

Check failure on line 261 in cocos/physics/physx/physx-adapter.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `Quat`
} else {
node.setWorldPosition(transform.translation);

Check failure on line 263 in cocos/physics/physx/physx-adapter.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `Vec3`
node.setWorldRotation(transform.rotation);

Check failure on line 264 in cocos/physics/physx/physx-adapter.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `Quat`
}
}

export function physXEqualsCocosVec3 (trans: any, v3: IVec3Like): boolean {
const pos = USE_BYTEDANCE ? trans.p : trans.translation;
return Vec3.equals(pos, v3, PX.EPSILON);

Check failure on line 270 in cocos/physics/physx/physx-adapter.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `IVec3Like`

Check failure on line 270 in cocos/physics/physx/physx-adapter.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `number`
}

export function physXEqualsCocosQuat (trans: any, q: IQuatLike): boolean {
Expand Down
Loading