Ignore:
Timestamp:
Oct 7, 2012, 2:34:59 PM (9 years ago)
Author:
sam
Message:

core: disable our rare uses of realloc() with a proper Array<> object.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/map.cpp

    r1513 r1985  
    3939    int ntilers;
    4040
    41     Layer **layers;
    42     int nlayers;
     41    Array<Layer *> m_layers;
    4342
    4443    int width, height;
     
    5352{
    5453    data->ntilers = 0;
    55     data->layers = NULL;
    56     data->nlayers = 0;
    5754    data->width = 0;
    5855    data->height = 0;
     
    121118                Layer *l = new Layer(data->width, data->height,
    122119                                     level, orientation, tiles);
    123                 data->layers[data->nlayers] = l;
    124                 data->nlayers++;
     120                data->m_layers.Push(l);
    125121                tiles = NULL;
    126122                //Log::Debug("new layer %ix%i\n", data->width, data->height);
     
    144140        {
    145141            /* This is a layer description. Prepare to read the data. */
    146             data->layers = (Layer **)realloc(data->layers,
    147                                        sizeof(Layer **) * (data->nlayers + 1));
    148142            orientation = toupper(a) == 'V' ? 1 : 0;
    149143            level = i * 32;
     
    162156    for (int i = 0; i < data->ntilers; i++)
    163157        Tiler::Deregister(data->tilesets[i]);
    164     for (int i = 0; i < data->nlayers; i++)
    165         delete data->layers[i];
    166     free(data->layers);
     158    for (int i = 0; i < data->m_layers.Count(); i++)
     159        delete data->m_layers[i];
    167160    delete data;
    168161}
     
    170163void Map::Render(int x, int y, int z)
    171164{
    172     for (int i = 0; i < data->nlayers; i++)
    173         data->layers[i]->Render(x, y, z);
     165    for (int i = 0; i < data->m_layers.Count(); i++)
     166        data->m_layers[i]->Render(x, y, z);
    174167}
    175168
Note: See TracChangeset for help on using the changeset viewer.