diff options
Diffstat (limited to 'src/glibext')
-rw-r--r-- | src/glibext/gbuffercache.c | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/src/glibext/gbuffercache.c b/src/glibext/gbuffercache.c index fd7c987..f7dc49f 100644 --- a/src/glibext/gbuffercache.c +++ b/src/glibext/gbuffercache.c @@ -903,10 +903,15 @@ void g_buffer_cache_insert_at(GBufferCache *cache, size_t index, GLineGenerator cache->lines = (cache_info *)realloc(cache->lines, cache->count * sizeof(cache_info)); } } -#ifndef NDEBUG - else - assert(needed == 1); -#endif + + else if (needed > 1) + { + if ((cache->used + needed - 1) >= cache->count) + { + cache->count += needed - 1 + LINE_ALLOC_BULK; + cache->lines = (cache_info *)realloc(cache->lines, cache->count * sizeof(cache_info)); + } + } /* Insertion du générateur */ @@ -934,7 +939,23 @@ void g_buffer_cache_insert_at(GBufferCache *cache, size_t index, GLineGenerator g_width_tracker_update(cache->tracker, index); - g_signal_emit_by_name(cache, "size-changed", true, index, 1); + if (needed > 1) + { + /* On déborde sur les lignes suivantes, donc on crée de l'espace ! */ + + memmove(&cache->lines[index + 1], + &cache->lines[index + 1 + needed - 1], (cache->used - index - 1) * sizeof(cache_info)); + + for (i = 1; i < needed; i++) + init_cache_info(&cache->lines[index + i], generator, i, BLF_NONE); + + cache->used += needed - 1; + + g_width_tracker_update_added(cache->tracker, index + 1, needed - 1); + + } + + g_signal_emit_by_name(cache, "size-changed", true, index, needed - 1); } |