Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pyglet window does not open and crashes on start-up #1019

Open
Andrea-Oliveri opened this issue Dec 20, 2023 · 5 comments
Open

Pyglet window does not open and crashes on start-up #1019

Andrea-Oliveri opened this issue Dec 20, 2023 · 5 comments
Labels
bug Something isn't working not reproducible Issue not reproducible on other machines.

Comments

@Andrea-Oliveri
Copy link

Andrea-Oliveri commented Dec 20, 2023

High-level description of the bug:
Good morning,
I have developed an application with Pyglet. When I run it from the console as such: python ./app.py, most of the time it works, the window opens and responds as expected. However, 1 out of 10 times approximately, after running that command, no window opens, nothing is printed on the console, but the process ends after a couple of seconds, leaving me with this:

>>> python ./app.py
>>>

More details and the debugging I managed to do on my own follow in the "How To Reproduce" section.
I would be happy to support by providing further insights and debugging further under your guidance.
Thank you very much for your help.

System Information:
Here is the output of python -m pyglet.info:

Platform
------------------------------------------------------------------------------
platform:  Windows-11-10.0.22631-SP0
release:   11
machine:   AMD64

Python
------------------------------------------------------------------------------
implementation: CPython
sys.version: 3.12.0 | packaged by Anaconda, Inc. | (main, Oct  2 2023, 17:20:38) [MSC v.1916 64 bit (AMD64)]
sys.maxint: 9223372036854775807
os.getcwd(): C:\Users\andre\Desktop\Python Pac-Man

pyglet
------------------------------------------------------------------------------
pyglet.version: 2.0.10
pyglet.compat_platform: win32
pyglet.__file__: C:\Users\andre\miniconda3\envs\pacman\Lib\site-packages\pyglet\__init__.py
pyglet.options['audio'] = ('xaudio2', 'directsound', 'openal', 'pulse', 'silent')
pyglet.options['debug_font'] = False
pyglet.options['debug_gl'] = True
pyglet.options['debug_gl_trace'] = False
pyglet.options['debug_gl_trace_args'] = False
pyglet.options['debug_gl_shaders'] = False
pyglet.options['debug_graphics_batch'] = False
pyglet.options['debug_lib'] = False
pyglet.options['debug_media'] = False
pyglet.options['debug_texture'] = False
pyglet.options['debug_trace'] = False
pyglet.options['debug_trace_args'] = False
pyglet.options['debug_trace_depth'] = 1
pyglet.options['debug_trace_flush'] = True
pyglet.options['debug_win32'] = False
pyglet.options['debug_input'] = False
pyglet.options['debug_x11'] = False
pyglet.options['shadow_window'] = True
pyglet.options['vsync'] = None
pyglet.options['xsync'] = True
pyglet.options['xlib_fullscreen_override_redirect'] = False
pyglet.options['search_local_libs'] = True
pyglet.options['win32_gdi_font'] = False
pyglet.options['headless'] = False
pyglet.options['headless_device'] = 0
pyglet.options['win32_disable_shaping'] = False
pyglet.options['dw_legacy_naming'] = False
pyglet.options['win32_disable_xinput'] = False
pyglet.options['com_mta'] = False
pyglet.options['osx_alt_loop'] = False

pyglet.window
------------------------------------------------------------------------------
display: <pyglet.canvas.win32.Win32Display object at 0x000002D01826E9C0>
screens[0]: Win32Screen(x=0, y=0, width=1536, height=864)

How To Reproduce:

Structure of the application

APP_FOLDER
    |--- app.py
    |--- src
    |     |--- window.py
    |     |--- /* other scripts */
    |--- assets
            |--- images
            |      |--- ...
            |--- sounds
                   |--- /* currently empty*/

Content of app.py

# -*- coding: utf-8 -*-

import os
import sys

# Needed for compatibility with pyinstaller.
if getattr(sys, 'frozen', False):
    os.chdir(sys._MEIPASS)

import pyglet.app
from src.window import Window

window = Window()

pyglet.app.run()

Content of window.py

# -*- coding: utf-8 -*-

import pyglet
# /* other imports */

class Window(pyglet.window.Window):
    def __init__(self):
        super().__init__(**{'width': 250,
                            'height': 300,
                            'fullscreen': False,
                            'resizable': True,
                            'caption': "App-Name",
                            'style': Window.WINDOW_STYLE_DEFAULT,
                            'vsync': True})
        
        self.set_minimum_size(250, 300)

        icon = pyglet.image.load("./assets/images/icon.ico")
        self.set_icon(icon)
        
        # /* other stuff to initialize*/

    def on_resize(self, width, height):
        # /* implemented */
    
    def on_key_press(self, symbol, modifiers):
        # /* implemented */

    def on_draw(self):
        # /* implemented */

What I could debug:
I have made extensive use of print to trace the line where the program hangs.
The culprit is line super().__init__(**{.....}) inside of window.py. Indeed, the print function correctly printed before (inside the constructor of my Window class) but not after this line.

Finally, I have attempted to use Pyglet's runtime options to try understanding what could be happening, but I could not interpret what they provided me. I have added the following lines on top of my app.py:

for o in ('debug_gl', 'debug_gl_shaders', 'debug_gl_trace', 'debug_gl_trace_args',
          'debug_graphics_batch', 'debug_input', 'debug_lib', 'debug_media', 'debug_texture',
          'debug_trace', 'debug_trace_args', 'debug_win32'):
    pyglet.options[o] = True

Attached are two text files, one with the output for when the window runs as expected, and one for when it does not run as expected.
Run Fail.txt
Run Success.txt

Addendum:
Please note I was able to reproduce the error with a much simpler script:

import pyglet

class Window(pyglet.window.Window):
    def __init__(self):
        super().__init__(width=500, height=500)

window = Window()
pyglet.app.run()
@Andrea-Oliveri Andrea-Oliveri added the bug Something isn't working label Dec 20, 2023
@pushfoo
Copy link
Contributor

pushfoo commented Dec 20, 2023

sys.version: 3.12.0 | packaged by Anaconda, Inc. | (main, Oct  2 2023, 17:20:38) [MSC v.1916 64 bit (AMD64)]

Can you try with a different Python version such as 3.10 or 3.11? This may be a 3.12 issue (see #961).

@caffeinepills
Copy link
Collaborator

Your pyglet.info is incomplete and doesn't show the OpenGL or graphics driver, which means it's probably crashing there as well.

I would check your graphics drivers and make sure they are up to date. Also I've seen numerous tickets with issues with Anaconda environments, I would make sure to try your scripts outside that environment to ensure it's not that. Also I would try Python 3.11 to make sure it's not an issue there. It could also be a combination of all of these. Let us know.

@Andrea-Oliveri
Copy link
Author

Andrea-Oliveri commented Dec 20, 2023

I have tried in a freshly created conda environment with Python 3.10. Unfortunately, can confirm the issue appeared in this environment as well (tested both in my app and in the very simple script mentioned at the end of the previous comment).

Please find the output of python -m pyglet.info. I have made sure to obtain the full one this time, but I did observe the issue of it sometimes stopping after the screens[0] line as in the above comment.

Platform
------------------------------------------------------------------------------
platform:  Windows-10-10.0.22631-SP0
release:   10
machine:   AMD64

Python
------------------------------------------------------------------------------
implementation: CPython
sys.version: 3.10.13 | packaged by Anaconda, Inc. | (main, Sep 11 2023, 13:24:38) [MSC v.1916 64 bit (AMD64)]
sys.maxint: 9223372036854775807
os.getcwd(): C:\Users\andre\Desktop\Pyglet issue test

pyglet
------------------------------------------------------------------------------
pyglet.version: 2.0.10
pyglet.compat_platform: win32
pyglet.__file__: C:\Users\andre\miniconda3\envs\pyglet_issue\lib\site-packages\pyglet\__init__.py
pyglet.options['audio'] = ('xaudio2', 'directsound', 'openal', 'pulse', 'silent')
pyglet.options['debug_font'] = False
pyglet.options['debug_gl'] = True
pyglet.options['debug_gl_trace'] = False
pyglet.options['debug_gl_trace_args'] = False
pyglet.options['debug_gl_shaders'] = False
pyglet.options['debug_graphics_batch'] = False
pyglet.options['debug_lib'] = False
pyglet.options['debug_media'] = False
pyglet.options['debug_texture'] = False
pyglet.options['debug_trace'] = False
pyglet.options['debug_trace_args'] = False
pyglet.options['debug_trace_depth'] = 1
pyglet.options['debug_trace_flush'] = True
pyglet.options['debug_win32'] = False
pyglet.options['debug_input'] = False
pyglet.options['debug_x11'] = False
pyglet.options['shadow_window'] = True
pyglet.options['vsync'] = None
pyglet.options['xsync'] = True
pyglet.options['xlib_fullscreen_override_redirect'] = False
pyglet.options['search_local_libs'] = True
pyglet.options['win32_gdi_font'] = False
pyglet.options['headless'] = False
pyglet.options['headless_device'] = 0
pyglet.options['win32_disable_shaping'] = False
pyglet.options['dw_legacy_naming'] = False
pyglet.options['win32_disable_xinput'] = False
pyglet.options['com_mta'] = False
pyglet.options['osx_alt_loop'] = False

pyglet.window
------------------------------------------------------------------------------
display: <pyglet.canvas.win32.Win32Display object at 0x000001FE90F94E50>
screens[0]: Win32Screen(x=0, y=0, width=1536, height=864)
config['double_buffer'] = 1
config['stereo'] = 0
config['buffer_size'] = 32
config['aux_buffers'] = 4
config['sample_buffers'] = 0
config['samples'] = 0
config['red_size'] = 8
config['green_size'] = 8
config['blue_size'] = 8
config['alpha_size'] = 8
config['depth_size'] = 24
config['stencil_size'] = 8
config['accum_red_size'] = 0
config['accum_green_size'] = 0
config['accum_blue_size'] = 0
config['accum_alpha_size'] = 0
config['major_version'] = 3
config['minor_version'] = 3
config['forward_compatible'] = None
config['opengl_api'] = 'gl'
config['debug'] = None
context: Win32ARBContext(id=2192833788848, share=Win32Context(id=2192865582320, share=None))

window.context._info
------------------------------------------------------------------------------
gl_info.get_version(): (3, 3)
gl_info.get_vendor(): ATI Technologies Inc.
gl_info.get_renderer(): AMD Radeon(TM) Graphics

pyglet.gl.glx_info
------------------------------------------------------------------------------
GLX not available.

pyglet.media
------------------------------------------------------------------------------
audio driver: <pyglet.media.drivers.xaudio2.adaptation.XAudio2Driver object at 0x000001FE97EBCAC0>

pyglet.media.ffmpeg
------------------------------------------------------------------------------
FFmpeg not available.

pyglet.media.drivers.openal
------------------------------------------------------------------------------
OpenAL not available.

pyglet.input.wintab
------------------------------------------------------------------------------
WinTab not available.

At this time I am not in a situation which allows me to easily test the app outside of a conda environment. Are there any actions we can take towards understanding if that may indeed be the cause of the issue? Perhaps if I packaged the interpreter with Pyinstaller, would that be worth trying? Or perhaps some debug options?

Please also find the exact conda environment I am operating in, for future reference:

# Name                    Version                   Build  Channel
bzip2                     1.0.8                he774522_0
ca-certificates           2023.12.12           haa95532_0
libffi                    3.4.4                hd77b12b_0
openssl                   3.0.12               h2bbff1b_0
pip                       23.3.1          py310haa95532_0
pyglet                    2.0.10                   pypi_0    pypi
python                    3.10.13              he1021f5_0
setuptools                68.2.2          py310haa95532_0
sqlite                    3.41.2               h2bbff1b_0
tk                        8.6.12               h2bbff1b_0
tzdata                    2023c                h04d1e81_0
vc                        14.2                 h21ff451_1
vs2015_runtime            14.27.29016          h5e58377_2
wheel                     0.41.2          py310haa95532_0
xz                        5.4.5                h8cc25b3_0
zlib                      1.2.13               h8cc25b3_0

To my knowledge, all my drivers are up-to-date. Both Windows Update and Geforce Experience say no updates are available.

@Andrea-Oliveri
Copy link
Author

I have made another observation in my attempts debugging, which I hope will be useful to further understand how to dig deeper. I have read about the shadow_window, pretty much by accident.

I have vaguely understood what its purpose is, but not how to use it (and found no examples online, which I would therefore suggest to add to the documentation). I have however grasped that it's only useful if I had multiple windows (a.k.a. OpenGL contexts) in my app (which I don't), and that some drivers don't appreciate it.

I have therefore tried to disable it using the global runtime options: pyglet.options['shadow_window'] = False.

In both of my test apps, the following behaviours were observed:

  1. The error above does not happen anymore (can't claim this with 100% certainty, but I can say that I have tried many times re-running the apps and the issue did not happen a single time)
  2. Another issue that I thought was unrelated disappeared as well. That one is described below.

Other mysterious issue:
In a similar fashion to the original issue in the first comment, this one also does not happen all the time. Sometimes, after closing the window of my application (the only window I ever explicitly instantiated), despite the window disappearing from the screen and the taskbar, the console remains unusable for 3-4 seconds, hinting that the process is not over yet. Some other times, it just ends right away.

Please let me know if these new findings are useful and how you would like to advance in debugging this issue.
Thank you again for your support.

Andrea-Oliveri added a commit to Andrea-Oliveri/Pac-Man that referenced this issue Dec 21, 2023
@caffeinepills
Copy link
Collaborator

Unfortunately I still have yet to reproduce this.

I have cleaned up the traces to give information on which functions are being called in the latest versions, but for now I will mark this as unreproducible.

@caffeinepills caffeinepills added the not reproducible Issue not reproducible on other machines. label Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working not reproducible Issue not reproducible on other machines.
Projects
None yet
Development

No branches or pull requests

3 participants