>       Not sure offhand, but I'd say try printing the value of 'this'
>       within your RefreshPlayerList() method, to see if it's different
>       when calling from the button callback vs. refresh_callback..
>       if the values are different, that might be the reason.
>
>       If that's not it, it would be best if you can write a short
>       simple standalone 'compilable' program that demonstrates the
>       problem, as it's hard to tell with a code snippet.

You are right, the value of 'this' is different.
Somehow i think add_timeout corrupts the pointer...

If have written a working example (VS 2005 Express)
_____________________________________________________________

#include <fltk/run.h>
#include <fltk/Window.h>
#include <fltk/Button.h>
#include <fltk/IntInput.h>
#include <fltk/Output.h>
#include <fltk/Browser.h>
#include <cstdlib>

using namespace fltk;


class ObserverWindow : public Window {
        Button start_button;
        Browser browser_playerlist;

        inline void refresh_callback_i() {
                        RefreshPlayerList();
                        
fltk::add_timeout(1.0,(fltk::TimeoutHandler)refresh_callback,this);
        }

        static void refresh_callback(Widget*, void* v) {
                ((ObserverWindow*)v)->refresh_callback_i(); //bad pointer :(
        }

        inline void start_callback_i() {
                RefreshPlayerList();
                
fltk::add_timeout(1.0,(fltk::TimeoutHandler)refresh_callback,this); //still 
good pointer
        }
        static void start_callback(Widget*, void* v) {
                ((ObserverWindow*)v)->start_callback_i(); //good pointer
        }
public:

        ObserverWindow(const char* label=0) :
                Window(USEDEFAULT,USEDEFAULT,550,500,label,true),
                start_button(160,180,40,20,"start"),
                browser_playerlist(160, 60, 300, 100, "Player:") {
                        start_button.callback(start_callback,this);
                        end();
                }
                ~ObserverWindow() {}

                void RefreshPlayerList() {
                        browser_playerlist.remove_all();
                        browser_playerlist.redraw();
                        browser_playerlist.add("test",0,0,0,0);
                }
};

int main(int argc, char ** argv) {
        ObserverWindow wnd("crash_test");
        wnd.show(argc,argv);
        return run();
}

_____________________________________________________________

I hope someone can tell me how i can fix this ? :)
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to