Repository navigation
view_set_viewport follow-ups: polygon off from a Draw event, camera fields, bad values - #807
Conversation
…nt, camera fields, bad values - Turning a polygon off (polygons : []) from a Draw event, while the view's surface is the render target, no longer unbalances the surface stack. DrawViews resets the target only if it set it, rather than checking the view's surface again after the Draw event. The surface view_set_viewport made is freed once it's off the surface stack (surface_free won't free a target), instead of leaking. - The room rectangle only changes the camera fields that are given, so roomRectX alone doesn't undo a camera_set_view_pos y, and a call without roomRect fields leaves the camera alone. - polygons with an odd number of values, and non-finite values (NaN, infinity) in polygons or the screen/roomRect fields, raise errors. Found by GM-TestFramework#386 at 3cd731d. Claude-Session: https://claude.ai/code/session_01EgTASfpMoBvX7TBDy119t5
iampremo
left a comment
There was a problem hiding this comment.
Reviewed at 8ef1195.
Looks good to me. The DrawViews flag fixes the unbalanced-stack crash, and it also covers the opposite case where a Draw event creates the view's surface after the target was chosen. CheckForSurface sees the surface_set_target_system push, so the view's surface gets queued instead of hitting surface_free's "in use" refusal, and the identity check in the flush keeps a reused ID safe. Applying only the given roomRect* fields to the camera fixes the camera_set_view_pos regression. I have two small optional nits below.
Automated reviewThis PR follows up on Open: 1 nit. New in this review: the review comments. Reviewed 75a27d3 Advisory: this check doesn't block merging. It runs again on each push. Reply in a comment's thread if it is wrong, and resolve the thread once it is dealt with: the next review reads both. |
…thing, flush after the views, exact target flag - The polygon's values are checked (finite) and the polygon triangulated before any of the entry is applied, next to the odd-length check, so a rejected call changes nothing. - DrawViews also frees queued view_set_viewport surfaces once after the views loop, so a surface let go while the game had it as the target outside DrawViews is freed even if no view is visible. - viewSurfaceTargetSet is true only when surface_set_target_system actually pushed the surface (it pushes nothing for a surface that no longer exists). Claude-Session: https://claude.ai/code/session_01EgTASfpMoBvX7TBDy119t5
iampremo
left a comment
There was a problem hiding this comment.
Reviewed at 75a27d3.
Re-reviewed at 75a27d3. Both of my nits are fixed, and the code matches the replies.
- Rejected call: the finite check on
polygonsand the ear-clip now run next to the odd-length check, before the port, polygon, callbacks or camera are written. So a non-finite value or a polygon that can't be triangulated now leaves the entry unchanged. - Flush after the loop:
ViewPolygon_FlushSurfaceFrees()now also runs once after the views loop inDrawViews, inside the same@if. A surface queued outsideDrawViewsis freed on the next frame even if no view is visible.
The bot's two nits are also fixed. The polygon check is the same fix as mine. viewSurfaceTargetSet is now true only if g_SurfaceStack actually grew. That matches surface_set_target_system_RELEASE, which pushes nothing when the surface or its depth surface is missing. So a stale view_surface_id no longer leads to a surface_reset_target() with nothing to pop.
Looks good to me.
| yyError("view_set_viewport() - polygons in entry " + index + " has an odd number of values; it needs x,y pairs"); | ||
| return; | ||
| } | ||
| // check and triangulate the polygon before anything is changed, so a call that is rejected changes nothing |
There was a problem hiding this comment.
Nit: The comment says "a call that is rejected changes nothing", but that only holds within one entry. Entries are checked and applied one at a time in the outer loop, so view_set_viewport([{ screenX: 10, polygons: [...] }, { polygons: [0, 0, 1] }]) applies entry 0 in full (port, polygon, surface, camera) before entry 1 raises the odd-length error. A game that catches the error is left with some entries applied and others not. Either check every entry in a first pass (fields, polygon, earclip, callables) and apply them in a second, or change the comment to say "an entry that is rejected changes nothing for that entry".
Follow-up to #806 (
view_set_viewport, non-rectangular viewports, https://github.com/YoYoGames/GMS2-Runner-Main/issues/1076). YoYoGames/GM-TestFramework#386 at 3cd731d added cases that HTML5develop(3e6e1ef, with #806) fails. In headless Chrome, 4 of the 6 tests reported: the keeps-fields test failed, and the Draw-event test ended the game before the errors test could run.Fixes:
view_set_viewport([{ polygons: [] }])while the view's surface is the render target used to end the game with "Unbalanced surface stack". It freed the view's surface and set it to -1, andDrawViewsthen skippedsurface_reset_target()because it checked the view's surface again after the Draw event.DrawViewsnow resets the target only if it set it.surface_freewon't free a surface that is still a target, so the surfaceview_set_viewportmade is queued and freed once it's off the stack, right after the view is drawn. Before, it leaked.roomRectXon its own used to reset the camera's y toview_yview, undoing acamera_set_view_pos. A call without anyroomRect*fields leaves the camera alone, as before.polygonswith an odd number of values raises an error, and so do non-finite values (NaN, infinity) inpolygonsor in thescreen*/roomRect*fields.Tests: BasicViewSetViewportTestSuite from GM-TestFramework#386 at 3cd731d, raw build, headless Chrome:
develop3e6e1efroomRectXmoved the camera's y)There were no console errors on this branch.
Deferred free, checked over CDP in the issue's ViewportTriangles project:
polygons: []setview_surface_idto -1 and queued the surface.surface_reset_target(), it was freed: 4 live surfaces went down to 3, with nothing left queued.