|
|
Home » Community » U++ community news and announcements » 2023.2
|
|
|
|
|
|
|
Re: 2023.2 [message #60294 is a reply to message #60230] |
Tue, 14 November 2023 15:30   |
Tom1
Messages: 1303 Registered: March 2007
|
Ultimate Contributor |
|
|
Hi,
One of my application windows lost context menu (and timer) with U++ 2023.2. I was able to track the breakdown to U++ git commit 608b204.
Here are the details:
In one of my windows (in a multi window app) deeper in the hierarchy MenuBar::Execute(THISBACK(ContextMenu)) runs a context menu once, but refuses to start again until I have closed and reopened that window again. It gets stuck in Win32Wnd.cpp in the while loop:
bool Ctrl::ProcessEvents(bool *quit)
{
ASSERT_(IsMainThread(), "ProcessEvents can only run in the main thread");
if(ProcessEvent(quit)) {
while(ProcessEvent(quit) && (!LoopCtrl || LoopCtrl->InLoop())); // LoopCtrl-MF 071008
SweepMkImageCache();
return true;
}
SweepMkImageCache();
return false;
}
It seems that "LoopCtrl->InLoop()" never returns false, even after closing the popup menu. I tried to follow deeper, but my ability to understand CtrlCore proved insufficient.
Another, related issue is with TimeCallback that does not work at all in that same window either. Not even before using the context menu.
Unfortunately, this is a very complex program and I have not yet been able to build a separate test case to demonstrate the issue. Simple test cases do not reproduce this issue.
Best regards,
Tom
|
|
|
|
Re: 2023.2 [message #60296 is a reply to message #60295] |
Tue, 14 November 2023 16:00   |
Tom1
Messages: 1303 Registered: March 2007
|
Ultimate Contributor |
|
|
Hi Mirek,
I removed the TimeCallback timer entirely to test, but it does not have any effect to the MenuBar issue...
But yes, this was there:
class MyWindow : public WithMyWindowLayout<TopWindow> {
StatusBar status;
...
TimeCallback timer;
String remotely_updated_string;
void refreshStatus(){ // timer runs this at 100 ms intervals
if(!IsForeground()) return;
status = remotely_updated_string;
}
...
MyWindow(){
...
timer.Set(-100,[&](){ refreshStatus(); });
...
}
~MyWindow(){
...
timer.Kill();
...
}
}
};
Best regards,
Tom
|
|
|
Re: 2023.2 [message #60297 is a reply to message #60296] |
Tue, 14 November 2023 16:07   |
Tom1
Messages: 1303 Registered: March 2007
|
Ultimate Contributor |
|
|
And more. MyWindow is constructed with new. I:
MyWindow *mywindow;
...
mywindow=new MyWindow(&mywindow);
mywindow->OpenMain();
At a GUI_APP_MAIN my main window is started like this:
One<MyMainWindow> mainwindow;
mainwindow.Create();
mainwindow->OpenMain();
if(cmd.GetCount()) mainwindow->OpenFile(cmd[0]);
Ctrl::EventLoop();
// Tom
|
|
|
Re: 2023.2 [message #60298 is a reply to message #60296] |
Tue, 14 November 2023 17:17   |
 |
mirek
Messages: 14257 Registered: November 2005
|
Ultimate Member |
|
|
Just quick note first:
~MyWindow(){
...
timer.Kill();
...
}
Not necessarry - TimerCallback destructor "kills itself". And no timer event can happen during destruction process.
Anyway, try
void refreshStatus(){ // timer runs this at 100 ms intervals
DDUMP(IsForeground());
if(!IsForeground()) return;
status = remotely_updated_string;
}
[Updated on: Tue, 14 November 2023 17:17] Report message to a moderator
|
|
|
Re: 2023.2 [message #60299 is a reply to message #60298] |
Tue, 14 November 2023 17:49   |
Tom1
Messages: 1303 Registered: March 2007
|
Ultimate Contributor |
|
|
Hi,
RDUMP/DDUMP does not print anything to log, so we're not getting any timer events at all here.
BTW: My app uses a whole lot of timers all around to do all kinds of background update tasks. Could this contribute to the problem?
Also, thanks for the tip: I can clean off the timer.Kill();s then.
BR, Tom
|
|
|
Re: 2023.2 [message #60303 is a reply to message #60299] |
Tue, 14 November 2023 23:48   |
 |
mirek
Messages: 14257 Registered: November 2005
|
Ultimate Member |
|
|
timer.Set(-100,[&](){ refreshStatus(); });
[&] is unusual here (and pretty error prone with timer). Normal is
timer.Set(-100, [=] { refreshStatus(); });
Now I do not frankly see a reason why [&] should not work in this very case, but can you try [=] anyway?
Also, make sure that all other timer (and GUI in general) lambdas are with [=]....
You should only use [&] if you are sure that lambda is invoked immediately (e.g. with CoDo).
Mirek
[Updated on: Tue, 14 November 2023 23:49] Report message to a moderator
|
|
|
|
Re: 2023.2 [message #60305 is a reply to message #60304] |
Wed, 15 November 2023 10:41   |
 |
mirek
Messages: 14257 Registered: November 2005
|
Ultimate Member |
|
|
koldo wrote on Wed, 15 November 2023 08:38Hi Mirek
These sentences are very interesting.
Quote:Also, make sure that all other timer (and GUI in general) lambdas are with [=]....
You should only use [&] if you are sure that lambda is invoked immediately (e.g. with CoDo).
I almost understand why you say that but, for didactic reasons, could you explain why to include capture by value rather than by reference.
struct MyApp ... {
Button btn;
String a;
...
};
void MyApp::MyApp()
{
String b;
btn << [&] { a = b; };
}
This creates a dangling reference to b. In fact, if the lambda execution is not 'immediate' (before next statement basically), in most of GUI cases it makes only sense to work with member variables (e.g. 'a' in this case). But then, [=] in fact captures 'this' and that is likely MORE efficient than capturing all member variables individually.
Note that capturing this by [=] was deemed confusing by C++ comitee and they tried to improve on it with [=, this], unfortunately currently it is hard to make code compatible both ways.
Mirek
[Updated on: Wed, 15 November 2023 11:04] Report message to a moderator
|
|
|
Re: 2023.2 [message #60308 is a reply to message #60303] |
Wed, 15 November 2023 11:14   |
Tom1
Messages: 1303 Registered: March 2007
|
Ultimate Contributor |
|
|
Hi,
It does not make difference if I use [=] here. However, I would not dare to point to local temporary variables with timer anyway. Instead, my timer sets are mostly of type timer.Set(THISBACK(UpdateRoutine)); In that case the reference is all about using 'this'.
INTERESTINGLY: The entire timer system freezes when I open the secondary window. Ctrl::TimerProc() does not get called at all until I close that secondary window.
UPDATE: While the secondary window is open, there is not a single WM_TIMER coming into Ctrl::UtilityProc(). The execution of thread is not frozen within TimerProc() though. Windows is just no longer sending WM_TIMER messages in.
Best regards,
Tom
[Updated on: Wed, 15 November 2023 11:34] Report message to a moderator
|
|
|
|
Re: 2023.2 [message #60310 is a reply to message #60309] |
Wed, 15 November 2023 13:07   |
Tom1
Messages: 1303 Registered: March 2007
|
Ultimate Contributor |
|
|
Hi Mirek,
I found a solution:
virtual void Paint(Draw& draw){
...
// scaleview->Refresh();
}
I have a 'scaleview' control under the window. The window's Paint() calls scaleview->Refresh(); After this the timer is frozen until the window is closed. Removing this call to Refresh() makes everything work again.
The funny thing (if any in this case) is that this code is about 10-15 years old and has worked without any problem until now. (The scaleview gets painted anyway automatically, so this call was probably just causing some recursive feeding of more paint requests. So, I'm glad its gone now. Strange thing is that it was not visible on CPU loading...)
Anyway, Mirek, thanks for your help on this issue.
Best regards,
Tom
|
|
|
Re: 2023.2 [message #60311 is a reply to message #60305] |
Thu, 16 November 2023 13:03  |
 |
koldo
Messages: 3435 Registered: August 2008
|
Senior Veteran |
|
|
mirek wrote on Wed, 15 November 2023 10:41koldo wrote on Wed, 15 November 2023 08:38Hi Mirek
These sentences are very interesting.
Quote:Also, make sure that all other timer (and GUI in general) lambdas are with [=]....
You should only use [&] if you are sure that lambda is invoked immediately (e.g. with CoDo).
I almost understand why you say that but, for didactic reasons, could you explain why to include capture by value rather than by reference.
struct MyApp ... {
Button btn;
String a;
...
};
void MyApp::MyApp()
{
String b;
btn << [&] { a = b; };
}
This creates a dangling reference to b. In fact, if the lambda execution is not 'immediate' (before next statement basically), in most of GUI cases it makes only sense to work with member variables (e.g. 'a' in this case). But then, [=] in fact captures 'this' and that is likely MORE efficient than capturing all member variables individually.
Note that capturing this by [=] was deemed confusing by C++ comittee and they tried to improve on it with [=, this], unfortunately currently it is hard to make code compatible both ways.
Mirek
Thank you Mirek for answering this off-topic question.
Additional information about this can be found here.
I didn't know this:Quote:[=] in fact captures 'this'
In summary, especially in classes, when we sometimes put a [&], we should really have to put [this], and in some cases a [=].
Best regards
Iñaki
|
|
|
Goto Forum:
Current Time: Mon May 12 01:04:13 CEST 2025
Total time taken to generate the page: 0.03576 seconds
|
|
|