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

ps1: gpu: Ensure hi >= lo when calling std::clamp() #1851

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

thentenaar
Copy link

@thentenaar thentenaar commented Feb 21, 2025

On Lunar Disc 1, when entering Berg (about two minutes in,) going into Alex's house or the barn to the right of it, winds up causing an assertion failure in std::clamp() on the screen transition. Could be a bug in the game where it sends the 0xe3/0xe4 coords in the wrong order, or if it's off by one calculating them. Not sure if the real hardware ignores it or does anything in particular as a result.

Adding some print() calls in GPU::Render::triangle() before the clamp, I see:

v0=(320,216), v1=(336,216) v2=(320,232)
vmin.x=320, x1=160 x2=159
vmin.y=216, y1=112 y2=111
vmax.x=336, x1=160 x2=159
vmax.y=232, y1=112 y2=111

/usr/lib/gcc/x86_64-pc-linux-gnu/14/include/g++-v14/bits/stl_algo.h:3626: constexpr const _Tp& std::clamp(const _Tp&, const _Tp&, const _Tp&) [with _Tp = int]: Assertion '!(__hi < __lo)' failed.

Thus, this patch ensures hi >= lo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant