dille12 / OVRDOZE

OVRDOZE: WIP python/pygame 2D zombie shooter
Other
5 stars 2 forks source link

fs_size and larger screens #9

Closed altruios closed 2 years ago

altruios commented 2 years ago

so here is the error I found.

Traceback (most recent call last):
  File "2dshooter/RUN.py", line 522, in <module>
    s7_2 = button7_2.tick(screen, mouse_pos, mouse_single_tick, glitch)
  File "2dshooter/RUN.py", line 236, in tick
    return self.action(self.args)
  File "2dshooter/RUN.py", line 139, in start_sp
    game.main(difficulty = arg, draw_los = draw_los, dev_tools = dev, skip_intervals = check_box_inter.__dict__["checked"], map = maps_dict[selected_map]["map"])
  File "2dshooter/game.py", line 1223, in main
    pygame.transform.scale(screen, fs_size, full_screen)
ValueError: Destination surface not the given width or height.

there's some recap: I have a 4k monitor, and I noticed this in the code.

fs_size = 1920, 1080

game would not start (I hear some music and a black screen, then it crashes)- it would give this error at start:

anim/glitch/0010.png
RESET
Traceback (most recent call last):
  File "2dshooter/RUN.py", line 658, in <module>
    pygame.transform.scale(screen, fs_size, full_screen)
ValueError: Destination surface not the given width or height.

when I changed the fs_size var to be:

fs_size = 1920*2,1080*2

which is my resolution, the loading screen starts up. everything looks fine. the latest error (the top one of this post) happens when I hit start game on single or multiplayer after I made that change.

It's also hard for me to debug - because when I run the debugger in vscode - whatever screen the terminal is displayed in is the one pygame (not the monitor pygame is in ) seems to want to measure and get the dimensions of. (so I can't seem to have vscode open on the side and pygame on the center monitor without producing a

ValueError: Destination surface not the given width or height.

at some point - because of some mismatch of measurement.

I'll try another DE and maybe it's just an I3 thing, but I think it's a 4k/1080p or a (single/dual monitor ?) thing.

altruios commented 2 years ago

found it - I think. it was in values... but it also gets set in RUN for the home screen which doesn't use those values.

going to see If I can get that more holistic.

altruios commented 2 years ago

related pull request. however I think there should be a holistic way to tell what the monitor resolution actually is from python: but I can't seem to find a good consistent (platform independent) way of doing that (without adding in something like pysimplegui, or another module).

https://github.com/dille12/2dshooter/pull/10

dille12 commented 2 years ago

I read about this issue, the pygame.FULLSCREEN needs fs_size to be exactly the dimensions of your monitor. Best way would be to use a module to detect the monitor dimensions. From what i can gather from https://stackoverflow.com/questions/3129322/how-do-i-get-monitor-resolution-in-python,

screeninfo module might work with Linux too

dille12 commented 2 years ago

I think I fixed it, try it out when you can

altruios commented 2 years ago

alas: just tried the latest pull: issue is... better: but still get this error:

anim/glitch/0010.png
Traceback (most recent call last):
  File "2dshooter/RUN.py", line 579, in <module>
    pygame.transform.scale(screen, fs_size, full_screen)
ValueError: Destination surface not the given width or height.

I say better because now there felt like there was less load time (when I had the exact right resolution - it worked great)...

printing out the vars just before the crash we get this:


screen
<Surface(854x480x32 SW)>
fs_size
(1080, 1920)
full_screen
<Surface(3840x2160x32 SW)>
Traceback (most recent call last):
  File "2dshooter/RUN.py", line 587, in <module>
    pygame.transform.scale(screen, fs_size, full_screen)
ValueError: Destination surface not the given width or height.

the surface size is the correct dimension, however the fs_size variable still seems to set itself as 1920x1080?

looking closer at it now.

altruios commented 2 years ago

ah: found the issue: it was going to the first monitor in the list of get_monitors... however it needs to go to the monitor with .is_primary property set to true. making pull request for fix.

dille12 commented 2 years ago

I thought that 1080x1920 was a weird res, is your monitor flipped?

altruios commented 2 years ago

aye: to the side for coding - it's the first one in the list - but my primary was set to the second input on my graphics card.

altruios commented 2 years ago

question: do you have two monitors - does launching vscode for you in one of the monitors and the game in the other work for you? for me it seems that the python instance needs to also be running in the same window as the game window?

dille12 commented 2 years ago

No I only have my shitty school laptop. But that's really weird, does the window always start in the same monitor you have your VSCode in?

altruios commented 2 years ago

initially -yeah: so maybe it's a timing issue in the order of things init-ing. it flashes on the monitor it python is running in, then it starts in my main window, then it crashes. if i have python in my main window - it doesn't crash.

dille12 commented 2 years ago

yeah I think it tries to start the game in whatever window the IDE is in, and the fullscreen scale cant be done in that spesific monitor so it crashes. I wonder if theres a way to start the game always in the main monitor