Skip to content

Commit

Permalink
PhysX adapter should reject if it failed to load
Browse files Browse the repository at this point in the history
  • Loading branch information
shrinktofit committed Sep 11, 2023
1 parent d7f90a3 commit aa633eb
Showing 1 changed file with 12 additions and 15 deletions.
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,14 +57,15 @@ const USE_EXTERNAL_PHYSX = !!globalThis.PHYSX;
// 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)) {
Expand All @@ -80,29 +81,28 @@ export function InitPhysXLibs (): any {
}
}

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`
});
Expand All @@ -112,12 +112,9 @@ function initWASM (): any {
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

0 comments on commit aa633eb

Please sign in to comment.