sa2kit 1.0.7 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/mmd/index.js CHANGED
@@ -461,7 +461,18 @@ var MMDPlayerEnhanced = ({
461
461
  animationIdRef.current = requestAnimationFrame(animate);
462
462
  if (helperRef.current && isPlayingRef.current) {
463
463
  const delta = clockRef.current.getDelta();
464
- helperRef.current.update(delta);
464
+ try {
465
+ helperRef.current.update(delta);
466
+ } catch (error2) {
467
+ if (error2.message && error2.message.includes("OOM")) {
468
+ console.error("\u274C \u7269\u7406\u5F15\u64CE\u5185\u5B58\u6EA2\u51FA\uFF0C\u505C\u6B62\u64AD\u653E");
469
+ isPlayingRef.current = false;
470
+ setIsPlaying(false);
471
+ onError?.(new Error("\u7269\u7406\u5F15\u64CE\u5185\u5B58\u6EA2\u51FA"));
472
+ return;
473
+ }
474
+ throw error2;
475
+ }
465
476
  if (!hasAudioRef.current && !loop && !animationEndedFiredRef.current) {
466
477
  const currentTime = clockRef.current.getElapsedTime();
467
478
  if (animationDurationRef.current > 0) {
@@ -537,40 +548,68 @@ var MMDPlayerEnhanced = ({
537
548
  helperRef.current.enable("physics", false);
538
549
  const helperObjects = helperRef.current.objects;
539
550
  if (helperObjects && Array.isArray(helperObjects)) {
551
+ const physicsWorldsToDestroy = /* @__PURE__ */ new Set();
540
552
  helperObjects.forEach((obj) => {
541
553
  if (obj.physics) {
542
554
  try {
543
555
  const physics = obj.physics;
556
+ if (physics.world) {
557
+ physicsWorldsToDestroy.add(physics.world);
558
+ }
544
559
  if (physics.bodies && Array.isArray(physics.bodies)) {
545
560
  physics.bodies.forEach((body) => {
546
561
  if (physics.world && body) {
547
- physics.world.removeRigidBody(body);
562
+ try {
563
+ physics.world.removeRigidBody(body);
564
+ if (window.Ammo && body.destroy) {
565
+ body.destroy();
566
+ }
567
+ } catch (e) {
568
+ }
548
569
  }
549
570
  });
550
571
  physics.bodies.length = 0;
572
+ physics.bodies = null;
551
573
  }
552
574
  if (physics.constraints && Array.isArray(physics.constraints)) {
553
575
  physics.constraints.forEach((constraint) => {
554
576
  if (physics.world && constraint) {
555
- physics.world.removeConstraint(constraint);
577
+ try {
578
+ physics.world.removeConstraint(constraint);
579
+ if (window.Ammo && constraint.destroy) {
580
+ constraint.destroy();
581
+ }
582
+ } catch (e) {
583
+ }
556
584
  }
557
585
  });
558
586
  physics.constraints.length = 0;
559
- }
560
- if (physics.world) {
561
- const world = physics.world;
562
- while (world.getNumCollisionObjects() > 0) {
563
- const body = world.getCollisionObjectArray().at(0);
564
- world.removeCollisionObject(body);
565
- }
587
+ physics.constraints = null;
566
588
  }
567
589
  if (physics.reset) physics.reset();
590
+ physics.world = null;
568
591
  obj.physics = null;
569
592
  } catch (e) {
570
593
  console.warn("\u6E05\u7406\u7269\u7406\u7CFB\u7EDF\u5931\u8D25:", e);
571
594
  }
572
595
  }
573
596
  });
597
+ physicsWorldsToDestroy.forEach((world) => {
598
+ try {
599
+ while (world.getNumCollisionObjects() > 0) {
600
+ const obj = world.getCollisionObjectArray().at(0);
601
+ world.removeCollisionObject(obj);
602
+ if (obj && obj.destroy) {
603
+ obj.destroy();
604
+ }
605
+ }
606
+ if (world.destroy) {
607
+ world.destroy();
608
+ }
609
+ } catch (e) {
610
+ console.warn("\u9500\u6BC1\u7269\u7406\u4E16\u754C\u5931\u8D25:", e);
611
+ }
612
+ });
574
613
  helperObjects.length = 0;
575
614
  }
576
615
  } catch (error2) {