Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/src/editmode_undo.c')
-rw-r--r--source/blender/src/editmode_undo.c40
1 files changed, 32 insertions, 8 deletions
diff --git a/source/blender/src/editmode_undo.c b/source/blender/src/editmode_undo.c
index d0a44360ad5..7893dac2408 100644
--- a/source/blender/src/editmode_undo.c
+++ b/source/blender/src/editmode_undo.c
@@ -107,6 +107,7 @@ typedef struct UndoElem {
Object *ob; // pointer to edited object
int type; // type of edited object
void *undodata;
+ uintptr_t undosize;
char name[MAXUNDONAME];
void (*freedata)(void *);
void (*to_editmode)(void *);
@@ -138,6 +139,7 @@ void undo_editmode_push(char *name, void (*freedata)(void *),
{
UndoElem *uel;
int nr;
+ uintptr_t memused, totmem, maxmem;
/* at first here was code to prevent an "original" key to be insterted twice
this was giving conflicts for example when mesh changed due to keys or apply */
@@ -145,9 +147,8 @@ void undo_editmode_push(char *name, void (*freedata)(void *),
/* remove all undos after (also when curundo==NULL) */
while(undobase.last != curundo) {
uel= undobase.last;
- BLI_remlink(&undobase, uel);
uel->freedata(uel->undodata);
- MEM_freeN(uel);
+ BLI_freelinkN(&undobase, uel);
}
/* make new */
@@ -160,7 +161,7 @@ void undo_editmode_push(char *name, void (*freedata)(void *),
uel->from_editmode= from_editmode;
uel->validate_undo= validate_undo;
- /* and limit amount to the maximum */
+ /* limit amount to the maximum amount*/
nr= 0;
uel= undobase.last;
while(uel) {
@@ -171,19 +172,43 @@ void undo_editmode_push(char *name, void (*freedata)(void *),
if(uel) {
while(undobase.first!=uel) {
UndoElem *first= undobase.first;
- BLI_remlink(&undobase, first);
first->freedata(first->undodata);
- MEM_freeN(first);
+ BLI_freelinkN(&undobase, first);
}
}
/* copy */
+ memused= MEM_get_memory_in_use();
curundo->undodata= curundo->from_editmode();
+ curundo->undosize= MEM_get_memory_in_use() - memused;
curundo->ob= G.obedit;
curundo->id= G.obedit->id;
curundo->type= G.obedit->type;
-}
+ if(U.undomemory != 0) {
+ /* limit to maximum memory (afterwards, we can't know in advance) */
+ totmem= 0;
+ maxmem= ((uintptr_t)U.undomemory)*1024*1024;
+
+ uel= undobase.last;
+ while(uel && uel->prev) {
+ totmem+= uel->undosize;
+ if(totmem>maxmem) break;
+ uel= uel->prev;
+ }
+
+ if(uel) {
+ if(uel->prev && uel->prev->prev)
+ uel= uel->prev;
+
+ while(undobase.first!=uel) {
+ UndoElem *first= undobase.first;
+ first->freedata(first->undodata);
+ BLI_freelinkN(&undobase, first);
+ }
+ }
+ }
+}
/* helper to remove clean other objects from undo stack */
static void undo_clean_stack(void)
@@ -205,9 +230,8 @@ static void undo_clean_stack(void)
}
else {
mixed= 1;
- BLI_remlink(&undobase, uel);
uel->freedata(uel->undodata);
- MEM_freeN(uel);
+ BLI_freelinkN(&undobase, uel);
}
uel= next;