@@ -357,7 +357,9 @@ Local<Value> NbtByteClass::pack(ByteTag* tag, bool noDelete) {
357
357
NbtByteClass* nbtObj = new NbtByteClass (std::unique_ptr<ByteTag>(tag));
358
358
nbtObj->canDelete = false ;
359
359
return nbtObj->getScriptObject ();
360
- } else return (new NbtByteClass (std::unique_ptr<ByteTag>(tag)))->getScriptObject ();
360
+ } else
361
+ return (new NbtByteClass (std::unique_ptr<ByteTag>(tag->copy ()->as_ptr <ByteTag>())))
362
+ ->getScriptObject (); // Raw pointer usually from BDS, so we have to copy it before pack it.
361
363
}
362
364
CATCH (" Fail in construct NbtByte!" );
363
365
}
@@ -427,7 +429,7 @@ Local<Value> NbtIntClass::pack(IntTag* tag, bool noDelete) {
427
429
NbtIntClass* nbtObj = new NbtIntClass (std::unique_ptr<IntTag>(tag));
428
430
nbtObj->canDelete = false ;
429
431
return nbtObj->getScriptObject ();
430
- } else return (new NbtIntClass (std::unique_ptr<IntTag>(tag)))->getScriptObject ();
432
+ } else return (new NbtIntClass (std::unique_ptr<IntTag>(tag-> copy ()-> as_ptr <IntTag>() )))->getScriptObject ();
431
433
}
432
434
CATCH (" Fail in construct NbtInt!" );
433
435
}
@@ -498,7 +500,8 @@ Local<Value> NbtShortClass::pack(ShortTag* tag, bool noDelete) {
498
500
NbtShortClass* nbtObj = new NbtShortClass (std::unique_ptr<ShortTag>(tag));
499
501
nbtObj->canDelete = false ;
500
502
return nbtObj->getScriptObject ();
501
- } else return (new NbtShortClass (std::unique_ptr<ShortTag>(tag)))->getScriptObject ();
503
+ } else
504
+ return (new NbtShortClass (std::unique_ptr<ShortTag>(tag->copy ()->as_ptr <ShortTag>())))->getScriptObject ();
502
505
}
503
506
CATCH (" Fail in construct NbtShort!" );
504
507
}
@@ -568,7 +571,7 @@ Local<Value> NbtLongClass::pack(Int64Tag* tag, bool noDelete) {
568
571
NbtLongClass* nbtObj = new NbtLongClass (std::unique_ptr<Int64Tag>(tag));
569
572
nbtObj->canDelete = false ;
570
573
return nbtObj->getScriptObject ();
571
- } else return (new NbtLongClass (std::unique_ptr<Int64Tag>(tag)))->getScriptObject ();
574
+ } else return (new NbtLongClass (std::unique_ptr<Int64Tag>(tag-> copy ()-> as_ptr <Int64Tag>() )))->getScriptObject ();
572
575
}
573
576
CATCH (" Fail in construct NbtLong!" );
574
577
}
@@ -639,7 +642,8 @@ Local<Value> NbtFloatClass::pack(FloatTag* tag, bool noDelete) {
639
642
NbtFloatClass* nbtObj = new NbtFloatClass (std::unique_ptr<FloatTag>(tag));
640
643
nbtObj->canDelete = false ;
641
644
return nbtObj->getScriptObject ();
642
- } else return (new NbtFloatClass (std::unique_ptr<FloatTag>(tag)))->getScriptObject ();
645
+ } else
646
+ return (new NbtFloatClass (std::unique_ptr<FloatTag>(tag->copy ()->as_ptr <FloatTag>())))->getScriptObject ();
643
647
}
644
648
CATCH (" Fail in construct NbtFloat!" );
645
649
}
@@ -710,7 +714,9 @@ Local<Value> NbtDoubleClass::pack(DoubleTag* tag, bool noDelete) {
710
714
NbtDoubleClass* nbtObj = new NbtDoubleClass (std::unique_ptr<DoubleTag>(tag));
711
715
nbtObj->canDelete = false ;
712
716
return nbtObj->getScriptObject ();
713
- } else return (new NbtDoubleClass (std::unique_ptr<DoubleTag>(tag)))->getScriptObject ();
717
+ } else
718
+ return (new NbtDoubleClass (std::unique_ptr<DoubleTag>(tag->copy ()->as_ptr <DoubleTag>())))
719
+ ->getScriptObject ();
714
720
}
715
721
CATCH (" Fail in construct NbtDouble!" );
716
722
}
@@ -781,7 +787,9 @@ Local<Value> NbtStringClass::pack(StringTag* tag, bool noDelete) {
781
787
NbtStringClass* nbtObj = new NbtStringClass (std::unique_ptr<StringTag>(tag));
782
788
nbtObj->canDelete = false ;
783
789
return nbtObj->getScriptObject ();
784
- } else return (new NbtStringClass (std::unique_ptr<StringTag>(tag)))->getScriptObject ();
790
+ } else
791
+ return (new NbtStringClass (std::unique_ptr<StringTag>(tag->copy ()->as_ptr <StringTag>())))
792
+ ->getScriptObject ();
785
793
}
786
794
CATCH (" Fail in construct NbtString!" );
787
795
}
@@ -859,7 +867,9 @@ Local<Value> NbtByteArrayClass::pack(ByteArrayTag* tag, bool noDelete) {
859
867
NbtByteArrayClass* nbtObj = new NbtByteArrayClass (std::unique_ptr<ByteArrayTag>(tag));
860
868
nbtObj->canDelete = false ;
861
869
return nbtObj->getScriptObject ();
862
- } else return (new NbtByteArrayClass (std::unique_ptr<ByteArrayTag>(tag)))->getScriptObject ();
870
+ } else
871
+ return (new NbtByteArrayClass (std::unique_ptr<ByteArrayTag>(tag->copy ()->as_ptr <ByteArrayTag>())))
872
+ ->getScriptObject ();
863
873
}
864
874
CATCH (" Fail in construct NbtByteArray!" );
865
875
}
@@ -989,7 +999,7 @@ Local<Value> NbtListClass::pack(ListTag* tag, bool noDelete) {
989
999
NbtListClass* nbtObj = new NbtListClass (std::unique_ptr<ListTag>(tag));
990
1000
nbtObj->canDelete = false ;
991
1001
return nbtObj->getScriptObject ();
992
- } else return (new NbtListClass (std::unique_ptr<ListTag>(tag )))->getScriptObject ();
1002
+ } else return (new NbtListClass (tag-> copyList ( )))->getScriptObject ();
993
1003
}
994
1004
CATCH (" Fail in construct NbtList!" );
995
1005
}
@@ -1499,7 +1509,7 @@ Local<Value> NbtCompoundClass::pack(CompoundTag* tag, bool noDelete) {
1499
1509
NbtCompoundClass* nbtObj = new NbtCompoundClass (std::unique_ptr<CompoundTag>(tag));
1500
1510
nbtObj->canDelete = false ;
1501
1511
return nbtObj->getScriptObject ();
1502
- } else return (new NbtCompoundClass (std::unique_ptr<CompoundTag>(tag )))->getScriptObject ();
1512
+ } else return (new NbtCompoundClass (tag-> clone ( )))->getScriptObject ();
1503
1513
}
1504
1514
CATCH (" Fail in construct NbtCompound!" );
1505
1515
}
0 commit comments