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

Segmentation fault in opengl_utils.pyx #8406

Closed
SanAndreyas opened this issue Oct 14, 2023 · 5 comments
Closed

Segmentation fault in opengl_utils.pyx #8406

SanAndreyas opened this issue Oct 14, 2023 · 5 comments
Labels
Status: Needs-analysis Issue needs to be analyzed if it's real Type: Bug A bug or something not working as intended

Comments

@SanAndreyas
Copy link
Contributor

Software Versions

  • Python: 3.11
  • OS: Debian
  • Kivy: 2.2.1
  • Kivy installation method: pip

Describe the bug
Program received signal SIGSEGV, Segmentation fault.

import io
from kivy.core.image import Image as CoreImage
data = io.BytesIO(open("image.png", "rb").read())
texture = CoreImage(data, ext="png", filename="image.png").texture

Crashes !ONLY! when accessing ".texture".

Crash DUMP:
#0 0x0000000000000000 in ?? ()
#1 0x00007ffff5ce317a in __pyx_f_4kivy_8graphics_12opengl_utils_gl_get_extensions (__pyx_skip_dispatch=__pyx_skip_dispatch@entry=0) at /project/kivy/graphics/opengl_utils.c:3090
#2 0x00007ffff5ce47e4 in __pyx_f_4kivy_8graphics_12opengl_utils_gl_has_extension (__pyx_v_name=0x7ffff6857f00, __pyx_skip_dispatch=__pyx_skip_dispatch@entry=0) at /project/kivy/graphics/opengl_utils.c:3441
#3 0x00007ffff5ce8008 in __pyx_f_4kivy_8graphics_12opengl_utils_gl_has_capability (__pyx_v_cap=2, __pyx_skip_dispatch=) at /project/kivy/graphics/opengl_utils.c:3945
#4 0x00007ffff5e61db4 in __pyx_pf_4kivy_8graphics_7texture_2texture_create_from_data (__pyx_self=, __pyx_v_mipmap=, __pyx_v_im=) at /project/kivy/graphics/texture.c:10360
#5 __pyx_pw_4kivy_8graphics_7texture_3texture_create_from_data (__pyx_self=, __pyx_args=, __pyx_kwds=) at /project/kivy/graphics/texture.c:10245
#6 0x0000555555758c47 in cfunction_call (func=0x7ffff6821710, args=, kwargs=) at Objects/methodobject.c:542

The issue tracker is a tool to address bugs only (search known bugs: https://git.io/vM1iE).
Please use the #support Discord channel at https://chat.kivy.org/ or Stack Overflow for
support questions, more information at https://git.io/vM1yQ.

Expected behavior
No crash

To Reproduce
import io
from kivy.core.image import Image as CoreImage
data = io.BytesIO(open("image.png", "rb").read())
texture = CoreImage(data, ext="png", filename="image.png").texture

Code and Logs and screenshots

Crash DUMP:
#0  0x0000000000000000 in ?? ()
#1  0x00007ffff5ce317a in __pyx_f_4kivy_8graphics_12opengl_utils_gl_get_extensions (__pyx_skip_dispatch=__pyx_skip_dispatch@entry=0) at /project/kivy/graphics/opengl_utils.c:3090
#2  0x00007ffff5ce47e4 in __pyx_f_4kivy_8graphics_12opengl_utils_gl_has_extension (__pyx_v_name=0x7ffff6857f00, __pyx_skip_dispatch=__pyx_skip_dispatch@entry=0) at /project/kivy/graphics/opengl_utils.c:3441
#3  0x00007ffff5ce8008 in __pyx_f_4kivy_8graphics_12opengl_utils_gl_has_capability (__pyx_v_cap=2, __pyx_skip_dispatch=<optimized out>) at /project/kivy/graphics/opengl_utils.c:3945
#4  0x00007ffff5e61db4 in __pyx_pf_4kivy_8graphics_7texture_2texture_create_from_data (__pyx_self=<optimized out>, __pyx_v_mipmap=<optimized out>, __pyx_v_im=<optimized out>) at /project/kivy/graphics/texture.c:10360
#5  __pyx_pw_4kivy_8graphics_7texture_3texture_create_from_data (__pyx_self=<optimized out>, __pyx_args=<optimized out>, __pyx_kwds=<optimized out>) at /project/kivy/graphics/texture.c:10245
#6  0x0000555555758c47 in cfunction_call (func=0x7ffff6821710, args=<optimized out>, kwargs=<optimized out>) at Objects/methodobject.c:542

Additional context
Crashes !ONLY! when accessing ".texture".
Used latest version of SDL as well as older 2.26.5

@misl6
Copy link
Member

misl6 commented Oct 15, 2023

This happens only when using CoreImage directly?

@misl6 misl6 added the awaiting-reply Waiting for reply from issue opener, will be closed if no reply label Oct 15, 2023
@SanAndreyas
Copy link
Contributor Author

SanAndreyas commented Oct 15, 2023

texture = CoreImage(data, ext="png", filename="image.png").texture # crashes
image = CoreImage(data, ext="png", filename="image.png") # does not crash

If I create the texture from a .png file directly and not from data, it works.
As you can see at #5 it crashes only when taking the texture from data in function texture_create_from_data() which eventually calls gl_get_extensions() where the actual seg fault happends.

@github-actions github-actions bot removed the awaiting-reply Waiting for reply from issue opener, will be closed if no reply label Oct 15, 2023
@misl6 misl6 added Status: Needs-analysis Issue needs to be analyzed if it's real Type: Bug A bug or something not working as intended labels Nov 4, 2023
@mak8kammerer
Copy link
Contributor

Texture class use OpenGL functions. The OpenGL context is not created in your code, which leads to a segmentation fault.

@SanAndreyas
Copy link
Contributor Author

SanAndreyas commented Jan 13, 2024

Texture class use OpenGL functions. The OpenGL context is not created in your code, which leads to a segmentation fault.

Thank you for your analysis. Your suggestion indeed fixed the issue ( no segmentation fault ).

from kivy.app import App
from kivy.uix.widget import Widget
from kivy.graphics import Color, Rectangle


class MyWidget(Widget):
    def __init__(self, **kwargs):
        super(MyWidget, self).__init__(**kwargs)
        with self.canvas:
            import io
            from kivy.core.image import Image as CoreImage
            data = io.BytesIO(open("image.png", "rb").read())
            texture = CoreImage(data, ext="png", filename="image.png").texture
            self.rect = Rectangle(pos=(100, 100), size=(200, 200), texture=texture)


class MyApp(App):
    def build(self):
        return MyWidget()


if __name__ == '__main__':
    MyApp().run()

@SanAndreyas
Copy link
Contributor Author

SanAndreyas commented Jan 13, 2024

I have now actually found on the texture page documentation the following:

Warning

Using Texture before OpenGL has been initialized will lead to a crash. If you need to create textures before the application has started, import Window first: from kivy.core.window import Window

from kivy.core.window import Window

import io
from kivy.core.image import Image as CoreImage
data = io.BytesIO(open("image.png", "rb").read())
texture = CoreImage(data, ext="png", filename="image.png").texture

This fixed the crash, seems to be a known limitation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Needs-analysis Issue needs to be analyzed if it's real Type: Bug A bug or something not working as intended
Projects
None yet
Development

No branches or pull requests

4 participants