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

getstati to local variables (not global) messes with R_BeginPolygon #218

Open
Baker7 opened this issue Nov 14, 2024 · 0 comments
Open

getstati to local variables (not global) messes with R_BeginPolygon #218

Baker7 opened this issue Nov 14, 2024 · 0 comments

Comments

@Baker7
Copy link

Baker7 commented Nov 14, 2024

I have procrastinated on reporting this one, although the screenshots are from the Zircon Engine, to the best of my knowledge this affects every DarkPlaces engine from 2014 forward as I initially thought this could be an engine bug only to find that every DarkPlaces seems affected. I procrastinated because I can work around this oddball issue by moving code to a different function or other ways, so this doesn't stop me from doing anything, but the disturbing nature of this issue is the concern ...

The offending code:
float viewheight = getstati(STAT_VIEWHEIGHT);

(Because this code should not mess up rendering, something is somehow getting memory stomped .. mechanism unknown. And it only occurs if the "viewheight" variable is later read by QuakeC. So some Quake VM issue seems to be living here ...)

As a local variable that is read later in the function ...
(Notice the compass is rendered with a missing block).

local_getstati.MConverter.eu.webm

As a global variable ... there are no issues in the rendering.

global_getstati.MConverter.eu.webm

If the variable "viewheight" is a local variable and it is ALSO read later in the SAME function, it messes up my compass drawing with R_BeginPolygon.

The drawing code looks like ...

`#define F 2
void Compass_Draw_2D ()
{
if (!autocvar_showcompass)
return;

//           X    Y   U  768 = 32 (x24)  192 = 8 (x24)
float mx = 192 * F;
float my = 12 *F;

vector L = { ov.vid_conwidth  * 0.5 - mx, my };
vector T = { ov.vid_conwidth  * 0.5 + mx, my };
vector R = { ov.vid_conwidth  * 0.5 + mx, my + 16 * F };
vector B = { ov.vid_conwidth  * 0.5 - mx, my + 16 * F };

vector L2 = { ov.vid_conwidth  * 0.5 - mx / 32, my - 16};
vector T2 = { ov.vid_conwidth  * 0.5 + mx / 32, my - 16 };
vector R2 = { ov.vid_conwidth  * 0.5 + mx / 32, my + 16 * F  - 24};
vector B2 = { ov.vid_conwidth  * 0.5 - mx / 32, my + 16 * F  - 24};

// Angles are -180 to 180 .. Lets say compass starts at E.  N  W  S  90 is north.

float LX = pmove_angles_y; // Yaw
if (LX < 0)
	LX += 360.0;
LX = (360) - (LX + 45.0);
LX += 90;

float T0 = LX / 360.0;
vector ST0 = { T0 + 0.0 , 0 };
vector ST1 = { T0 + 1.0 , 0 };
vector ST2 = { T0 + 1.0 , 1 };
vector ST3 = { T0 + 0.0 , 1 };

// Draw compass
R_BeginPolygon (COMPASS_TEXTURE_PNG, DRAWFLAG_NORMAL_0, is_2d_true);	
	R_PolygonVertex (L, ST0, white_111, alpha_1_0);
	R_PolygonVertex (T, ST1, white_111, alpha_1_0);
	R_PolygonVertex (R, ST2, white_111, alpha_1_0);
	R_PolygonVertex (B, ST3, white_111, alpha_1_0);
R_EndPolygon ();

// Draw pointer
vector vc = stov(autocvar_compass_pointer_color);
R_BeginPolygon (COMPASS_POINTER_TEXTURE_PNG, DRAWFLAG_NORMAL_0, is_2d_true);	
	R_PolygonVertex (L2, '0 0', vc, alpha_1_0);
	R_PolygonVertex (T2, '1 0', vc, alpha_1_0);
	R_PolygonVertex (R2, '1 1', vc, alpha_1_0);
	R_PolygonVertex (B2, '0 1', vc, alpha_1_0);
R_EndPolygon ();

}

`

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

1 participant