Ignore:
Timestamp:
Jun 7, 2012, 4:14:56 PM (9 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.

File:
1 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)))
Note: See TracChangeset for help on using the changeset viewer.