Skip to content

Chain call crash in Python-JavaScript bridge when accessing object properties. #144

@ghost

Description

Context: The bug occurs when using the Python-JavaScript bridge and the mineflayer module.
Replay conditions: The crash occurs when methods are called in a chain, e.g. playerEntity.position.offset(...).

from javascript import require, On
mineflayer = require('mineflayer')

bot = mineflayer.createBot({
  'host': 'localhost',
  'port': 30034,
  'username': 'lookAt_Bot'
})

def lookAtNearestPlayer():
    playerEntity = bot.nearestEntity()
  
    if not playerEntity: 
        return
  
    pos = playerEntity.position.offset(0, playerEntity.height, 0)
    bot.lookAt(pos)
    
@On(bot, 'chat')
def chathandle(this, username, message, *args):
    if username == "sffkjsdfsfd" and message == "asdkasdjkadjskajsdj":
        bot.chat('asjdkjasdkasjd')

@On(bot, 'physicsTick')
def handle(*args):
    lookAtNearestPlayer()

Workaround: Assigning an intermediate value to a variable before calling a method prevents a crash.

pos = playerEntity.position
pos = pos.offset(0, playerEntity.height, 0)
bot.lookAt(pos)
  • Funny enough, "@on(bot, 'chat')" also affects the bug. If you remove this event, the script will not crash.
  • The script crashes on chat messages (even though the event should not affect anything), but I don't think this applies to JSPyBridge.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions