Fixed the following nasty bugs:

- memory corruption when mouse click happens because there are more than 3 possible values for mouse button click
- Recursive crash when outputting string representation of unitRef.
This commit is contained in:
Mark Vejvoda
2010-06-02 08:03:56 +00:00
parent ace1cef8a8
commit 8ebd901dfa
7 changed files with 96 additions and 24 deletions

View File

@@ -104,9 +104,9 @@ enum WindowStyle{
class Window {
private:
Uint32 lastMouseDown[3];
int lastMouseX[3];
int lastMouseY[3];
Uint32 lastMouseDown[mbCount];
int lastMouseX[mbCount];
int lastMouseY[mbCount];
static unsigned int lastMouseEvent; /** for use in mouse hover calculations */
static MouseState mouseState;

View File

@@ -53,7 +53,9 @@ bool Window::isActive = false;
// ========== PUBLIC ==========
Window::Window() {
memset(lastMouseDown, 0, sizeof(lastMouseDown));
for(int idx = 0; idx < mbCount; idx++) {
lastMouseDown[idx] = 0;
}
assert(global_window == 0);
global_window = this;
@@ -70,12 +72,17 @@ Window::~Window() {
}
bool Window::handleEvent() {
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
SDL_Event event;
SDL_GetMouseState(&oldX,&oldY);
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
while(SDL_PollEvent(&event)) {
try {
//printf("START [%d]\n",event.type);
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
switch(event.type) {
case SDL_MOUSEBUTTONDOWN:
@@ -88,6 +95,8 @@ bool Window::handleEvent() {
break;
}
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
switch(event.type) {
case SDL_QUIT:
//printf("In [%s::%s] Line :%d\n",__FILE__,__FUNCTION__,__LINE__);
@@ -224,9 +233,11 @@ bool Window::handleEvent() {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d] (b) Couldn't process event: [UNKNOWN ERROR]\n",__FILE__,__FUNCTION__,__LINE__);
}
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
//printf("END [%d]\n",event.type);
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
return true;
}
@@ -441,15 +452,18 @@ void Window::handleMouseDown(SDL_Event event) {
return;
}
Uint32 ticks = SDL_GetTicks();
int n = (int) button;
assert(n >= 0 && n < mbCount);
if(ticks - lastMouseDown[n] < DOUBLECLICKTIME
&& abs(lastMouseX[n] - event.button.x) < DOUBLECLICKDELTA
&& abs(lastMouseY[n] - event.button.y) < DOUBLECLICKDELTA) {
eventMouseDown(event.button.x, event.button.y, button);
eventMouseDoubleClick(event.button.x, event.button.y, button);
} else {
}
else {
eventMouseDown(event.button.x, event.button.y, button);
}
lastMouseDown[n] = ticks;

View File

@@ -265,12 +265,12 @@ void SystemFlags::handleDebug(DebugType type, const char *fmt, ...) {
printf("Opening logfile [%s] type = %d, currentDebugLog.fileStreamOwner = %d\n",debugLog.c_str(),type, currentDebugLog.fileStreamOwner);
currentDebugLog.mutex->p();
MutexSafeWrapper safeMutex(currentDebugLog.mutex);
(*currentDebugLog.fileStream) << "Starting Mega-Glest logging for type: " << type << "\n";
(*currentDebugLog.fileStream).flush();
currentDebugLog.mutex->v();
safeMutex.ReleaseLock();
}
//printf("Logfile is open [%s]\n",SystemFlags::debugLogFile);
@@ -279,12 +279,12 @@ void SystemFlags::handleDebug(DebugType type, const char *fmt, ...) {
assert(currentDebugLog.fileStream != NULL);
currentDebugLog.mutex->p();
MutexSafeWrapper safeMutex(currentDebugLog.mutex);
(*currentDebugLog.fileStream) << "[" << szBuf2 << "] " << szBuf;
(*currentDebugLog.fileStream).flush();
currentDebugLog.mutex->v();
safeMutex.ReleaseLock();
}
// output to console
else {