Fixed [2.1.17] MD2 destroys the game

Status
Not open for further replies.

Yacker

Metallic
Loading this model over Sonic, playing in OpenGL with md2s on, playing as Sonic, and switching maps several times will cause the game to slowly break apart.
It usually starts with other character md2's vanishing or missing textures, and progresses to cause all md2s in the game to lose textures, and it can even make it impossible to add files to the game.
It might cause further mayhem with enough map loads, netplay, and other variables, but I haven't tested much.
Link to the model: https://www.dropbox.com/s/pz7wv1b2dg3k4gr/md2.zip?dl=0
 
Last edited by a moderator:
OpenGL in a nutshell is horribly broken and un-optimized. You'd be better off waiting for RedEnchilada, Wofly or another Furyhunter to start working on that renderer before you start using MD2s again.
 
...make it impossible to add files to the game? What on earth, is there some memory issue or something going on here I wonder?

Also tbh we'd be better off fixing the bug now rather than waiting for an OpenGL remake that may not happen for years yet. This sounds quite a serious one indeed. (Seriously guys stop dismissing OpenGL bugs due to the state of the renderer itself, they're not necessarily impossible to fix contrary to popular opinion =V)
 
Well, the model itself isn't setup proper for SRB2. SRB2 has a poly limit of 4048 vertices per model. (this has 6391) This alone is probably the cause of game breaking. I'm also unsure whats going on with the animations? You have 198 blank frame animations, separated out, but all are just the modeled T-posed. Your limited to the same number of frames as the sprites. (1 idle frame, 2 boredom frames, 8 walking frames, 4 spinning frames, 1 springup frame, 4 running frames, 6 ability(super) frames, 1 airbubble frame, 1 taking damaged frame, 1 death frame, 2 falling frames, 1 tailsgrab frame, 1 frame for lifeupbox and 1 for goalsign, in that order for a default character)
 
I wasn't aware of the vertex limit, only the triangle limit. The animations...I, uh, don't know. I didn't actually make any animations for the model and simply loaded it to see if it would...and, well, the results are as posted. Still, though, the game should probably...not load the model or error or something if a model doesn't meet that obscure specification instead of just, well, breaking apart.
 
SRB2 has a poly limit of 4048 vertices per model.

Actually it's 4096, quickly checking the source code. Most of the MD2 limits are powers of 2, conveniently enough.

But yeah, it is strange the game doesn't check the vertex etc limits against the model's specs at all. Probably should spit out console error messages too or something.
 
I once had this problem before and I can confirm 100% it's the vertices limit. I experienced the same problems and what not, textures acting up, md2s not appearing (and funny enough, my one sonic md2 had his body all normal, but his head, hands, and shoes were missing!) Etc.

Once I quit the game, and fixed to model to be under 5,000 verts (as MI stated 4096), it worked perfectly. I didn't report it back then since I knew it was a mistake on my end because of the vert count.
 
Actually it's 4096, quickly checking the source code. Most of the MD2 limits are powers of 2, conveniently enough.

But yeah, it is strange the game doesn't check the vertex etc limits against the model's specs at all. Probably should spit out console error messages too or something.

My bad, was thinking the old limit. (2048) I never stray too far over 3000 just to be safe, and in case I redo something later on. Perhaps make a clearer warning on the wiki page about it? I assume most people looking up how to make models for the game are looking there. But honestly, the model not appearing at all or incorrectly should be enough to tell you somethings wrong with it, I don't understand why you'd proceed to change the map multiple times.
 
Better to let the models -1500. as well stable performance remains.
Is poorly positioned the model, "lying down".
 
Last edited:
While making a fix for this (that's a link btw) , I've found other MD2s such as Jeck's Sonic (I think it was his?) break other limits such as the one for texture coordinatess with no issue (the Sonic model I was using had something like 12945 texture coords when the max was 4096). Makes me wonder whether the limits need to be upped, or whether the MD2s shouldn't use as much stuff as they do? *shrugs*

Anyway, so you guys know, the "limits" as of 2.1.16 are supposed to be:

Code:
#define MD2_MAX_TRIANGLES               8192
#define MD2_MAX_VERTICES                4096
#define MD2_MAX_TEXCOORDS               4096
#define MD2_MAX_FRAMES                  512
#define MD2_MAX_SKINS                   32

The "skins" one seems to not matter at all really since all MD2s are forced to have only one anyway. Only the max vertices limit was ever referenced in the source code for anything up till now as it turns out, which is odd really.

But there we go, it's SRB2's source code. =P
 
My fix is in now, having too many vertices should now simply make the console spit out an error saying you have too many (and how many maximum are accepted). The number of frames and triangles are also checked btw.
 
You've possibly introduced a new bug, as line 794 is
Code:
md2_models[[B]s[/B]].error = false;
instead of
Code:
md2_models[[B]i[/B]].error = false;
 
Whoops, well spotted, will fix right away.

EDIT: and the fix has been merged in too now, thanks for spotting that x_x
 
Last edited:
Status
Not open for further replies.

Who is viewing this thread (Total: 1, Members: 0, Guests: 1)

Back
Top