From 88340cd36a00a508a61fe550759e5cff3e6753df Mon Sep 17 00:00:00 2001 From: cxl Date: Sat, 5 Nov 2011 18:26:10 +0000 Subject: [PATCH] CtrlCore: X11 Fixed issue with memory leaks causing segmentation fault without displaying the warning git-svn-id: svn://ultimatepp.org/upp/trunk@4133 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/Core/Util.cpp | 1 + uppsrc/CtrlCore/X11App.cpp | 13 ++- uppsrc/CtrlCore/X11Ctrl.h | 225 +++++++++++++++++++------------------ uppsrc/CtrlCore/init | 2 +- 4 files changed, 123 insertions(+), 118 deletions(-) diff --git a/uppsrc/Core/Util.cpp b/uppsrc/Core/Util.cpp index af72cace1..7a8cdae22 100644 --- a/uppsrc/Core/Util.cpp +++ b/uppsrc/Core/Util.cpp @@ -19,6 +19,7 @@ void InstallPanicMessageBox(void (*mb)(const char *title, const char *text)) void PanicMessageBox(const char *title, const char *text) { + PanicMode = true; if(sPanicMessageBox) (*sPanicMessageBox)(title, text); else { diff --git a/uppsrc/CtrlCore/X11App.cpp b/uppsrc/CtrlCore/X11App.cpp index e7d35c1df..c56690c90 100644 --- a/uppsrc/CtrlCore/X11App.cpp +++ b/uppsrc/CtrlCore/X11App.cpp @@ -153,12 +153,15 @@ void Ctrl::UntrapX11Errors(bool b) X11ErrorTrap = b; } -static void sPanicMessageBox(const char *title, const char *text) +void sPanicMessageBox(const char *title, const char *text) { - GuiLock __; write(2, text, strlen(text)); write(2, "\n", 1); - Ctrl::ReleaseCtrlCapture(); + if(Ctrl::grabWindow) { + LLOG("RELEASE GRAB"); + XUngrabPointer(Xdisplay, CurrentTime); + XFlush(Xdisplay); + } XDisplay *display = XOpenDisplay(NULL); if(!display) return; @@ -233,11 +236,11 @@ static void sPanicMessageBox(const char *title, const char *text) int X11ErrorHandler(XDisplay *, XErrorEvent *error) { + if(X11ErrorTrap || IsPanicMode()) return 0; + if(GetIniKey(INI_PREFIX "X11_ERRORS") != "1") return 0; - if(X11ErrorTrap || IsPanicMode()) return 0; - static const char *request[] = { "", "X_CreateWindow", diff --git a/uppsrc/CtrlCore/X11Ctrl.h b/uppsrc/CtrlCore/X11Ctrl.h index 981340552..60144a368 100644 --- a/uppsrc/CtrlCore/X11Ctrl.h +++ b/uppsrc/CtrlCore/X11Ctrl.h @@ -1,112 +1,113 @@ -//$ class Ctrl { - bool ignoretakefocus:1; -protected: - struct XWindow { - Ptr ctrl; - bool exposed; - Vector invalid; - Ptr owner; - Ptr last_active; - XIC xic; - }; - -private: - static ArrayMap& Xwindow(); - static int WndCaretTime; - static bool WndCaretVisible; - static int Xbuttons; - static int Xbuttontime; - static Point Xbuttonpos; - static Window grabWindow, focusWindow; - static Point mousePos; - static int PopupGrab; - static Ptr popupWnd; - static Index sel_formats; - static Ptr sel_ctrl; - static void ProcessEvent(XEvent *event); - static void TimerAndPaint(); - static void ProcessEvent(XEvent& event); - void Invalidate(XWindow& xw, const Rect& r); - static void AnimateCaret(); - void DoPaint(const Vector& invalid); - void SetLastActive(XWindow *w, Ctrl *la); - XWindow *GetXWindow(); - static void SyncMousePos(); - static void ReleaseGrab(); - static Vector hotkey; - static Vector modhot; - static Vector keyhot; - - void StartPopupGrab(); - static void EndPopupGrab(); - static void SyncIMPosition(); - - friend bool GetMouseRight(); - friend bool GetMouseLeft(); - friend bool GetMouseMiddle(); - friend Point GetMousePos(); - -protected: - void Create(Ctrl *owner, bool redirect, bool savebits); - void Create0(Ctrl *owner, bool redirect, bool savebits); - void SyncExpose(); - void TakeFocus(); - static Window GetXServerFocusWindow(); - void AddGlobalRepaint(); - static void KillFocus(Window w); - static void FocusSync(); - - void DropEvent(XWindow& w, XEvent *event); - static void DropStatusEvent(XEvent *event); - static Index drop_formats; - static String Unicode(const WString& w); - static WString Unicode(const String& s); - static bool ClipHas(int type, const char *fmt); - static String ClipGet(int type, const char *fmt); - - XWindow *AddXWindow(Window &w); - void RemoveXWindow(Window &w); - XWindow *XWindowFromWindow(Window &w); - -public: - struct Xclipboard { - Window win; - - VectorMap data; - - String Read(int fmt, int selection, int property); - void Write(int fmt, const ClipData& data); - bool IsAvailable(int fmt, const char *type); - - void Clear() { data.Clear(); } - void Request(XSelectionRequestEvent *se); - - Xclipboard(); - ~Xclipboard(); - }; - - static Xclipboard& xclipboard(); - - static int Xeventtime; - - static XIM xim; - - void DnD(Window src, bool paste); - - virtual void EventProc(XWindow& w, XEvent *event); - virtual bool HookProc(XEvent *event); - Window GetWindow() const { return top ? top->window : None; } - static Ctrl *CtrlFromWindow(Window w); - static bool TrapX11Errors(); - static void UntrapX11Errors(bool b); - - Window GetParentWindow(void) const; - Ctrl *GetParentWindowCtrl(void) const; - Rect GetRectInParentWindow(void) const; - - static void SyncNativeWindows(void); -public: - static void InitX11(const char *display); - static void ExitX11(); - static void GuiFlush() { XFlush(Xdisplay); } -//$ }; +//$ class Ctrl { + bool ignoretakefocus:1; +protected: + struct XWindow { + Ptr ctrl; + bool exposed; + Vector invalid; + Ptr owner; + Ptr last_active; + XIC xic; + }; + +private: + static ArrayMap& Xwindow(); + static int WndCaretTime; + static bool WndCaretVisible; + static int Xbuttons; + static int Xbuttontime; + static Point Xbuttonpos; + static Window grabWindow, focusWindow; + static Point mousePos; + static int PopupGrab; + static Ptr popupWnd; + static Index sel_formats; + static Ptr sel_ctrl; + static void ProcessEvent(XEvent *event); + static void TimerAndPaint(); + static void ProcessEvent(XEvent& event); + void Invalidate(XWindow& xw, const Rect& r); + static void AnimateCaret(); + void DoPaint(const Vector& invalid); + void SetLastActive(XWindow *w, Ctrl *la); + XWindow *GetXWindow(); + static void SyncMousePos(); + static void ReleaseGrab(); + static Vector hotkey; + static Vector modhot; + static Vector keyhot; + + void StartPopupGrab(); + static void EndPopupGrab(); + static void SyncIMPosition(); + + friend bool GetMouseRight(); + friend bool GetMouseLeft(); + friend bool GetMouseMiddle(); + friend Point GetMousePos(); + friend void sPanicMessageBox(const char *title, const char *text); + +protected: + void Create(Ctrl *owner, bool redirect, bool savebits); + void Create0(Ctrl *owner, bool redirect, bool savebits); + void SyncExpose(); + void TakeFocus(); + static Window GetXServerFocusWindow(); + void AddGlobalRepaint(); + static void KillFocus(Window w); + static void FocusSync(); + + void DropEvent(XWindow& w, XEvent *event); + static void DropStatusEvent(XEvent *event); + static Index drop_formats; + static String Unicode(const WString& w); + static WString Unicode(const String& s); + static bool ClipHas(int type, const char *fmt); + static String ClipGet(int type, const char *fmt); + + XWindow *AddXWindow(Window &w); + void RemoveXWindow(Window &w); + XWindow *XWindowFromWindow(Window &w); + +public: + struct Xclipboard { + Window win; + + VectorMap data; + + String Read(int fmt, int selection, int property); + void Write(int fmt, const ClipData& data); + bool IsAvailable(int fmt, const char *type); + + void Clear() { data.Clear(); } + void Request(XSelectionRequestEvent *se); + + Xclipboard(); + ~Xclipboard(); + }; + + static Xclipboard& xclipboard(); + + static int Xeventtime; + + static XIM xim; + + void DnD(Window src, bool paste); + + virtual void EventProc(XWindow& w, XEvent *event); + virtual bool HookProc(XEvent *event); + Window GetWindow() const { return top ? top->window : None; } + static Ctrl *CtrlFromWindow(Window w); + static bool TrapX11Errors(); + static void UntrapX11Errors(bool b); + + Window GetParentWindow(void) const; + Ctrl *GetParentWindowCtrl(void) const; + Rect GetRectInParentWindow(void) const; + + static void SyncNativeWindows(void); +public: + static void InitX11(const char *display); + static void ExitX11(); + static void GuiFlush() { XFlush(Xdisplay); } +//$ }; diff --git a/uppsrc/CtrlCore/init b/uppsrc/CtrlCore/init index 9ebf9e9f2..39c087bcf 100644 --- a/uppsrc/CtrlCore/init +++ b/uppsrc/CtrlCore/init @@ -3,7 +3,7 @@ #include "Draw/init" #include "plugin\bmp/init" #include "RichText/init" -#define BLITZ_INDEX__ F58C23D3C57D9E639358E3B0D8F9A293E +#define BLITZ_INDEX__ F4A0E2450AF6499214C0E1EC13352603A #include "CtrlCore.icpp" #undef BLITZ_INDEX__ #endif