app/undo.c app/gimage.h added a simple ref count to the guides so that

1998-03-11  Larry Ewing  <lewing@discord.isc.tamu.edu>

	* app/undo.c
	* app/gimage.h
	* app/gimage.c: added a simple ref count to the guides so that
	undo does not free the too early...
This commit is contained in:
Larry Ewing 1998-03-11 06:38:32 +00:00 committed by Larry Ewing
parent 16aacc47a8
commit bd8f7a1a9a
4 changed files with 17 additions and 4 deletions

View File

@ -1974,6 +1974,7 @@ undo_push_guide (GImage *gimage,
if ((new = undo_push (gimage, size, GIMAGE_MOD)))
{
((Guide *)(guide))->ref_count++;
data = g_new (GuideUndo, 1);
new->data = data;
new->pop_func = undo_pop_guide;
@ -1998,14 +1999,17 @@ undo_pop_guide (GImage *gimage,
{
GuideUndo *data;
Guide tmp;
int tmp_ref;
data = data_ptr;
gdisplays_expose_guide (gimage->ID, data->guide);
gdisplays_expose_guide (gimage->ID, &data->orig);
tmp_ref = data->guide->ref_count;
tmp = *(data->guide);
*(data->guide) = data->orig;
data->guide->ref_count = tmp_ref;
data->orig = tmp;
switch (state)
@ -2030,8 +2034,9 @@ undo_free_guide (int state,
data = data_ptr;
if (data->guide->position < 0)
gimage_delete_guide (data->gimage, data->guide);
data->guide->ref_count--;
if (data->guide->position < 0 && data->guide->ref_count <= 0)
gimage_delete_guide (data->gimage, data->guide);
g_free (data_ptr);
}

View File

@ -825,6 +825,7 @@ gimage_add_hguide (GImage *gimage)
Guide *guide;
guide = g_new (Guide, 1);
guide->ref_count = 0;
guide->position = -1;
guide->orientation = HORIZONTAL_GUIDE;
@ -839,6 +840,7 @@ gimage_add_vguide (GImage *gimage)
Guide *guide;
guide = g_new (Guide, 1);
guide->ref_count = 0;
guide->position = -1;
guide->orientation = VERTICAL_GUIDE;

View File

@ -87,6 +87,7 @@ typedef struct _GImage GImage;
struct _Guide
{
int ref_count;
int position;
int orientation;
};

View File

@ -1974,6 +1974,7 @@ undo_push_guide (GImage *gimage,
if ((new = undo_push (gimage, size, GIMAGE_MOD)))
{
((Guide *)(guide))->ref_count++;
data = g_new (GuideUndo, 1);
new->data = data;
new->pop_func = undo_pop_guide;
@ -1998,14 +1999,17 @@ undo_pop_guide (GImage *gimage,
{
GuideUndo *data;
Guide tmp;
int tmp_ref;
data = data_ptr;
gdisplays_expose_guide (gimage->ID, data->guide);
gdisplays_expose_guide (gimage->ID, &data->orig);
tmp_ref = data->guide->ref_count;
tmp = *(data->guide);
*(data->guide) = data->orig;
data->guide->ref_count = tmp_ref;
data->orig = tmp;
switch (state)
@ -2030,8 +2034,9 @@ undo_free_guide (int state,
data = data_ptr;
if (data->guide->position < 0)
gimage_delete_guide (data->gimage, data->guide);
data->guide->ref_count--;
if (data->guide->position < 0 && data->guide->ref_count <= 0)
gimage_delete_guide (data->gimage, data->guide);
g_free (data_ptr);
}