GithubHelp home page GithubHelp logo

Comments (2)

swistakm avatar swistakm commented on July 22, 2024

I have reproduced the issue. I was testing on pygame & windows 10. I was using following snippet:

sel = imgui.selectable('click me to give draw list & segfault', False)
if sel[1]:  # clicked
    print("draws")
    draws = imgui.get_draw_data()
    print(draws)
    print(draws.commands_lists)

In my situation it doesn't break immidiately on imgui.get_draw_data() call but on draws.commands_lists attribute access. @pconerly is it the same for you?

Regarding the possible cause, I have to look deeper into C++ sources to confirm that but I'm pretty confident you should not try to access the draw data and commands lists before they are finalized with imgui.render() call (or Render() in C++). If you already use some built-in integration (Pygame, PySDL2, etc.) it will mean that window is already drawn.

If you really want to access the draw commands before they are actually drawn you'll have to install your own render callback in that will override one installed by PySDL2 integration. This requires some trickery but is definitely doable:

...
window, gl_context = impl_pysdl2_init()
renderer = SDL2Renderer(window)

def overridden_callback(draw_data):
    print(draw_data)
    print(draw_data.commands_lists)
    renderer.render(draw_data)

io = imgui.get_io()
io.render_callback = overridden_callback
...

from pyimgui.

swistakm avatar swistakm commented on July 22, 2024

I wonder if we could/should make some kind of safeguard around these to make sure we will raise an exception in such condition. This will guard us against segfaults because these in Python are usually hard to debug.

Edit: We may also check if newer versions of ImGui have some additional asserts in such places. If so, they would be automatically translated to Python exceptions.

from pyimgui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.