StanislavPetrovV / DOOM-style-Game

DOOM-style 3D (raycasting) Game in Python Pygame
MIT License
550 stars 242 forks source link

ValueError: Cannot scale to negative size #7

Open tomleary opened 1 year ago

tomleary commented 1 year ago

While trying out object_renderer.py (around the the 20:15 mark in the video), I'll encounter an error, often when I turn at the same time I'm moving. I've even copy-pasted lines from the repo into my own copy and it still gives the same error. Here's the error text:

pygame 2.1.2 (SDL 2.0.18, Python 3.10.10)
Hello from the pygame community. https://www.pygame.org/contribute.html
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: cHRM chunk does not match sRGB
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: cHRM chunk does not match sRGB
libpng warning: iCCP: known incorrect sRGB profile
Traceback (most recent call last):
  File "/Users/tom/Desktop/Python/RaycastingGame/main.py", line 53, in <module>
    game.run()
  File "/Users/tom/Desktop/Python/RaycastingGame/main.py", line 47, in run
    self.update()
  File "/Users/tom/Desktop/Python/RaycastingGame/main.py", line 27, in update
    self.raycasting.update()
  File "/Users/tom/Desktop/Python/RaycastingGame/raycasting.py", line 111, in update
    self.get_objects_to_render()
  File "/Users/tom/Desktop/Python/RaycastingGame/raycasting.py", line 21, in get_objects_to_render
    wall_column = pg.transform.scale(wall_column, (SCALE, proj_height))
ValueError: Cannot scale to negative size

I'm guessing involves some kind of math, but I wouldn't know where and how to begin to fix it. Any thoughts?

lordlogo2002 commented 1 year ago
wall_column = pg.transform.scale(wall_column, (SCALE, abs(proj_height)))

this fixed it for me. the abs fucntion turns the proj_height into a positive value