Panda3D / Ursina - Assertion Error at line 601 of nodePath.cxx

52 Views Asked by At

I'm currently making a survival game in Ursina Engine but somewhere in development I did something and now this error is spamming my console. I literally can't see anything in the console because it appears its sending this error every frame and I want to know what is causing the error. Error: Assertion failed: _error_type == ET_ok at line 601 of panda/src/pgraph/nodePath.cxx

from typing import TypedDict, Any, TypeVar
from direct.stdpy.threading import Thread
from ursina import *  # pyright: ignore[reportWildcardImportFromLibrary]
from ursina.prefabs.first_person_controller import (
    FirstPersonController,
    InputField,
    Text,
    WindowPanel,
)
from ursina.prefabs.health_bar import HealthBar
from ursina.prefabs.ursfx import ursfx
from ursina.shaders import lit_with_shadows_shader


class PlayerData(TypedDict):
    attack_damage: int
    level: int
    xp: int
    next_xp: int


SOUND_EFFECTS: dict[str, str] = {
    "cant": 'ursfx([(0.0, 1.0), (0.12, 0.5), (0.25, 0.5), (0.37, 0.5), (1.0, 0.0)], volume=1.0, wave="sine", pitch=-13, speed=2.9)',  # basically like, "hey you can't do this"
    "heal": 'ursfx([(0.0, 0.13), (0.1, 0.07), (0.25, 0.1), (0.37, 0.08), (1.0, 0.0)], volume=1.0, wave="triangle", speed=4.0)',  # every time player heals naturally
    "hurt": 'ursfx([(0.0, 1.0), (0.09, 1.0), (0.26, 1.0), (0.31, 1.0), (0.38, 1.0)], volume=0.13, wave="noise", pitch=-25, speed=3.1)',  # every time player takes damage
}
XP_INCREMENT = 12

app = Ursina()

playerController = FirstPersonController(y=2, origin_y=0.5)
healthText = Text("Health (100%)", y=-0.45, x=-0.75)
hungerText = Text("Hunger (100%)", y=-0.4, x=-0.75)
playerHealthBar = HealthBar(y=-0.45, x=-0.55)
playerHungerBar = HealthBar(bar_color=color.orange, y=-0.4, x=-0.55)
playerData: PlayerData = {
    "attack_damage": 5,
    "level": 1,
    "next_xp": 100,
    "xp": 0,
}

expectedEnemyHealthbarPosition = 0.5

T = TypeVar("T")


class Datastore:
    def __init__(self, name: str):
        self.name = name
        self.store = {}

    def set(self, key: Any, value: T | Any):
        self.store[key] = value

    def get(self, key: Any) -> T | Any:
        return self.store[key]

    def increase(self, key: Any, by: int | float, default: int | float = 0):
        if not self.store.get(key):
            self.store[key] = default
        self.store[key] += by

    def decrease(self, key: Any, by: int | float, default: int | float = 0):
        if not self.store.get(key):
            self.store[key] = default
        self.store[key] -= by


class Enemy(Entity):
    def __init__(
        self,
        name: str = "cube enemy :)",
        add_to_scene_entities=True,
        destroy_on_death: bool = True,
        assign_player: PlayerData = playerData,
        informational_messages: bool = False,
        damages_player: bool = True,
        **kwargs,
    ):
        global expectedEnemyHealthbarPosition
        super().__init__(
            add_to_scene_entities, shader=lit_with_shadows_shader, **kwargs
        )
        expectedEnemyHealthbarPosition -= 0.05
        self.health_bar = HealthBar()
        self.health_bar.text = name
        self.health_bar.y = expectedEnemyHealthbarPosition
        self.destroy_on_death = destroy_on_death
        self.player = assign_player
        self.informational_messages = informational_messages
        self.damages_player = damages_player
        self.timer = 0
        self.cooldown_timer = 0

    def on_click(self):
        """
        it isn't recommended to overwrite this function unless you know what you're doing
        """
        if self.cooldown_timer > 0:
            return
        if distance(self, playerController) > 4.89:
            if self.informational_messages:
                print("too far to hit")
            return
        eval(SOUND_EFFECTS["hurt"])
        self.cooldown_timer = 20
        self.health_bar.value -= self.player["attack_damage"]
        # print("ow")
        if self.health_bar.value < 1:
            if self.destroy_on_death:
                destroy(self)
                destroy(self.health_bar)
            self.on_death()

    def on_death(self):  # hopefully if not overwritten
        if self.informational_messages:
            print("oh no :(")

    def update(self):
        self.timer += 1
        if self.timer >= 20:
            self.timer = 0
            if self.damages_player and distance(self, playerController) < 2:
                playerHealthBar.value -= 5
        if self.cooldown_timer > 0:
            self.cooldown_timer -= 1


test_enemy = Enemy(model="cube", y=1, collider="box", x=-4)
tree = Enemy(
    model="JustATree",
    damages_player=False,
    name="Tree",
    y=1,
    collider="mesh",
    color=color.green,
    rotation_x=180,
    z=-6,
)
plane = Entity(model="plane", collider="box", texture="grass", scale=(100, 1, 100))
pivot = Entity()
DirectionalLight(
    parent=pivot, y=5, z=3, shadows=True, model="cube", rotation=(90, 0, 0)
)

ALLOW_NUMBERS = "-0123456789"
DEBUG_MENU = {
    "jetpackField": InputField("1", limit_content_to=ALLOW_NUMBERS),
    "attackField": InputField("5", limit_content_to=ALLOW_NUMBERS),
}


def _ifh1():
    if DEBUG_MENU["attackField"].text == "" or DEBUG_MENU["attackField"].text == "-":
        t = 0
    else:
        t = int(DEBUG_MENU["attackField"].text)
    playerData["attack_damage"] = t


DEBUG_MENU[
    "attackField"
].on_value_changed = _ifh1  # pyright: ignore[reportGeneralTypeIssues]

debugPanel = WindowPanel(
    "Debug Menu",
    content=[
        Text("Jetpack Strength"),
        DEBUG_MENU["jetpackField"],
        Text("Player Attack Damage"),
        DEBUG_MENU["attackField"],
    ],
    enabled=False,
)


timer = 0
isJetpackEnabled = False
jetpackDirection = False  # False = down, True = up
TICK_UPDATE_DELAY = 0.2


def updateTick():
    while True:
        healthText.text = f"Health ({round((playerHealthBar.value / playerHealthBar.max_value) * 100, 2)}%)"
        hungerText.text = f"Hunger ({round((playerHungerBar.value / playerHungerBar.max_value) * 100, 2)}%)"
        time.sleep(TICK_UPDATE_DELAY)


def update():
    global timer, isJetpackEnabled
    if timer > 0:
        timer -= 1
    elif timer == 0:
        isJetpackEnabled = False
    if isJetpackEnabled:
        if DEBUG_MENU["jetpackField"].text == "":
            DEBUG_MENU["jetpackField"].text = "0"
        match jetpackDirection:
            case False:
                playerController.y -= int(DEBUG_MENU["jetpackField"].text)
            case True:
                playerController.y += int(DEBUG_MENU["jetpackField"].text)


def input(key: str):
    global isJetpackEnabled, jetpackDirection, timer
    print(key)
    if key == "q" or key == "q hold":
        isJetpackEnabled = True
        jetpackDirection = False
        timer = 10
    if key == "e" or key == "e hold":
        isJetpackEnabled = True
        jetpackDirection = True
        timer = 10
    if key == "f4":
        playerController.enabled = not playerController.enabled
        debugPanel.enabled = not debugPanel.enabled


app.run()
tickingThread = Thread(target=updateTick)
tickingThread.start()

I tried to remove some models but that didn't do anything

0

There are 0 best solutions below