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

sdlgfx behaviour showing noise (reads wrong memory) on newer macs #282

Open
JASlotman opened this issue Mar 20, 2025 · 4 comments
Open

sdlgfx behaviour showing noise (reads wrong memory) on newer macs #282

JASlotman opened this issue Mar 20, 2025 · 4 comments

Comments

@JASlotman
Copy link

What doesn't work?
We made a small engine that we use for students, so we can test many different architectures. We stumbled upon a bug where when we use the drawcricle and other shapes from the gfx library and update a surface or window it draws a noisy reactangles around the shapes we want to display.

How To Reproduce
Any code that reproduces the bug, e.g.:

Sorry I dont have a minimal code that creates this bug here are three minimal tidbits of our code that give the problem

def update(self,name):
        window = self.windowlist.get(name)
        SDL_ShowWindow(window)
        ren = SDL_GetRenderer(window)
        SDL_RenderPresent(ren)

def clear(self,name):
        ren = SDL_GetRenderer(self.windowlist.get(name))
        SDL_SetRenderDrawColor(ren, 0, 0, 0, 255)
        SDL_RenderClear(ren)


def drawCircle(self,x,y,r,color,filled):
        if filled:
            filledCircleColor(self.renderer,int(x),int(self.ySize-y),int(r),color)
        else:
            aacircleColor(self.renderer,int(x),int(self.ySize-y),int(r),color)

#psuedocode intended to draw a line that causes problems but works on all other architectures (linux, windows, old macs) but not on new macs adding a clear solves this but it will clear the screen in between updates which is not intended behavior (i.e. does not draw a line but shows a moving circle)

while running:
      x += 1
      y += 1
      drawCircle(x,y,r,col,True)
      update()

Platform (if relevant):

  • OS: [Mac, newer machines]
  • Python Version: [>3.9]
  • SDL2 Version: [0.9.16 / 2.30.10]
  • Using pysdl2-dll: [Yes]

Additional context
Only drawing a single element also causes this unless we first do a clear. When a student that was working on an other project used and saw that the rectangles were not filled with random noise but with an image that he loaded into memory for another project, which makes us beleive sdl2 might be accessing a wrong memory area in these newer macs. (my guess is these are the M1 or higher machines)

@JASlotman
Copy link
Author

The engine we made for these student projects we called nanopy, if someone wants to look into this I can grant access to this private project on our github.

@a-hurst
Copy link
Member

a-hurst commented Mar 20, 2025

Hi @JASlotman, thanks for the bug report! It's entirely possible there's a weird ARM64 or Apple Silicon bug with SDL2_gfx in the pysdl2-dll binaries. Does the bug reproduce on your end using the gfxdrawing.py example in the PySDL2 examples? On my system (an M1 MBP running Ventura) that runs as expected.

In your example code, I also noticed there's no call to fill the rendering context between each refresh and drawing. Is that correct? If so, I can imagine that might cause some undefined system-specific behaviour!

Also depending on the context, you may be better off using a Python-based drawing library like Pillow or Aggdraw and then using sdl2.ext.pillow_to_surface to convert them to an SDL surface for rendering, with the benefit of fewer bugs (SDL2_gfx hasn't been updated by its author in over 7 years), more flexibility, and better rendering quality. I can put together an example if you'd like!

@JASlotman
Copy link
Author

Thank you for your input, I will test the gfxdrawing.py when I can access a mac again that has the issue. I'll also look into the fill and the pillow library.

Thanks a lot and I will report back

@JASlotman
Copy link
Author

@a-hurst I've looked into the gfxdrawing example and there is one essential difference to the behavior we want to achieve. But we might be going about it wrong. In the example many shapes are drawn to a black background. What we want to do is not clear the surface in between but write to the exsisting drawing. And that's when we run into our problem. What would be the correct way to do this? (i.e. in the gfxdrawing example not writing the next shapes to a new surface but adding them to the existing one)

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

2 participants