-
Notifications
You must be signed in to change notification settings - Fork 96
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
negative uints #93
Comments
Do you have a patch? CC: @andrei-drexler, @ericwa |
I'll add a guard against outputting those <3 vert faces in ericw-tools in the future.. Not sure where the best place to patch it in QS is though. |
Would it not be OK to simply Sys_Error with any such bad maps in Mod_LoadEdges ??
Also: Can you give links to such bad maps please? |
It looks like that patch is checking the wrong thing - that's checking total edge count in the .bsp being < 3. This issue is about otherwise well-formed maps that have one degenerate face (0, 1, or 2 edges just for a specific bad face.) I've fixed this in ericw-tools a while ago so hopefully it won't be a problem on many .bsp's. |
OK, should I close this then? Or, do you have a better patch? |
.. and the correct check should be something like this I guess ? diff --git a/Quake/gl_model.c b/Quake/gl_model.c
index 6e5cfd7..52bad53 100644
--- a/Quake/gl_model.c
+++ b/Quake/gl_model.c
@@ -1281,6 +1281,9 @@ static void Mod_LoadFaces (lump_t *l, qboolean bsp2)
ins++;
}
+ if (out->numedges < 3)
+ Sys_Error ("surfnum %d: bad numedges %d", surfnum, out->numedges);
+
out->flags = 0;
if (side) |
OK, I just tried several (surely not all) mods with the following: diff --git a/Quake/gl_model.c b/Quake/gl_model.c
index 6e5cfd7..70b1689 100644
--- a/Quake/gl_model.c
+++ b/Quake/gl_model.c
@@ -1282,6 +1282,8 @@ static void Mod_LoadFaces (lump_t *l, qboolean bsp2)
}
out->flags = 0;
+ if (out->numedges < 3)
+ Con_Warning("surfnum %d: bad numedges %d\n", surfnum, out->numedges);
if (side)
out->flags |= SURF_PLANEBACK; It resulted in the following:
Then applied the following to r_world.c: diff --git a/Quake/r_world.c b/Quake/r_world.c
index 5cc9667..1cab21b 100644
--- a/Quake/r_world.c
+++ b/Quake/r_world.c
@@ -319,7 +319,7 @@
//
//==============================================================================
-static unsigned int R_NumTriangleIndicesForSurf (msurface_t *s)
+static int R_NumTriangleIndicesForSurf (msurface_t *s)
{
return 3 * (s->numedges - 2);
}
@@ -384,9 +384,12 @@ using VBOs.
*/
static void R_BatchSurface (msurface_t *s)
{
- int num_surf_indices;
+ int num_surf_indices = R_NumTriangleIndicesForSurf (s);
- num_surf_indices = R_NumTriangleIndicesForSurf (s);
+ if (num_surf_indices <= 0) {
+ Con_Warning("bad numedges for surface\n");
+ return;
+ }
if (num_vbo_indices + num_surf_indices > MAX_BATCH_SIZE)
R_FlushBatch();
... and noclip'ed around in alk_dancing and ej3_bizz, hoping to see what I want to apply the first warning patch to However, I don't know whether on not the change to r_world.c is correct |
... well, of course I couldn't hit the issue because I mistakenly @ericwa -- what do you think? |
IMO the right thing is do a developer warning on first encountering this, but silence after that, and just ignore the faces. |
Isn't the patch above doing that already (inlined below again with warning in R_BatchSurface changed into a Con_DWarning), or am I missing something? If you want to Con_DWarning in R_BatchSurface only once, I really don't know how it's doable. diff --git a/Quake/gl_model.c b/Quake/gl_model.c
index 6e5cfd7..70b1689 100644
--- a/Quake/gl_model.c
+++ b/Quake/gl_model.c
@@ -1282,6 +1282,8 @@ static void Mod_LoadFaces (lump_t *l, qboolean bsp2)
}
out->flags = 0;
+ if (out->numedges < 3)
+ Con_Warning("surfnum %d: bad numedges %d\n", surfnum, out->numedges);
if (side)
out->flags |= SURF_PLANEBACK;
diff --git a/Quake/r_world.c b/Quake/r_world.c
index 5cc9667..1cab21b 100644
--- a/Quake/r_world.c
+++ b/Quake/r_world.c
@@ -319,7 +319,7 @@ void R_DrawTextureChains_Glow (qmodel_t *model, entity_t *ent, texchain_t chain)
//
//==============================================================================
-static unsigned int R_NumTriangleIndicesForSurf (msurface_t *s)
+static int R_NumTriangleIndicesForSurf (msurface_t *s)
{
return 3 * (s->numedges - 2);
}
@@ -384,9 +384,12 @@ using VBOs.
*/
static void R_BatchSurface (msurface_t *s)
{
- int num_surf_indices;
+ int num_surf_indices = R_NumTriangleIndicesForSurf (s);
- num_surf_indices = R_NumTriangleIndicesForSurf (s);
+ if (num_surf_indices <= 0) {
+ Con_DWarning("bad numedges for surface\n");
+ return;
+ }
if (num_vbo_indices + num_surf_indices > MAX_BATCH_SIZE)
R_FlushBatch(); |
I think @ericwa probably means the thing that you present in this patch (the previous two combined), minus the |
I.e.: drop the warning at render time altogether? |
That's what I think it meant yes, but @ericwa would have to confirm that. |
OK, here is what I have hopefully finalized diff --git a/Quake/gl_model.c b/Quake/gl_model.c
index 6e5cfd7..cc12d27 100644
--- a/Quake/gl_model.c
+++ b/Quake/gl_model.c
@@ -1282,6 +1282,8 @@ static void Mod_LoadFaces (lump_t *l, qboolean bsp2)
}
out->flags = 0;
+ if (out->numedges < 3)
+ Con_Warning("surfnum %d: bad numedges %d\n", surfnum, out->numedges);
if (side)
out->flags |= SURF_PLANEBACK;
diff --git a/Quake/r_world.c b/Quake/r_world.c
index 5cc9667..22dd574 100644
--- a/Quake/r_world.c
+++ b/Quake/r_world.c
@@ -319,7 +319,7 @@ void R_DrawTextureChains_Glow (qmodel_t *model, entity_t *ent, texchain_t chain)
//
//==============================================================================
-static unsigned int R_NumTriangleIndicesForSurf (msurface_t *s)
+static int R_NumTriangleIndicesForSurf (msurface_t *s)
{
return 3 * (s->numedges - 2);
}
@@ -384,9 +384,13 @@ using VBOs.
*/
static void R_BatchSurface (msurface_t *s)
{
- int num_surf_indices;
+ int num_surf_indices = R_NumTriangleIndicesForSurf (s);
- num_surf_indices = R_NumTriangleIndicesForSurf (s);
+ if (num_surf_indices <= 0)
+ {
+ // Con_DWarning ("bad numedges for surface\n");
+ return;
+ }
if (num_vbo_indices + num_surf_indices > MAX_BATCH_SIZE)
R_FlushBatch(); |
Just an additional comment on the render time warning: I tried your patch again (the one where the render time warning isn't commented out) and realized that I missed the significance of the change from |
It is commented out, so no worries in there, no? (I had just wanted to test whether any badness was associated with the fix, now no need I guess.) |
Sure, no worries there. I just thought I'd mention that in case there was more to the render time warning. |
Just tested the last patch on I might suggest changing the Either |
e.g.: mj4m?, alk_dancing, ej3_bizz, rotj_entsoy... See: #93 issue was reported by Spike.
Patch pushed as commit 7029526, kept the warning in Mod_LoadFaces as Con_Warning. Thanks. |
e.g.: mj4m?, alk_dancing, ej3_bizz, rotj_entsoy... See: sezero#93 issue was reported by Spike.
e.g.: mj4m?, alk_dancing, ej3_bizz, rotj_entsoy... See: sezero/quakespasm#93 issue was reported by Spike. (cherry picked from commit 7029526)
https://github.com/sezero/quakespasm/blob/master/Quake/r_world.c#L324
there are bad bsps out there with only 1 or 2 edges per face (ericw-tools seems to generate them).
these degenerate faces can thus return -3 here...
R_BatchSurface then ends up overflowing the vbo_indices array with the next surface, or telling the glDrawElements to draw rather more primitives than was really intended. both situations are rather likely to result in crashes...
The text was updated successfully, but these errors were encountered: