Fix (unreported) error on freeing timers which customdata pointer shall not be freed.
Looks like there was no way to avoid that so far, since WM_event_add_timer_notifier can set mere int-in-pointer there, this can cause issues. So added mere flags system to wmTimer to allow controlling this.
This commit is contained in:
@@ -508,6 +508,10 @@ typedef struct wmNDOFMotionData {
|
|||||||
} wmNDOFMotionData;
|
} wmNDOFMotionData;
|
||||||
#endif /* WITH_INPUT_NDOF */
|
#endif /* WITH_INPUT_NDOF */
|
||||||
|
|
||||||
|
typedef enum { /* Timer flags */
|
||||||
|
WM_TIMER_NO_FREE_CUSTOM_DATA = 1 << 0, /* Do not attempt to free customdata pointer even if non-NULL. */
|
||||||
|
} wmTimerFlags;
|
||||||
|
|
||||||
typedef struct wmTimer {
|
typedef struct wmTimer {
|
||||||
struct wmTimer *next, *prev;
|
struct wmTimer *next, *prev;
|
||||||
|
|
||||||
@@ -515,6 +519,7 @@ typedef struct wmTimer {
|
|||||||
|
|
||||||
double timestep; /* set by timer user */
|
double timestep; /* set by timer user */
|
||||||
int event_type; /* set by timer user, goes to event system */
|
int event_type; /* set by timer user, goes to event system */
|
||||||
|
wmTimerFlags flags; /* Various flags controlling timer options, see below. */
|
||||||
void *customdata; /* set by timer user, to allow custom values */
|
void *customdata; /* set by timer user, to allow custom values */
|
||||||
|
|
||||||
double duration; /* total running time in seconds */
|
double duration; /* total running time in seconds */
|
||||||
@@ -523,7 +528,7 @@ typedef struct wmTimer {
|
|||||||
double ltime; /* internal, last time timer was activated */
|
double ltime; /* internal, last time timer was activated */
|
||||||
double ntime; /* internal, next time we want to activate the timer */
|
double ntime; /* internal, next time we want to activate the timer */
|
||||||
double stime; /* internal, when the timer started */
|
double stime; /* internal, when the timer started */
|
||||||
int sleep; /* internal, put timers to sleep when needed */
|
bool sleep; /* internal, put timers to sleep when needed */
|
||||||
} wmTimer;
|
} wmTimer;
|
||||||
|
|
||||||
typedef struct wmOperatorType {
|
typedef struct wmOperatorType {
|
||||||
|
@@ -1466,6 +1466,7 @@ wmTimer *WM_event_add_timer_notifier(wmWindowManager *wm, wmWindow *win, unsigne
|
|||||||
wt->timestep = timestep;
|
wt->timestep = timestep;
|
||||||
wt->win = win;
|
wt->win = win;
|
||||||
wt->customdata = SET_UINT_IN_POINTER(type);
|
wt->customdata = SET_UINT_IN_POINTER(type);
|
||||||
|
wt->flags |= WM_TIMER_NO_FREE_CUSTOM_DATA;
|
||||||
|
|
||||||
BLI_addtail(&wm->timers, wt);
|
BLI_addtail(&wm->timers, wt);
|
||||||
|
|
||||||
@@ -1487,8 +1488,9 @@ void WM_event_remove_timer(wmWindowManager *wm, wmWindow *UNUSED(win), wmTimer *
|
|||||||
wm->reports.reporttimer = NULL;
|
wm->reports.reporttimer = NULL;
|
||||||
|
|
||||||
BLI_remlink(&wm->timers, wt);
|
BLI_remlink(&wm->timers, wt);
|
||||||
if (wt->customdata)
|
if (wt->customdata != NULL && (wt->flags & WM_TIMER_NO_FREE_CUSTOM_DATA) == 0) {
|
||||||
MEM_freeN(wt->customdata);
|
MEM_freeN(wt->customdata);
|
||||||
|
}
|
||||||
MEM_freeN(wt);
|
MEM_freeN(wt);
|
||||||
|
|
||||||
/* there might be events in queue with this timer as customdata */
|
/* there might be events in queue with this timer as customdata */
|
||||||
|
Reference in New Issue
Block a user