Fix/workaround at least one class of buffer underruns in the GL plugin. Fix some bad deletes (instead of delete []). etc.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@404 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
hrydgard 2008-08-31 13:36:52 +00:00
parent d9e129ae99
commit 09406d76c4
25 changed files with 117 additions and 69 deletions

View File

@ -60,7 +60,6 @@ bool CBoot::Boot_BIN(const std::string& _rFilename)
}
delete pFile;
return true;
}

View File

@ -186,9 +186,9 @@ void Stop() // - Hammertime!
#endif
delete g_pThread; //Wait for emuthread to close
g_pThread = 0;
Core::StopTrace();
LogManager::Shutdown();
g_pThread = 0;
Host_SetWaitCursor(false);
}
@ -360,6 +360,7 @@ THREAD_RETURN EmuThread(void *pArg)
if( g_pUpdateFPSDisplay != NULL )
g_pUpdateFPSDisplay("Stopping...");
delete cpuThread;
cpuThread = NULL;
// Returns after game exited
g_bHwInit = false;

View File

@ -106,6 +106,7 @@ CEXIMemoryCard::~CEXIMemoryCard()
{
Flush(true);
delete [] memory_card_content;
memory_card_content = NULL;
}
bool CEXIMemoryCard::IsPresent()

View File

@ -354,7 +354,7 @@ void CCodeView::OnPaint(wxPaintEvent& event)
wxBrush rowBrush(wxColor(col >> 16, col >> 8, col));
dc.SetBrush(nullBrush);
dc.SetPen(nullPen);
dc.DrawRectangle(0, rowY1, 16, rowY2);
dc.DrawRectangle(0, rowY1, 16, rowY2 - rowY1 + 2);
if (selecting && (address == selection))
{
@ -374,7 +374,7 @@ void CCodeView::OnPaint(wxPaintEvent& event)
dc.SetBrush(rowBrush);
}
dc.DrawRectangle(16, rowY1, width, rowY2 - 1);
dc.DrawRectangle(16, rowY1, width, rowY2 - rowY1 + 1);
dc.SetBrush(currentBrush);
dc.SetTextForeground(_T("#600000"));
dc.DrawText(temp, 17, rowY1);

View File

@ -55,7 +55,8 @@ CBannerLoaderGC::CBannerLoaderGC(DiscIO::IFileSystem& _rFileSystem)
CBannerLoaderGC::~CBannerLoaderGC()
{
delete[] m_pBannerFile;
delete [] m_pBannerFile;
m_pBannerFile = NULL;
}

View File

@ -70,7 +70,8 @@ CBannerLoaderWii::CBannerLoaderWii(DiscIO::IFileSystem& _rFileSystem)
CBannerLoaderWii::~CBannerLoaderWii()
{
delete m_pBuffer;
delete [] m_pBuffer;
m_pBuffer = NULL;
}

View File

@ -42,7 +42,7 @@ CARCFile::CARCFile(const u8* _pBuffer, size_t _BufferSize)
CARCFile::~CARCFile()
{
delete m_pBuffer;
delete [] m_pBuffer;
}

View File

@ -36,7 +36,9 @@ CVolumeWiiCrypted::CVolumeWiiCrypted(IBlobReader* _pReader, u64 _VolumeOffset, c
CVolumeWiiCrypted::~CVolumeWiiCrypted()
{
delete m_pReader; // is this really our responsibility?
m_pReader = NULL;
delete[] m_pBuffer;
m_pBuffer = NULL;
}

View File

@ -39,8 +39,14 @@ CMemcardManager::CMemcardManager(wxWindow* parent, wxWindowID id, const wxString
CMemcardManager::~CMemcardManager()
{
if(memoryCard[0]) delete memoryCard[0];
if(memoryCard[1]) delete memoryCard[1];
if (memoryCard[0]) {
delete memoryCard[0];
memoryCard[0] = NULL;
}
if (memoryCard[1]) {
delete memoryCard[1];
memoryCard[1] = NULL;
}
}
void CMemcardManager::CreateGUIControls()

View File

@ -117,8 +117,8 @@ bool GCMemcard::RemoveFile(u32 index) //index in the directory array
bat.LastAllocated[0] = u8(firstFree>>8);
bat.LastAllocated[1] = u8(firstFree);
delete mc_data;
mc_data=mc_data2;
delete [] mc_data;
mc_data = mc_data2;
//--
//update freespace counter
@ -366,7 +366,7 @@ u32 GCMemcard::CopyFrom(GCMemcard& source, u32 index)
if(!source.GetFileData(index,t)) return 0;
u32 ret = ImportFile(d,t);
delete t;
delete[] t;
return ret;
}

View File

@ -78,6 +78,11 @@ u8 FAKE_ReadFifo8()
return videoBuffer[readptr++];
}
int FAKE_GetPosition()
{
return readptr;
}
u16 FAKE_ReadFifo16()
{
u16 val = Common::swap16(*(u16*)(videoBuffer+readptr));

View File

@ -43,7 +43,7 @@ void Mixer(short *buffer, int numSamples, int bits, int rate, int channels)
// silence
memset(buffer, 0, numSamples * 2 * sizeof(short));
// first get th DTK Music
// first get the DTK Music
if (g_Config.m_EnableDTKMusic)
{
g_dspInitialize.pGetAudioStreaming(buffer, numSamples);

View File

@ -111,6 +111,7 @@ CReBarSettings::~CReBarSettings()
if (m_pBands != NULL)
{
delete[] m_pBands;
m_pBands = NULL;
}
}
@ -120,6 +121,7 @@ bool CReBarSettings::Load(LPCTSTR szRegKey, LPCTSTR szPrefix, HKEY hkRootKey /*
if (m_pBands != NULL)
{
delete[] m_pBands;
m_pBands = NULL;
}
m_pBands = NULL;

View File

@ -22,13 +22,13 @@ void DecodedVArray::Zero()
posMtxInds = 0;
for (int i=0; i<3; i++)
normals[i] = 0;
for (int i=0; i<2; i++)
colors[i] = 0;
for (int i=0; i<8; i++)
{
texMtxInds[i] = 0;
uvs[i] = 0;
}
for (int i=0; i<2; i++)
colors[i] = 0;
}
void DecodedVArray::Destroy()

View File

@ -97,9 +97,9 @@ bool FifoCommandRunnable(void)
{
u32 iBufferSize = FAKE_GetFifoSize();
if (iBufferSize == 0)
return false;
return false; // can't peek
u8 Cmd = PeekFifo8(0);
u8 Cmd = PeekFifo8(0);
u32 iCommandSize = 0;
switch(Cmd)
@ -362,12 +362,6 @@ void OpcodeDecoder_Shutdown()
void OpcodeDecoder_Run()
{
// just a small check
if (g_pDataReader != &g_fifoReader)
{
MessageBox(NULL, "very strange", "video-plugin", MB_OK);
}
DVSTARTPROFILE();
while (FifoCommandRunnable())

View File

@ -51,12 +51,7 @@ void VertexLoader::SetVArray(DecodedVArray *_varray)
{
varray = _varray;
}
/*
inline u8 ReadBuffer8() { return fifo.Read8(); }
inline u16 ReadBuffer16() { return fifo.Read16(); }
inline u32 ReadBuffer32() { return fifo.Read32(); }
inline float ReadBuffer32F() { return fifo.Read32F(); }
*/
inline u8 ReadBuffer8()
{
return g_pDataReader->Read8();
@ -120,7 +115,7 @@ void VertexLoader::Setup()
{
m_PipelineStates[m_numPipelineStates++] = PosMtx_ReadDirect_UByte;
m_VertexSize += 1;
m_components |= VB_HAS_POSMTXIDX;
m_components |= VB_HAS_POSMTXIDX;
}
// Texture matrix indices
@ -195,7 +190,7 @@ void VertexLoader::Setup()
}
WriteCall(pFunc);
m_VertexSize += uSize;
int m_numNormals = (m_VtxAttr.NormalElements==1) ? NRM_THREE : NRM_ONE;
int m_numNormals = (m_VtxAttr.NormalElements == 1) ? NRM_THREE : NRM_ONE;
m_components |= VB_HAS_NRM0;
if (m_numNormals == NRM_THREE)
m_components |= VB_HAS_NRM1 | VB_HAS_NRM2;

View File

@ -135,7 +135,7 @@ public:
void SetVAT_group0(u32 _group0)
{
if (!m_AttrDirty && m_group0.Hex == _group0)
if (m_group0.Hex == _group0)
return;
m_AttrDirty = true;
m_group0.Hex = _group0;

View File

@ -59,6 +59,7 @@ void _SetCol565(u16 val)
col |= lut5to8[(val )&0x1f] << BSHIFT;
_SetCol(col | (0xFF<<ASHIFT));
}
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
inline u32 _Read24(u32 iAddress)
@ -112,7 +113,7 @@ void LOADERDECL Color_ReadDirect_24b_6666(void* _p)
_SetCol6666(val);
}
// F|RES: i am not 100 percent show, but the colElements seems to be important for rendering only
// F|RES: i am not 100 percent sure, but the colElements seems to be important for rendering only
// at least it fixes mario party 4
//
// if (colElements[colIndex])
@ -128,7 +129,7 @@ void LOADERDECL Color_ReadDirect_32b_8888(void* _p)
// "kill" the alpha
if (!colElements[colIndex])
col |= 0xFF<<ASHIFT;
col |= 0xFF << ASHIFT;
_SetCol(col);
}

View File

@ -26,6 +26,7 @@ IDataReader* g_pDataReader = NULL;
extern u8 FAKE_ReadFifo8();
extern u16 FAKE_ReadFifo16();
extern u32 FAKE_ReadFifo32();
extern int FAKE_GetPosition();
extern void FAKE_SkipFifo(u32 skip);
CDataReader_Fifo::CDataReader_Fifo(void)
@ -53,6 +54,12 @@ void CDataReader_Fifo::Skip(u32 skip)
return FAKE_SkipFifo(skip);
}
int CDataReader_Fifo::GetPosition()
{
return FAKE_GetPosition();
}
// =================================================================================================
// CDataReader_Memory
// =================================================================================================
@ -64,26 +71,31 @@ CDataReader_Memory::CDataReader_Memory(u32 _uAddress) :
m_szName = "CDataReader_Memory";
}
u32 CDataReader_Memory::GetReadAddress(void)
u32 CDataReader_Memory::GetReadAddress()
{
return m_uReadAddress;
}
u8 CDataReader_Memory::Read8(void)
int CDataReader_Memory::GetPosition()
{
return m_uReadAddress;
}
u8 CDataReader_Memory::Read8()
{
u8 tmp = Memory_Read_U8(m_uReadAddress);//m_pMemory[m_uReadAddress];
m_uReadAddress++;
return tmp;
}
u16 CDataReader_Memory::Read16(void)
u16 CDataReader_Memory::Read16()
{
u16 tmp = Memory_Read_U16(m_uReadAddress);//_byteswap_ushort(*(u16*)&m_pMemory[m_uReadAddress]);
m_uReadAddress += 2;
return tmp;
}
u32 CDataReader_Memory::Read32(void)
u32 CDataReader_Memory::Read32()
{
u32 tmp = Memory_Read_U32(m_uReadAddress);//_byteswap_ulong(*(u32*)&m_pMemory[m_uReadAddress]);
m_uReadAddress += 4;

View File

@ -29,9 +29,11 @@ protected:
public:
virtual void Skip(u32) = 0;
virtual u8 Read8 (void) = 0;
virtual u16 Read16(void) = 0;
virtual u32 Read32(void) = 0;
virtual u8 Read8 () = 0;
virtual u16 Read16() = 0;
virtual u32 Read32() = 0;
virtual int GetPosition() = 0; // return values can be anything, as long as relative distances are correct
};
// =================================================================================================
@ -43,12 +45,13 @@ class CDataReader_Fifo : public IDataReader
private:
public:
CDataReader_Fifo(void);
CDataReader_Fifo();
virtual void Skip(u32);
virtual u8 Read8(void);
virtual u16 Read16(void);
virtual u32 Read32(void);
virtual u8 Read8();
virtual u16 Read16();
virtual u32 Read32();
virtual int GetPosition();
};
// =================================================================================================
@ -66,12 +69,13 @@ public:
CDataReader_Memory(u32 _uAddress);
u32 GetReadAddress(void);
u32 GetReadAddress();
virtual void Skip(u32);
virtual u8 Read8(void);
virtual u16 Read16(void);
virtual u32 Read32(void);
virtual u8 Read8();
virtual u16 Read16();
virtual u32 Read32();
virtual int GetPosition();
};
extern IDataReader* g_pDataReader;

View File

@ -269,8 +269,8 @@ void Decode(void)
// draw primitives
default:
if (Cmd&0x80)
{
// load vertices
{
// load vertices (use computed vertex size from FifoCommandRunnable above)
u16 numVertices = g_pDataReader->Read16();
if (numVertices > 0) {
g_VertexLoaders[Cmd & GX_VAT_MASK].RunVertices((Cmd & GX_PRIMITIVE_MASK) >> GX_PRIMITIVE_SHIFT, numVertices);
@ -301,11 +301,6 @@ void OpcodeDecoder_Shutdown()
void OpcodeDecoder_Run()
{
// just a small check
if (g_pDataReader != &g_fifoReader) {
SysMessage("very strange");
}
DVSTARTPROFILE();
while (FifoCommandRunnable())

View File

@ -43,7 +43,7 @@ class PixelShaderMngr
memset(values, 0, (4+32+6+11) * 4);
tevstages = indstages = 0;
}
~PIXELSHADERUID() { delete[] values; }
~PIXELSHADERUID() { delete[] values; values = NULL;}
PIXELSHADERUID(const PIXELSHADERUID& r)
{
values = new u32[4+32+6+11];

View File

@ -19,8 +19,10 @@
#include <fstream>
#include <assert.h>
#include "Common.h"
#include "x64Emitter.h"
#include "Profiler.h"
#include "StringUtil.h"
#include "Render.h"
#include "VertexLoader.h"
@ -82,6 +84,12 @@ inline float ReadBuffer32F()
return *(float*)(&temp);
}
inline int GetBufferPosition()
{
return g_pDataReader->GetPosition();
}
// ==============================================================================
// Direct
// ==============================================================================
@ -143,7 +151,7 @@ VertexLoader::VertexLoader()
{
m_numPipelineStates = 0;
m_VertexSize = 0;
m_AttrDirty = 2;
m_AttrDirty = 1;
VertexLoader_Normal::Init();
m_compiledCode = (u8 *)AllocateExecutableMemory(COMPILED_CODE_SIZE, false);
@ -159,8 +167,7 @@ VertexLoader::~VertexLoader()
int VertexLoader::ComputeVertexSize()
{
if (m_AttrDirty < 2) {
if (!m_AttrDirty) {
if (m_VtxDesc.Hex0 == VertexManager::GetVtxDesc().Hex0 && (m_VtxDesc.Hex1&1)==(VertexManager::GetVtxDesc().Hex1&1))
return m_VertexSize;
@ -212,6 +219,7 @@ int VertexLoader::ComputeVertexSize()
break;
}
VertexLoader_Normal::index3 = m_VtxAttr.NormalIndex3;
if (m_VtxDesc.Normal != NOT_PRESENT)
m_VertexSize += VertexLoader_Normal::GetSize(m_VtxDesc.Normal, m_VtxAttr.NormalFormat, m_VtxAttr.NormalElements);
@ -297,7 +305,7 @@ void VertexLoader::ProcessFormat()
//_assert_( VertexManager::s_pCurBufferPointer == s_pBaseBufferPointer );
if (!m_AttrDirty ) {
if (!m_AttrDirty) {
if (m_VtxDesc.Hex0 == VertexManager::GetVtxDesc().Hex0 && (m_VtxDesc.Hex1&1)==(VertexManager::GetVtxDesc().Hex1&1))
// same
@ -410,7 +418,7 @@ void VertexLoader::ProcessFormat()
// Colors
int col[2] = {m_VtxDesc.Color0, m_VtxDesc.Color1};
for (int i = 0; i < 2; i++) {
SetupColor(i,col[i], m_VtxAttr.color[i].Comp, m_VtxAttr.color[i].Elements);
SetupColor(i, col[i], m_VtxAttr.color[i].Comp, m_VtxAttr.color[i].Elements);
if (col[i] != NOT_PRESENT )
m_VBVertexStride+=4;
@ -504,8 +512,8 @@ void VertexLoader::ProcessFormat()
case FORMAT_FLOAT:
CallCdeclFunction3_I(glNormalPointer, GL_FLOAT, m_VBVertexStride, offset); offset += 12;
if (m_VtxAttr.NormalElements) {
CallCdeclFunction6((void *)glVertexAttribPointer, SHADER_NORM1_ATTRIB,3,GL_FLOAT, GL_TRUE, m_VBVertexStride, offset); offset += 12;
CallCdeclFunction6((void *)glVertexAttribPointer, SHADER_NORM2_ATTRIB,3,GL_FLOAT, GL_TRUE, m_VBVertexStride, offset); offset += 12;
CallCdeclFunction6((void *)glVertexAttribPointer, SHADER_NORM1_ATTRIB, 3, GL_FLOAT, GL_TRUE, m_VBVertexStride, offset); offset += 12;
CallCdeclFunction6((void *)glVertexAttribPointer, SHADER_NORM2_ATTRIB, 3, GL_FLOAT, GL_TRUE, m_VBVertexStride, offset); offset += 12;
}
break;
default: _assert_(0); break;
@ -513,7 +521,7 @@ void VertexLoader::ProcessFormat()
}
for (int i = 0; i < 2; i++) {
if (col[i] != NOT_PRESENT ) {
if (col[i] != NOT_PRESENT) {
if (i)
CallCdeclFunction4((void *)glSecondaryColorPointer, 4, GL_UNSIGNED_BYTE, m_VBVertexStride, offset);
else
@ -570,7 +578,7 @@ void VertexLoader::ProcessFormat()
_assert_(offset+m_VBStridePad == m_VBVertexStride);
Util::EmitEpilogue(6);
if (Gen::GetCodePtr()-(u8*)m_compiledCode > COMPILED_CODE_SIZE)
if (Gen::GetCodePtr() - (u8*)m_compiledCode > COMPILED_CODE_SIZE)
{
assert(0);
Crash();
@ -689,12 +697,14 @@ void VertexLoader::SetupTexCoord(int num, int mode, int format, int elements, in
void VertexLoader::WriteCall(void (LOADERDECL *func)(void *))
{
m_PipelineStates[m_numPipelineStates++] = func;;
m_PipelineStates[m_numPipelineStates++] = func;
}
void VertexLoader::RunVertices(int primitive, int count)
{
if( count <= 0 )
ComputeVertexSize();
if( count <= 0 )
return;
if( fnSetupVertexPointers != NULL && fnSetupVertexPointers != (void (*)())(void*)m_compiledCode )
@ -833,6 +843,7 @@ void VertexLoader::RunVertices(int primitive, int count)
break;
default:
extraverts = 0;
break;
}
startv = v;
@ -842,8 +853,22 @@ void VertexLoader::RunVertices(int primitive, int count)
tcIndex = 0;
colIndex = 0;
s_texmtxwrite = s_texmtxread = 0;
int pred_size = m_VertexSize;
//int start = GetBufferPosition();
//if (!m_numPipelineStates)
// PanicAlert("trying to draw with no pipeline");
for (int i = 0; i < m_numPipelineStates; i++)
m_PipelineStates[i](&m_VtxAttr);
//int end = GetBufferPosition();
//if (end - start != pred_size) {
// std::string vtx_summary;
// vtx_summary += StringFromFormat("Nrm d:%i f:%i e:%i 3:%i", m_VtxDesc.Normal, m_VtxAttr.NormalFormat, m_VtxAttr.NormalElements, m_VtxAttr.NormalIndex3);
// PanicAlert((vtx_summary + "\nWTF %i %i").c_str(), end - start, pred_size);
//}
VertexManager::s_pCurBufferPointer += m_VBStridePad;
PRIM_LOG("\n");
}

View File

@ -224,5 +224,6 @@ u8 ReadBuffer8();
u16 ReadBuffer16();
u32 ReadBuffer32();
float ReadBuffer32F();
int GetBufferPosition();
#endif

View File

@ -106,7 +106,10 @@ void VertexLoader_Normal::Init(void)
unsigned int VertexLoader_Normal::GetSize(unsigned int _type, unsigned int _format, unsigned int _elements)
{
return m_sizeTable[_type][_format][_elements];
if (!index3 && _elements == NRM_NBT3)
return m_sizeTable[_type][_format][_elements] / 3;
else
return m_sizeTable[_type][_format][_elements];
}
TPipelineFunction VertexLoader_Normal::GetFunction(unsigned int _type, unsigned int _format, unsigned int _elements)