Skip to content

Commit

Permalink
Merge pull request #130 from z33ky/mb/scene.image-parse-fixes
Browse files Browse the repository at this point in the history
Fix scene loading memory errors
  • Loading branch information
Blixibon committed Jul 2, 2021
2 parents bb95574 + b41d49c commit 3709974
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions sp/src/game/server/sceneentity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3735,7 +3735,7 @@ CChoreoScene *CSceneEntity::LoadScene( const char *filename, IChoreoEventCallbac
Q_FixSlashes( loadfile );

// binary compiled vcd
void *pBuffer;
void *pBuffer = NULL;
#ifdef MAPBASE
//
// Raw scene file support
Expand All @@ -3760,12 +3760,13 @@ CChoreoScene *CSceneEntity::LoadScene( const char *filename, IChoreoEventCallbac
{
g_TokenProcessor.SetBuffer((char*)pBuffer);
pScene = ChoreoLoadScene( loadfile, NULL, &g_TokenProcessor, LocalScene_Printf );
g_TokenProcessor.SetBuffer(NULL);
}
// Okay, it's definitely missing.
else
{
MissingSceneWarning( loadfile );
return NULL;
pScene = NULL;
}

if (pScene)
Expand Down Expand Up @@ -4283,6 +4284,7 @@ CBaseEntity *CSceneEntity::FindNamedEntity( const char *name, CBaseEntity *pActo
#ifdef MAPBASE
const char *GetFirstSoundInScene(const char *pszScene)
{
const char *soundName;
SceneCachedData_t sceneData;
if ( scenefilecache->GetSceneCachedData( pszScene, &sceneData ) )
{
Expand All @@ -4292,30 +4294,35 @@ const char *GetFirstSoundInScene(const char *pszScene)
short stringId = scenefilecache->GetSceneCachedSound( sceneData.sceneId, 0 );

// Trust that it's been precached
return scenefilecache->GetSceneString( stringId );
soundName = scenefilecache->GetSceneString( stringId );
}
}
else
{
void *pBuffer = NULL;
if (filesystem->ReadFileEx( pszScene, "MOD", &pBuffer, false, true ))
if (filesystem->ReadFileEx( pszScene, "MOD", &pBuffer, true ))
{
g_TokenProcessor.SetBuffer((char*)pBuffer);
CChoreoScene *pScene = ChoreoLoadScene( pszScene, NULL, &g_TokenProcessor, LocalScene_Printf );
g_TokenProcessor.SetBuffer(NULL);
if (pScene)
{
for (int i = 0; i < pScene->GetNumEvents(); i++)
{
CChoreoEvent *pEvent = pScene->GetEvent(i);

if (pEvent->GetType() == CChoreoEvent::SPEAK)
return pEvent->GetParameters();
{
soundName = pEvent->GetParameters();
break;
}
}
}
}
FreeSceneFileMemory( pBuffer );
}

return NULL;
return soundName;
}

const char *GetFirstSoundInScene(CChoreoScene *scene)
Expand Down Expand Up @@ -4483,6 +4490,8 @@ bool CSceneEntity::ScriptLoadSceneFromString(const char* pszFilename, const char
PrecacheScene(pScene);
}

g_TokenProcessor.SetBuffer(NULL);

if (pScene != NULL)
{
// release prior scene if present
Expand Down Expand Up @@ -5284,12 +5293,12 @@ int GetSceneSpeechCount( char const *pszScene )
else
{
void *pBuffer = NULL;
if (filesystem->ReadFileEx( pszScene, "MOD", &pBuffer, false, true ))
int iNumSounds = 0;
if (filesystem->ReadFileEx( pszScene, "MOD", &pBuffer, true ))
{
int iNumSounds = 0;

g_TokenProcessor.SetBuffer((char*)pBuffer);
CChoreoScene *pScene = ChoreoLoadScene( pszScene, NULL, &g_TokenProcessor, LocalScene_Printf );
g_TokenProcessor.SetBuffer(NULL);
if (pScene)
{
for (int i = 0; i < pScene->GetNumEvents(); i++)
Expand All @@ -5300,9 +5309,11 @@ int GetSceneSpeechCount( char const *pszScene )
iNumSounds++;
}
}

return iNumSounds;
}

FreeSceneFileMemory( pBuffer );

return iNumSounds;
}
#endif
return 0;
Expand Down Expand Up @@ -5359,15 +5370,17 @@ void PrecacheInstancedScene( char const *pszScene )

// Attempt to precache manually
void *pBuffer = NULL;
if (filesystem->ReadFileEx( loadfile, "MOD", &pBuffer, false, true ))
if (filesystem->ReadFileEx( loadfile, "MOD", &pBuffer, true ))
{
g_TokenProcessor.SetBuffer((char*)pBuffer);
CChoreoScene *pScene = ChoreoLoadScene( loadfile, NULL, &g_TokenProcessor, LocalScene_Printf );
if (pScene)
{
PrecacheChoreoScene(pScene);
}
g_TokenProcessor.SetBuffer(NULL);
}
FreeSceneFileMemory( pBuffer );
#else
// Scenes are sloppy and don't always exist.
// A scene that is not in the pre-built cache image, but on disk, is a true error.
Expand Down

0 comments on commit 3709974

Please sign in to comment.