Commit bd0a86da authored by Christoffer Ackelman's avatar Christoffer Ackelman

QT: Fixed a segmentation fault that only occured if you auto-scrolled in one...

QT: Fixed a segmentation fault that only occured if you auto-scrolled in one direction for a very long time, it eventually messed up the stack.
parent 1423e127
...@@ -187,6 +187,7 @@ FlowDrawQt::FlowDrawQt(QWidget* x_toplevel, void** flow_ctx, ...@@ -187,6 +187,7 @@ FlowDrawQt::FlowDrawQt(QWidget* x_toplevel, void** flow_ctx,
: toplevel(x_toplevel), closing_down(0) : toplevel(x_toplevel), closing_down(0)
{ {
timer_id = new QTimer(this); timer_id = new QTimer(this);
draw_timer_id = new QTimer(this);
if (type == flow_eCtxType_Brow) { if (type == flow_eCtxType_Brow) {
ctx = (FlowCtx*)new BrowCtx("Claes context", 20); ctx = (FlowCtx*)new BrowCtx("Claes context", 20);
...@@ -1029,13 +1030,9 @@ void FlowDrawQt::set_window_size(DrawWind *wind, int width, int height) ...@@ -1029,13 +1030,9 @@ void FlowDrawQt::set_window_size(DrawWind *wind, int width, int height)
bool FlowDrawQt::draw_timer_cb() bool FlowDrawQt::draw_timer_cb()
{ {
FlowDrawQt* draw_ctx = (FlowDrawQt*)timer_cb->ctx->fdraw; draw_timer_id->stop();
(draw_timer_callback_func)(ctx);
(timer_cb->callback_func)(timer_cb->ctx); toplevel->update();
draw_ctx->toplevel->update();
delete timer_cb->timer_id;
delete timer_cb;
return FALSE; return FALSE;
} }
...@@ -1070,21 +1067,16 @@ void FlowDrawQt::event_timer(FlowCtx* ctx, QMouseEvent* event, QWidget *target) ...@@ -1070,21 +1067,16 @@ void FlowDrawQt::event_timer(FlowCtx* ctx, QMouseEvent* event, QWidget *target)
void FlowDrawQt::set_timer(FlowCtx* ctx, int time_ms, void FlowDrawQt::set_timer(FlowCtx* ctx, int time_ms,
void (*callback_func)(FlowCtx* ctx), void** id) void (*callback_func)(FlowCtx* ctx), void** id)
{ {
timer_cb = new flow_draw_sTimerCb(); draw_timer_callback_func = callback_func;
timer_cb->ctx = ctx; initOneShotTimer(draw_timer_id, SLOT(draw_timer_cb()), time_ms);
timer_cb->callback_func = callback_func; *id = (void*)draw_timer_id;
timer_cb->timer_id = new QTimer(this);
initOneShotTimer(timer_cb->timer_id, SLOT(draw_timer_cb()), time_ms);
*id = (void*)timer_cb;
} }
void FlowDrawQt::cancel_timer(void* id) void FlowDrawQt::cancel_timer(void* ctx)
{ {
delete (((flow_draw_sTimerCb*)id)->timer_id); if (draw_timer_id) {
draw_timer_id->stop();
delete ((char*)id); }
} }
void FlowDrawQt::set_cursor(DrawWind *wind, draw_eCursor cursor) void FlowDrawQt::set_cursor(DrawWind *wind, draw_eCursor cursor)
......
...@@ -52,12 +52,6 @@ public: ...@@ -52,12 +52,6 @@ public:
QImage* buffer = NULL; QImage* buffer = NULL;
}; };
typedef struct {
FlowCtx* ctx;
void (*callback_func)(FlowCtx* ctx);
QTimer* timer_id;
} flow_draw_sTimerCb;
class FlowDrawQt : private QObject, public FlowDraw { class FlowDrawQt : private QObject, public FlowDraw {
Q_OBJECT Q_OBJECT
...@@ -148,11 +142,12 @@ private: ...@@ -148,11 +142,12 @@ private:
void event_timer(FlowCtx* ctx, QMouseEvent *event, QWidget *target); void event_timer(FlowCtx* ctx, QMouseEvent *event, QWidget *target);
void cancel_event_timer(FlowCtx* ctx); void cancel_event_timer(FlowCtx* ctx);
flow_draw_sTimerCb* timer_cb; void (*draw_timer_callback_func)(FlowCtx* ctx);
QTimer* draw_timer_id;
public slots: public slots:
bool event_timer_cb(); bool event_timer_cb();
bool draw_timer_cb(); bool draw_timer_cb();
}; };
#endif #endif
\ No newline at end of file
...@@ -256,6 +256,7 @@ GlowDrawQt::GlowDrawQt(QWidget* toplevel, void** glow_ctx, ...@@ -256,6 +256,7 @@ GlowDrawQt::GlowDrawQt(QWidget* toplevel, void** glow_ctx,
: click_sensitivity(0), closing_down(0), customcolors_cnt(0) : click_sensitivity(0), closing_down(0), customcolors_cnt(0)
{ {
timer_id = new QTimer(this); timer_id = new QTimer(this);
draw_timer_id = new QTimer(this);
memset(customcolors, 0, sizeof(customcolors)); memset(customcolors, 0, sizeof(customcolors));
...@@ -1169,13 +1170,9 @@ void GlowDrawQt::set_window_size(DrawWind* wind, int width, int height) ...@@ -1169,13 +1170,9 @@ void GlowDrawQt::set_window_size(DrawWind* wind, int width, int height)
bool GlowDrawQt::draw_timer_cb() bool GlowDrawQt::draw_timer_cb()
{ {
GlowDrawQt* draw_ctx = (GlowDrawQt*)timer_cb->ctx->gdraw; draw_timer_id->stop();
(draw_timer_callback_func)(ctx);
(timer_cb->callback_func)(timer_cb->ctx); m_wind.window->update();
draw_ctx->m_wind.window->update();
delete timer_cb->timer_id;
delete timer_cb;
return FALSE; return FALSE;
} }
...@@ -1208,21 +1205,16 @@ void GlowDrawQt::event_timer(QMouseEvent* event, QWidget *target) ...@@ -1208,21 +1205,16 @@ void GlowDrawQt::event_timer(QMouseEvent* event, QWidget *target)
void GlowDrawQt::set_timer(GlowCtx* paintertx, int time_ms, void GlowDrawQt::set_timer(GlowCtx* paintertx, int time_ms,
void (*callback_func)(GlowCtx* ctx), void** id) void (*callback_func)(GlowCtx* ctx), void** id)
{ {
timer_cb = new glow_draw_sTimerCb(); draw_timer_callback_func = callback_func;
timer_cb->ctx = paintertx; initOneShotTimer(draw_timer_id, SLOT(draw_timer_cb()), time_ms);
timer_cb->callback_func = callback_func; *id = (void*)draw_timer_id;
timer_cb->timer_id = new QTimer(this);
initOneShotTimer(timer_cb->timer_id, SLOT(draw_timer_cb()), time_ms);
*id = (void*)timer_cb;
} }
void GlowDrawQt::remove_timer(void* id) void GlowDrawQt::remove_timer(void* id)
{ {
delete (((glow_draw_sTimerCb*)id)->timer_id); if (draw_timer_id) {
draw_timer_id->stop();
delete ((char*)id); }
} }
void GlowDrawQt::set_cursor(DrawWind* wind, glow_eDrawCursor cursor) void GlowDrawQt::set_cursor(DrawWind* wind, glow_eDrawCursor cursor)
......
...@@ -69,12 +69,6 @@ public: ...@@ -69,12 +69,6 @@ public:
QPixmap* background_pixmap = NULL; QPixmap* background_pixmap = NULL;
}; };
typedef struct {
GlowCtx* ctx;
void (*callback_func)(GlowCtx* ctx);
QTimer* timer_id;
} glow_draw_sTimerCb;
class GlowCustomColorsQt; class GlowCustomColorsQt;
class GlowDrawQt : private QObject, public GlowDraw { class GlowDrawQt : private QObject, public GlowDraw {
...@@ -196,7 +190,8 @@ private: ...@@ -196,7 +190,8 @@ private:
void event_timer(QMouseEvent *event, QWidget *target); void event_timer(QMouseEvent *event, QWidget *target);
void cancel_event_timer(); void cancel_event_timer();
glow_draw_sTimerCb* timer_cb; void (*draw_timer_callback_func)(GlowCtx* ctx);
QTimer* draw_timer_id;
public slots: public slots:
bool event_timer_cb(); bool event_timer_cb();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment