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

[GoldSource] Texture overflow: GL_MAXTEXTURES crash #2234

Open
metita opened this issue Apr 24, 2019 · 27 comments
Open

[GoldSource] Texture overflow: GL_MAXTEXTURES crash #2234

metita opened this issue Apr 24, 2019 · 27 comments
Assignees
Milestone

Comments

@metita
Copy link

metita commented Apr 24, 2019

Sometimes when you are on a server with a lot of textures (I guess this is the reason based on the error code) and you keep switching between servers, your client will crash randomly. I can't really tell how to reproduce it so if someone has extra info would be amazing.

@metita metita changed the title [GoldSource] GL_MAXTEXTURES crash. [GoldSource] Texture overflow: GL_MAXTEXTURES crash Apr 24, 2019
@metita
Copy link
Author

metita commented Apr 25, 2019

This is a common issue on a lot of mod servers when switching between servers continuously, if someone got the original output on when this crash occurs, would help a lot.

@SamVanheer
Copy link

SamVanheer commented Apr 25, 2019

There are a maximum of 4800 textures that can be loaded. Normally textures are unloaded when the client starts preparing to load a new map. It looks like this part works fine.

Edit: everything below here is wrong, see comment below.

The part that doesn't is the code that reuses texture entries that were freed:

while ( HIBYTE(v12->servercount) & 0x80 )
{
  if ( !v9 )
    v9 = v12;
  ++v13;
  ++v12;
  if ( v13 >= v11 )
    goto LABEL_10;
}

//Other stuff that is ignored

LABEL_10:
if ( !v9 )
{
    v9 = &gltextures[numgltextures++];
    if ( numgltextures >= 4800 )
      Sys_Error("Texture Overflow: MAX_GLTEXTURES");
}

This is from GL_LoadTexture2. It translates to this:

gltexture_t* pSlot = nullptr;

for( int i = 0; i < numgltextures; ++i )
{
    if( gltextures[ i ].servercount >= 0 )
        break;

    if( !pSlot  )
        pSlot  = &gltextures[ i ];
}

//Other stuff that is ignored

if ( !pSlot )
{
    pSlot = &gltextures[numgltextures++];
    if ( numgltextures >= 4800 )
      Sys_Error("Texture Overflow: MAX_GLTEXTURES");
}

This code is supposed to find the first free entry (servercount < 0), but it instead stops searching when it encounters a single texture in use.

As a result GL_LoadTexture2 will almost never reuse freed entries and will keep allocating new entries until it runs out, resulting in the fatal error.

To fix this, the loop needs to be changed to this:

for( int i = 0; i < numgltextures; ++i )
{
    if( gltextures[ i ].servercount >= 0 )
        continue;

    if( !pSlot  )
        pSlot  = &gltextures[ i ];
}

Now it will skip entries in use and correctly reuse free entries.

@mikela-valve This should be fairly simple to fix and test.

@metita
Copy link
Author

metita commented Apr 25, 2019

Thanks @SamVanheer appreciated your work.

@kisak-valve fix proposed? Thanks.

@mikela-valve mikela-valve self-assigned this Apr 25, 2019
@mikela-valve mikela-valve added this to the Next Release milestone Apr 25, 2019
@SamVanheer
Copy link

SamVanheer commented Apr 25, 2019

Sorry, i got this wrong. There's an outer loop that ensures it iterates over each texture.

I did find what i think is the problem: in GL_LoadTexture2 the servercount variable is set depending on the texture type:

if ( textureType == GLT_WORLD )
{
  slot->servercount = gHostSpawnCount;
}
else
{
  slot->servercount = 0;
}

And in GL_UnloadTextures:

if ( pTexture->servercount > 0 && pTexture->servercount != gHostSpawnCount )

All textures other than the world (map textures) are never unloaded. An easy fix is to always use gHostSpawnCount and let all textures unload, but then there's the risk of unloading textures that are only loaded once (e.g. Draw_PicFromWad).

GLT_SYSTEM and GLT_DECAL texture types definitely shouldn't be unloaded, it looks like all others are resources that are loaded once per map. Maybe allowing all of these to be unloaded is the safest bet:

  • GLT_STUDIO
  • GLT_WORLD
  • GLT_SPRITE

It looks like hud sprites are always GLT_HUDSPRITE so they should be safe.

@mikela-valve
Copy link
Member

I'm going to delay this until after the next release as I'd like it to be in a beta that has fewer changes in it to make it easier to notice if any issues arise from unloading these other texture types.

@metita
Copy link
Author

metita commented Oct 23, 2019

@mikela-valve Now that we got a clean beta and the latest update got released officially would like you to take a look at this issue because is a very common one on modded servers.

@dystopm
Copy link

dystopm commented Nov 17, 2019

Any news about this? It's a bit annoying nowadays

@zorkenJB
Copy link

@mikela-valve can you fix this?

@TheDoctor0
Copy link

I would also gladly see this fix applied as it is a common issue nowadays.

@dystopm
Copy link

dystopm commented Jul 19, 2020

Nothing? @mikela-valve it is a frequent error this days, will this ever be considerated on a future release?

@metita
Copy link
Author

metita commented Aug 3, 2020

@mikela-valve Sorry for bothering you with this one, is there a chance for this issue to be somehow added into the beta now that there are almost 0 issues with it? It is a annoying bug that is pretty common nowadays.

@Roccoxx
Copy link

Roccoxx commented Aug 4, 2020

considerating we're getting updates for the game, can you please take a look at this issue? @mikela-valve thanks in advance

@Maria22s
Copy link

Maria22s commented Aug 4, 2020

This is very annoying, can you take a look at it please? @mikela-valve

@SamVanheer
Copy link

You don't all have to get his attention, one person calling for him is more than enough. And the issue is already assigned to the next release milestone so it's a priority issue anyway.

@mikela-valve mikela-valve modified the milestones: Next Release, ToDo Aug 18, 2020
@orinasa
Copy link

orinasa commented Oct 15, 2020

When will it be? after 5 years? or will not at all. @mikela-valve

P.S Do you have an idea how to fix it? Texture overflow: GL_MAXTEXTURES.

@dystopm
Copy link

dystopm commented Oct 15, 2020

This is a high priority issue which is ruining actual gameplay, and also an excuse for players to use pirate software (to fix it) because most servers are modded nowadays with lots of resources, bringing a high chance to suffer this crash - @mikela-valve may I ask again, is there a chance to get this fixed?

@cyb3rm4n
Copy link

Agreed with @PM32, got this error on most of servers (i have my own modded server and my client suffers with this error)

@zorkenJB
Copy link

zorkenJB commented Nov 14, 2020 via email

@Maxi605
Copy link

Maxi605 commented Nov 14, 2020

@mikela-valve can you please fix it? is not that hard On Saturday, November 14, 2020, 01:42:51 AM GMT+2, Alexander Zhukov notifications@github.com wrote: Agreed with @PM32, got this error on most of servers (i have my own modded server and my client suffers with this error) — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

Is not about difficulty, he doesn't have time to work on goldsrc.

@orinasa
Copy link

orinasa commented Nov 16, 2020

@mikela-valve can you please fix it? is not that hard On Saturday, November 14, 2020, 01:42:51 AM GMT+2, Alexander Zhukov notifications@github.com wrote: Agreed with @PM32, got this error on most of servers (i have my own modded server and my client suffers with this error) — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.
Is not about difficulty, he doesn't have time to work on goldsrc.

15 minutes work. and you say he doesn't have time to work? Lol...

@SamVanheer
Copy link

Supporting a 22 year old game is about as low priority as it gets, and chances are the source code isn't even accessible remotely so they can't work on it until the pandemic is under control. All you can do is be patient.

@s1lentq
Copy link

s1lentq commented Nov 20, 2020

Sorry, i got this wrong. There's an outer loop that ensures it iterates over each texture.

I did find what i think is the problem: in GL_LoadTexture2 the servercount variable is set depending on the texture type:

if ( textureType == GLT_WORLD )
{
  slot->servercount = gHostSpawnCount;
}
else
{
  slot->servercount = 0;
}

And in GL_UnloadTextures:

if ( pTexture->servercount > 0 && pTexture->servercount != gHostSpawnCount )

All textures other than the world (map textures) are never unloaded. An easy fix is to always use gHostSpawnCount and let all textures unload, but then there's the risk of unloading textures that are only loaded once (e.g. Draw_PicFromWad).

GLT_SYSTEM and GLT_DECAL texture types definitely shouldn't be unloaded, it looks like all others are resources that are loaded once per map. Maybe allowing all of these to be unloaded is the safest bet:

  • GLT_STUDIO
  • GLT_WORLD
  • GLT_SPRITE

It looks like hud sprites are always GLT_HUDSPRITE so they should be safe.

@Solokiller IMHO, it looks like the issue is that the numgltextures global counter never decreases, and also textures potentially can be unloaded from the middle of the gltexture_t gltextures[4800] without shifting elements

@SamVanheer
Copy link

SamVanheer commented Nov 20, 2020

True, it doesn't seem to ever decrement that variable. However it does reuse texture slots that were unloaded so the error should only occur if all 4800 slots are in use at the same time. If the error occurs after a certain amount of time rather than when loading a particular map or other assets then it isn't clearing those slots correctly.

@Matiarguello
Copy link

three years later, without news, we also provide the code with the solution ... they just have to implement and test it.

@hajimura
Copy link

hajimura commented Aug 4, 2021

@MatiasEsf, because nobody cares more about this game

@lexzor
Copy link

lexzor commented May 30, 2022

@mikela-valve up?

@huihuangex
Copy link

anyone fix it?

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

No branches or pull requests