Fix menu proxy management that could lead to a crash.

[GB.QT4]
* BUG: Fix menu proxy management that could lead to a crash.

[GB.QT5]
* BUG: Fix menu proxy management that could lead to a crash.
This commit is contained in:
gambas 2017-09-09 01:36:45 +02:00
parent f9bb3106aa
commit 24bbfdc2b2

View File

@ -74,6 +74,7 @@ static CMENU_EXT *alloc_ext(CMENU *_object)
static void register_proxy(void *_object, CMENU *proxy) static void register_proxy(void *_object, CMENU *proxy)
{ {
void *check = proxy; void *check = proxy;
CMENU *old_proxy = NULL;
while (check) while (check)
{ {
@ -89,7 +90,10 @@ static void register_proxy(void *_object, CMENU *proxy)
// EXT(THIS_EXT->proxy)->proxy_for = NULL; // EXT(THIS_EXT->proxy)->proxy_for = NULL;
if (THIS_EXT && THIS_EXT->proxy) if (THIS_EXT && THIS_EXT->proxy)
GB.Unref(POINTER(&THIS_EXT->proxy)); {
old_proxy = (CMENU *)THIS_EXT->proxy;
THIS_EXT->proxy = NULL;
}
if (proxy) if (proxy)
{ {
@ -103,7 +107,13 @@ static void register_proxy(void *_object, CMENU *proxy)
ACTION->setMenu(THIS->menu); ACTION->setMenu(THIS->menu);
else else
ACTION->setMenu(proxy->menu); ACTION->setMenu(proxy->menu);
if (old_proxy)
((QAction *)old_proxy->widget.widget)->setMenu(old_proxy->menu);
} }
if (old_proxy)
GB.Unref(POINTER(&old_proxy));
} }
static int check_menu(void *_object) static int check_menu(void *_object)
@ -461,10 +471,10 @@ BEGIN_METHOD_VOID(Menu_free)
qDebug("Menu_free: item = %p", THIS); qDebug("Menu_free: item = %p", THIS);
#endif #endif
delete_menu(THIS);
//qDebug("Menu_free: (%s %p)", THIS->widget.name, THIS); //qDebug("Menu_free: (%s %p)", THIS->widget.name, THIS);
delete_menu(THIS);
GB.StoreObject(NULL, POINTER(&(THIS->picture))); GB.StoreObject(NULL, POINTER(&(THIS->picture)));
if (THIS_EXT) if (THIS_EXT)
@ -1007,6 +1017,7 @@ void CMenu::slotShown(void)
{ {
static bool init = FALSE; static bool init = FALSE;
//qDebug("slotShown: sender = %p menuAction = %p", sender(), ((QMenu *)sender())->menuAction());
GET_MENU_SENDER(menu); GET_MENU_SENDER(menu);
HANDLE_PROXY(menu); HANDLE_PROXY(menu);
@ -1028,6 +1039,7 @@ void CMenu::slotShown(void)
void CMenu::slotHidden(void) void CMenu::slotHidden(void)
{ {
//qDebug("slotHidden: sender = %p menuAction = %p", sender(), ((QMenu *)sender())->menuAction());
GET_MENU_SENDER(menu); GET_MENU_SENDER(menu);
HANDLE_PROXY(menu); HANDLE_PROXY(menu);