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

arcade.Text(...) constructor crashes #1823

Closed
VukanJ opened this issue Jun 18, 2023 · 2 comments
Closed

arcade.Text(...) constructor crashes #1823

VukanJ opened this issue Jun 18, 2023 · 2 comments

Comments

@VukanJ
Copy link

VukanJ commented Jun 18, 2023

Bug Report

Attempting to create a text object results in a crash.

System Info

ArchLinux (Linux 6.3.8-arch1-1)

Run this and paste the output here: python -m arcade
Arcade 2.6.17

vendor: NVIDIA Corporation
renderer: NVIDIA GeForce GTX 1070/PCIe/SSE2
version: (3, 3)
python: 3.10.8 | packaged by conda-forge | (main, Nov 22 2022, 08:26:04) [GCC 10.4.0]
platform: linux

Steps to reproduce

import arcade
arcade.Text("TEST", 0, 0)
### Actual behavior:
Crash. Traceback:
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
File ~/.local/mambaforge/lib/python3.10/site-packages/pyglet/text/layout.py:678, in get_default_decoration_shader()
    677 try:
--> 678     return pyglet.gl.current_context.pyglet_text_decoration_shader
    679 except AttributeError:

AttributeError: 'NoneType' object has no attribute 'pyglet_text_decoration_shader'

During handling of the above exception, another exception occurred:

AttributeError                            Traceback (most recent call last)
Cell In[2], line 1
----> 1 arcade.Text("TEST", 0, 0)

File ~/.local/mambaforge/lib/python3.10/site-packages/arcade/text_pyglet.py:214, in Text.__init__(self, text, start_x, start_y, color, font_size, width, align, font_name, bold, italic, anchor_x, anchor_y, multiline, rotation)
    211     multiline = True
    213 adjusted_font = _attempt_font_name_resolution(font_name)
--> 214 self._label = pyglet.text.Label(
    215     text=text,
    216     x=start_x,
    217     y=start_y,
    218     font_name=adjusted_font,
    219     font_size=font_size,
    220     anchor_x=anchor_x,
    221     anchor_y=anchor_y,
    222     color=get_four_byte_color(color),
    223     width=width,
    224     align=align,
    225     bold=bold,
    226     italic=italic,
    227     multiline=multiline
    228 )
    229 self.rotation = rotation

File ~/.local/mambaforge/lib/python3.10/site-packages/pyglet/text/__init__.py:474, in Label.__init__(self, text, font_name, font_size, bold, italic, stretch, color, x, y, width, height, anchor_x, anchor_y, align, multiline, dpi, batch, group, rotation)
    422 """Create a plain text label.
    423 
    424 :Parameters:
   (...)
    471 
    472 """
    473 doc = decode_text(text)
--> 474 super().__init__(doc, x, y, width, height, anchor_x, anchor_y, multiline, dpi, batch, group, rotation)
    476 self.document.set_style(0, len(self.document.text), {
    477     'font_name': font_name,
    478     'font_size': font_size,
   (...)
    483     'align': align,
    484 })

File ~/.local/mambaforge/lib/python3.10/site-packages/pyglet/text/__init__.py:274, in DocumentLabel.__init__(self, document, x, y, width, height, anchor_x, anchor_y, multiline, dpi, batch, group, rotation)
    236 def __init__(self, document=None,
    237              x=0, y=0, width=None, height=None,
    238              anchor_x='left', anchor_y='baseline',
    239              multiline=False, dpi=None, batch=None, group=None, rotation=0):
    240     """Create a label for a given document.
    241 
    242     :Parameters:
   (...)
    272 
    273     """
--> 274     super().__init__(document, width, height, multiline, dpi, batch, group)
    275     self._x = x
    276     self._y = y

File ~/.local/mambaforge/lib/python3.10/site-packages/pyglet/text/layout.py:922, in TextLayout.__init__(self, document, width, height, multiline, dpi, batch, group, wrap_lines)
    920 self._user_group = group
    921 self.group_cache = {}
--> 922 self._initialize_groups()
    924 if batch is None:
    925     batch = graphics.Batch()

File ~/.local/mambaforge/lib/python3.10/site-packages/pyglet/text/layout.py:943, in TextLayout._initialize_groups(self)
    942 def _initialize_groups(self):
--> 943     decoration_shader = get_default_decoration_shader()
    944     self.background_decoration_group = self.decoration_class(decoration_shader, order=0, parent=self._user_group)
    945     self.foreground_decoration_group = self.decoration_class(decoration_shader, order=2, parent=self._user_group)

File ~/.local/mambaforge/lib/python3.10/site-packages/pyglet/text/layout.py:681, in get_default_decoration_shader()
    678     return pyglet.gl.current_context.pyglet_text_decoration_shader
    679 except AttributeError:
    680     pyglet.gl.current_context.pyglet_text_decoration_shader = shader.ShaderProgram(
--> 681         shader.Shader(decoration_vertex_source, 'vertex'),
    682         shader.Shader(decoration_fragment_source, 'fragment'),
    683     )
    684     return pyglet.gl.current_context.pyglet_text_decoration_shader

File ~/.local/mambaforge/lib/python3.10/site-packages/pyglet/graphics/shader.py:254, in Shader.__init__(self, source_string, shader_type)
    251     raise TypeError("The `shader_type` '{}' is not yet supported".format(shader_type))
    252 self.type = shader_type
--> 254 source_string = ShaderSource(source_string, _shader_types[shader_type]).validate()
    255 shader_source_utf8 = source_string.encode("utf8")
    256 source_buffer_pointer = cast(c_char_p(shader_source_utf8), POINTER(c_char))

File ~/.local/mambaforge/lib/python3.10/site-packages/pyglet/graphics/shader.py:202, in ShaderSource.__init__(self, source, source_type)
    198     raise ValueError("Shader source is empty")
    200 self._version = self._find_glsl_version()
--> 202 if pyglet.gl.current_context.get_info().get_opengl_api() == "gles":
    203     self._lines[0] = "#version 310 es"
    204     self._lines.insert(1, "precision mediump float;")

AttributeError: 'NoneType' object has no attribute 'get_info'

Expected behavior:

No crash

@caffeinepills
Copy link

You need to create a Window or OpenGL context before you create any text.

@eschan145
Copy link
Contributor

Maybe we should put a helpful error message. The error output is confusing and not self-explanatory for beginners.

einarf added a commit that referenced this issue Jan 16, 2024
@einarf einarf closed this as completed in 01a53fb Jan 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants