Changeset 1443


Ignore:
Timestamp:
Jun 7, 2012, 4:14:56 PM (8 years ago)
Author:
sam
Message:

gpu: silently ignore empty vertex and index buffers instead of crashing
and letting the user guess what happened. This doesn't prevent us from
displaying an additional friendly warning later.

Location:
trunk/src/gpu
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gpu/indexbuffer.cpp

    r1324 r1443  
    4242    friend class IndexBuffer;
    4343
     44    size_t m_size;
     45
    4446#if defined USE_D3D9
    4547    IDirect3DIndexBuffer9 *m_ibo;
     
    4951    GLuint m_ibo;
    5052    uint8_t *m_memory;
    51     size_t m_size;
    5253#endif
    5354};
     
    6162  : m_data(new IndexBufferData)
    6263{
     64    m_data->m_size = size;
     65    if (!size)
     66        return;
    6367#if defined USE_D3D9 || defined _XBOX
    6468    if (FAILED(g_d3ddevice->CreateIndexBuffer(size, D3DUSAGE_WRITEONLY,
     
    6973    glGenBuffers(1, &m_data->m_ibo);
    7074    m_data->m_memory = new uint8_t[size];
    71     m_data->m_size = size;
    7275#endif
    7376}
     
    7578IndexBuffer::~IndexBuffer()
    7679{
     80    if (m_data->m_size)
     81    {
    7782#if defined USE_D3D9 || defined _XBOX
    78     if (FAILED(m_data->m_ibo->Release()))
    79         Abort();
     83        if (FAILED(m_data->m_ibo->Release()))
     84            Abort();
    8085#elif !defined __CELLOS_LV2__ && !defined __ANDROID__
    81     glDeleteBuffers(1, &m_data->m_ibo);
    82     delete[] m_data->m_memory;
     86        glDeleteBuffers(1, &m_data->m_ibo);
     87        delete[] m_data->m_memory;
    8388#endif
     89    }
    8490    delete m_data;
    8591}
     
    8793void *IndexBuffer::Lock(size_t offset, size_t size)
    8894{
     95    if (!m_data->m_size)
     96        return NULL;
     97
    8998#if defined USE_D3D9 || defined _XBOX
    9099    void *ret;
     
    99108void IndexBuffer::Unlock()
    100109{
     110    if (!m_data->m_size)
     111        return;
     112
    101113#if defined USE_D3D9 || defined _XBOX
    102114    if (FAILED(m_data->m_ibo->Unlock()))
     
    111123void IndexBuffer::Bind()
    112124{
     125    if (!m_data->m_size)
     126        return;
     127
    113128#if defined USE_D3D9 || defined _XBOX
    114129    if (FAILED(g_d3ddevice->SetIndices(m_data->m_ibo)))
     
    124139void IndexBuffer::Unbind()
    125140{
     141    if (!m_data->m_size)
     142        return;
     143
    126144#if defined USE_D3D9 || defined _XBOX
    127145    if (FAILED(g_d3ddevice->SetIndices(NULL)))
  • trunk/src/gpu/vertexbuffer.cpp

    r1401 r1443  
    4343    friend class VertexDeclaration;
    4444
     45    size_t m_size;
     46
    4547#if defined USE_D3D9
    4648    IDirect3DVertexBuffer9 *m_vbo;
     
    5052    GLuint m_vbo;
    5153    uint8_t *m_memory;
    52     size_t m_size;
    5354#endif
    5455};
     
    123124void VertexDeclaration::DrawElements(MeshPrimitive type, int skip, int count)
    124125{
     126    if (count <= 0)
     127        return;
     128
    125129#if defined _XBOX || defined USE_D3D9
    126130    g_d3ddevice->SetRenderState(D3DRS_ALPHABLENDENABLE, 1);
     
    159163                                            int skip, int count)
    160164{
     165    if (count <= 0)
     166        return;
     167
    161168#if defined _XBOX || defined USE_D3D9
    162169    g_d3ddevice->SetRenderState(D3DRS_ALPHABLENDENABLE, 1);
     
    227234                                                    ShaderAttrib attr12)
    228235{
     236    if (!vb->m_data->m_size)
     237        return;
     238
    229239#if defined _XBOX || defined USE_D3D9
    230240    /* Only the first item is required to know which stream this
     
    470480  : m_data(new VertexBufferData)
    471481{
     482    m_data->m_size = size;
     483    if (!size)
     484        return;
    472485#if defined USE_D3D9 || defined _XBOX
    473486    if (FAILED(g_d3ddevice->CreateVertexBuffer(size, D3DUSAGE_WRITEONLY, NULL,
     
    477490    glGenBuffers(1, &m_data->m_vbo);
    478491    m_data->m_memory = new uint8_t[size];
    479     m_data->m_size = size;
    480492#endif
    481493}
     
    483495VertexBuffer::~VertexBuffer()
    484496{
     497    if (m_data->m_size)
     498    {
    485499#if defined USE_D3D9 || defined _XBOX
    486     if (FAILED(m_data->m_vbo->Release()))
    487         Abort();
     500        if (FAILED(m_data->m_vbo->Release()))
     501            Abort();
    488502#elif !defined __CELLOS_LV2__
    489     glDeleteBuffers(1, &m_data->m_vbo);
    490     delete[] m_data->m_memory;
    491 #endif
     503        glDeleteBuffers(1, &m_data->m_vbo);
     504        delete[] m_data->m_memory;
     505#endif
     506    }
    492507    delete m_data;
    493508}
     
    495510void *VertexBuffer::Lock(size_t offset, size_t size)
    496511{
     512    if (!m_data->m_size)
     513        return NULL;
    497514#if defined USE_D3D9 || defined _XBOX
    498515    void *ret;
     
    507524void VertexBuffer::Unlock()
    508525{
     526    if (!m_data->m_size)
     527        return;
    509528#if defined USE_D3D9 || defined _XBOX
    510529    if (FAILED(m_data->m_vbo->Unlock()))
Note: See TracChangeset for help on using the changeset viewer.