Pocketmine-mp: Regarding #962

Created on 2 Jun 2017  路  8Comments  路  Source: pmmp/PocketMine-MP

Issue description



I get the following error during startup in my plugin. I believe this has something to do with #962

[12:07:30] [Server thread/CRITICAL]: TypeError: "Argument 1 passed to
pocketmine\utils\Binary::writeByte() must be of the type integer, null given, called in
/root/pmmp/src/pocketmine/nbt/NBT.php on line 279" (EXCEPTION) in "/src/pocketmine/utils/Binary"
at line 133

Steps to reproduce the issue


Using the code below.

OS and versions

  • PocketMine-MP: 087a994
  • PHP: 7.0.18
  • Server OS: Ubuntu 14.04 LTS 64-bit
  • Game version: Win10

Crashdump, backtrace or other files

    public function serializeGUI(){
        $gpane = Item::get(Item::GLASS_PANE, 0, 1);
        $nbt = new CompoundTag("", []);
        $nbt->CosmicAction = new IntTag("CosmicAction", CosmicAction::DUEL_SETTINGS);
        $nbt->duelsettings = new IntArrayTag('duelsettings', []);
        $nbt->locked = new ByteTag('locked', 1);
        $gpane->setNamedTag($nbt);
        $gpane->setCustomName(" ");

        $s_gapple = Item::get(466, 0, 1);
        $nbt = new CompoundTag("", []);
        $nbt->CosmicAction = new IntTag("CosmicAction", CosmicAction::DUEL_SETTINGS);
        $nbt->duelsettings = new IntArrayTag('duelsettings', [0, 1]);
        $nbt->ench = new ListTag('ench', []);
        $nbt->locked = new ByteTag('locked', 1);
        $s_gapple->setNamedTag($nbt); <--- Line 182
        $nbt = $s_gapple->getNamedTag();
        $s_gapple->setCustomName($this->itemRefresh($nbt->duelsettings->getValue()));
    }

    private function itemRefresh(array $duelsettings) : string{
        return self::DUELSETTINGS_LEVEL_NAME[$duelsettings[0] !== 0 ? $duelsettings[0] : $duelsettings[1]] ?? "";
    }
Core Fixed

Most helpful comment

Never mind... I forgot passing null to a type-hinted function raises a type error regardless of whether strict types are enabled or not. The commit causing this issue is https://github.com/pmmp/PocketMine-MP/commit/e4e4ef5f2a5b50ad9dc546b08a1f812da43ca0ef due to a type-hint added to Binary::writeByte()

All 8 comments

NICE. So it does a bad job of detecting the type of empty TAG_Lists then. Well done shoghi 馃憦

Could you test the referenced commit please?

okay, np

I confess I'm confused how you encountered this issue though... strict types are not currently enabled on any of the NBT components.

Never mind... I forgot passing null to a type-hinted function raises a type error regardless of whether strict types are enabled or not. The commit causing this issue is https://github.com/pmmp/PocketMine-MP/commit/e4e4ef5f2a5b50ad9dc546b08a1f812da43ca0ef due to a type-hint added to Binary::writeByte()

Tested, the commit fixed it!

Also, @Muqsit ,
$gpane = Item::get(Item::GLASS_PANE, 0,
is unneeded, due to meta and amount already being initialized with 0 and 1

@thebigsmileXD yeah I'm aware of that. It was originally written when I used to use a spoon, and since then I got the habit of writing the 2nd and 3rd parameters even though they have the default value. :P

Was this page helpful?
0 / 5 - 0 ratings

Related issues

admsteck picture admsteck  路  22Comments

Muqsit picture Muqsit  路  23Comments

Frago9876543210 picture Frago9876543210  路  50Comments

markkrueg picture markkrueg  路  18Comments

MisteFr picture MisteFr  路  19Comments