I have the following code in a header file.
What I would like is for the variable ‘mouse’ to exist as a global variable with the relevant methods and properties. However I get a crash and immediate exit at app launch. If I extern the var and init in a cpp I get the same problem. If I declare the variable as a property of testApp or any other class it works. I’m guessing it has something to do with ofAppEvents or ofMouseEvents?
This was working with 00573 (the zip theo posted in the ofxSimpleGUI post), but I updated everything from SVN and since then it doesnt work. Any ideas on if whether this is a bug or a ‘feature’? And why it was working but isn’t any more?
error message in console:
terminate called after throwing an instance of ‘Poco::SystemException’
what(): System exception
class ofxMouse : public ofMouseListener, public ofAppListener {
public:
int x, y; // current x, y
int px, py; // previous x, y
int vx, vy; // velocity x, y
bool button[MAX_MOUSE_BUTTONS]; // is the nth button down
ofxMouse() {
ofMouseEvents.addListener(this);
ofAppEvents.addListener(this);
for(int i=0; i<MAX_MOUSE_BUTTONS; i++) button[i] = false;
}
string toString() {
char sz[255];
sprintf(sz, "MOUSE Position: (%i, %i) | Previous: (%i, %i) | Velocity: (%i, %i) | Button1: %i | Button2: %i | Button3: %i \n", x, y, px, py, vx, vy, button[0], button[1], button[2] );
return string(sz);
}
//protected:
void update() {
vx = x - px;
vy = y - py;
}
void draw() {
px = x;
py = y;
}
void mouseMoved( int _x, int _y ) {
x = _x;
y = _y;
}
void mouseDragged( int _x, int _y, int _button ) {
x = _x;
y = _y;
}
void mousePressed( int _x, int _y, int _button ) {
x = _x;
y = _y;
button[_button] = true;
}
void mouseReleased() {
}
void mouseReleased(int _x, int _y, int _button ) {
x = _x;
y = _y;
button[_button] = false;
}
};
static ofxMouse mouse;