Is zero-height clipping rectangle supported (or misuse)?

TL;DR: SDL_RenderClipRect draws to the whole screen when clipping rectangle has 0 height, on Metal backend (MacOS).

Background Context:

My game’s rendering system uses SDL2’s 2D accelerated rendering API to draw isometric tiles on the screen. My design only redraws areas when something changes (i.e. “screen damage” occurs) and uses SDL_RenderSetClipRect to specify an area of the screen where it will redraw, then only draws items that the redraw area touches. The redraw area is algorithmically determined and was able to have a height of 0. While in my specific use case, I realized I should probably just avoid the drawing operations entirely when the height is 0, it nonetheless took some troubleshooting to find out what was going on.

SDL Behavior:

When specifically using the Metal backend on MacOS, calling SDL_RenderSetClipRect with the address of an SDL_Rect whose h is 0 causes subsequent drawing operations to apply to the entire screen.

Expected Behavior:

  • I’d have expected a zero-height clipping rectangle to effectively disable drawing. Other SDL renderer backends seem to behave this way as far as I’ve noticed.
  • Is this actually valid to consider a bug? Is a no-height rectangle a misuse of the renderer API?
  • If this is considered misuse of the API, SDL_RenderSetClipRect would ideally return a value indicating an error has occurred, and set a message for SDL_GetError. At the moment, it just returns 0 indicating the operation was successful.
  • If this is a misuse, SDL would further ideally refuse to set the clipping and indicate an error even on renderers where this currently has what I think is intuitive behavior. This would make sure nobody using another renderer backend during development unwittingly develops something that violates the intended use of the API and runs into unexpected behavior on another backend that is not as forgiving.


  • I have no current need for this behavior to be changed. In my case I got around this by manually avoiding draws on zero-height regions, which actually was an optimization for me.
  • It mainly just seems like a potential hazard for developers who expect it to work the same as on other renderers. For example I ported to MacOS after having designed the game primarily on Windows.

Simple Runnable Sample (MacOS): (5.4 KB)

Samples for other platforms don’t seem applicable since this appears to be specific to the Metal renderer backend, at least as far as I’ve observed.

Might as well also take a moment to say thanks for this library and the continued support and improvements through the years.

1 Like