Game stretched on some android phones

I have made a custom render script that adjusts the viewport so circles stay circles. It works fine on desktop and html. I just change the viewport line.

render.set_viewport((render.get_window_width()-render.get_width())/2,
(render.get_window_height()-render.get_height())/2,
render.get_width(),
render.get_height())

That’s literally all I do and it works fine.

On my android phone though the circles are stretched out vertically a bit. It’s a Samsung GT S7580. Is there a way of reading the aspect of the screen. I just installed on another phone and exactly the same stretching is taking place.

On a S4 the game is tiny but correct aspect on others defold seems to stretch the game losing the aspect ratio.

You can read the current window dimensions using render.get_window_width() and render.get_window_height() and you read the dimensions from game.project using either render.get_width() or sys.get_config("display.width")

I’m sure I am doing as you say. It works on some devices and not others so I’m sure this is a bug now

Hmm, maybe I could log the window width and height that are being reported. I was thinking maybe it gets the wrong dimension somehow.

It’s probably a problem with your render script. What happens if you resize the window on desktop while the game is running? Can you share your complete render script?

Sure. I think I only changed the viewport though.

function update(self)
render.set_depth_mask(true)
render.clear({[render.BUFFER_COLOR_BIT] = self.clear_color, [render.BUFFER_DEPTH_BIT] = 1, [render.BUFFER_STENCIL_BIT] = 0})

render.set_viewport((render.get_window_width()-render.get_width())/2,
                    (render.get_window_height()-render.get_height())/2,
                    render.get_width(),
                    render.get_height())

render.set_view(self.view)

render.set_depth_mask(false)
render.disable_state(render.STATE_DEPTH_TEST)
render.disable_state(render.STATE_STENCIL_TEST)
render.enable_state(render.STATE_BLEND)
render.set_blend_func(render.BLEND_SRC_ALPHA, render.BLEND_ONE_MINUS_SRC_ALPHA)
render.disable_state(render.STATE_CULL_FACE)

render.set_projection(vmath.matrix4_orthographic(0, render.get_width(), 0, render.get_height(), -1, 1))

render.draw(self.tile_pred)
render.draw(self.particle_pred)
render.draw_debug3d()

render.set_view(vmath.matrix4())
render.set_projection(vmath.matrix4_orthographic(0, render.get_window_width(), 0, render.get_window_height(), -1, 1))

render.enable_state(render.STATE_STENCIL_TEST)
render.draw(self.gui_pred)
render.draw(self.text_pred)
render.disable_state(render.STATE_STENCIL_TEST)

render.set_depth_mask(false)
render.draw_debug2d()

end

And basically it works fine on the desktop and HTML on an S4 it does what I expect. But not the two other phones that I tried.

Ah ok, sorry that wasn’t the whole script, but I only changed it in one place. I’m going to put some logs in the phone now

I’ve bumped this down from a bug because theres sooo much stuff about aspect ration and I just want to get some logs to be sure what is happening. I feel that somebody else should have seen this if it’s really a bug