diff --git a/stepmania/src/RageDisplay_D3D.cpp b/stepmania/src/RageDisplay_D3D.cpp index c2bd1557a4..a907734479 100644 --- a/stepmania/src/RageDisplay_D3D.cpp +++ b/stepmania/src/RageDisplay_D3D.cpp @@ -24,6 +24,7 @@ #include "archutils/Win32/GraphicsWindow.h" #else #include "archutils/Xbox/GraphicsWindow.h" +#include "archutils/Xbox/VirtualMemory.h" #endif #include "ScreenDimensions.h" @@ -1204,6 +1205,16 @@ unsigned RageDisplay_D3D::CreateTexture( HRESULT hr; IDirect3DTexture8* pTex; hr = g_pd3dDevice->CreateTexture( img->w, img->h, 1, 0, D3DFORMATS[pixfmt], D3DPOOL_MANAGED, &pTex ); + +#if defined(XBOX) + while(hr == E_OUTOFMEMORY) + { + if(!vmem_Manager.DecommitLRU()) + break; + hr = g_pd3dDevice->CreateTexture( img->w, img->h, 1, 0, D3DFORMATS[pixfmt], D3DPOOL_MANAGED, &pTex ); + } +#endif + if( FAILED(hr) ) RageException::Throw( "CreateTexture(%i,%i,pixfmt=%i) failed: %s", img->w, img->h, pixfmt, GetErrorString(hr).c_str() ); diff --git a/stepmania/src/RageSound.cpp b/stepmania/src/RageSound.cpp index 9d3b8e4745..44a876024b 100644 --- a/stepmania/src/RageSound.cpp +++ b/stepmania/src/RageSound.cpp @@ -34,6 +34,10 @@ #include "RageSoundReader_Resample.h" #include "RageSoundReader_FileReader.h" +#if defined(XBOX) +#include "archutils/Xbox/VirtualMemory.h" +#endif + const int channels = 2; const int framesize = 2 * channels; /* 16-bit */ #define samplerate() Sample->GetSampleRate() @@ -350,6 +354,11 @@ int RageSound::FillBuf( int frames ) * that would be read. */ int RageSound::GetData( char *buffer, int frames ) { +#if defined(XBOX) + // should prevent a page fault crash + vmem_Manager.Lock(buffer); +#endif + if( m_Param.m_LengthSeconds != -1 ) { /* We have a length; only read up to the end. */ @@ -378,6 +387,10 @@ int RageSound::GetData( char *buffer, int frames ) databuf.read( buffer, got*framesize ); } +#if defined(XBOX) + vmem_Manager.Unlock(buffer); +#endif + return got; } diff --git a/stepmania/src/RageSoundManager.cpp b/stepmania/src/RageSoundManager.cpp index 9b1576ee5f..eddea2c1dd 100644 --- a/stepmania/src/RageSoundManager.cpp +++ b/stepmania/src/RageSoundManager.cpp @@ -12,6 +12,10 @@ #include "arch/arch.h" #include "arch/Sound/RageSoundDriver.h" +#if defined(XBOX) +#include "archutils/Xbox/VirtualMemory.h" +#endif + /* * This mutex is locked before Update() deletes old sounds from owned_sounds. Lock * this mutex if you want to ensure that sounds remain valid. (Other threads may @@ -217,6 +221,10 @@ RageSound *RageSoundManager::PlaySound( RageSound &snd, const RageSoundParams *p else { sound_to_play = new RageSound(snd); +#if defined(XBOX) + // keep the sound data committed to memory + vmem_Manager.Lock(sound_to_play); +#endif /* We're responsible for freeing it. */ g_SoundManMutex.Lock(); /* lock for access to owned_sounds */ diff --git a/stepmania/src/RageSurface_Load_PNG.cpp b/stepmania/src/RageSurface_Load_PNG.cpp index 0216237ca7..ade5fc6e73 100644 --- a/stepmania/src/RageSurface_Load_PNG.cpp +++ b/stepmania/src/RageSurface_Load_PNG.cpp @@ -17,6 +17,8 @@ #if defined(_XBOX) # include // for alloca +# include "archutils/Xbox/VirtualMemory.h" +# define PNG_USER_MEM_SUPPORTED #elif !defined(WIN32) # include #endif @@ -89,6 +91,17 @@ static RageSurface *RageSurface_Load_PNG( RageFile *f, const char *fn, char erro error.fn = fn; png_struct *png = png_create_read_struct( PNG_LIBPNG_VER_STRING, &error, PNG_Error, PNG_Warning ); + +#if defined(XBOX) + while(png == NULL) + { + if(!vmem_Manager.DecommitLRU()) + break; + + png = png_create_read_struct( PNG_LIBPNG_VER_STRING, &error, PNG_Error, PNG_Warning ); + } +#endif + if( png == NULL ) { sprintf( errorbuf, "creating png_create_read_struct failed");