Debugger says: You MUST NOT NEVER EVER use a modal dialog in a timer
-
hi,
why you don't put the "todo stuff" inside your lambda ?
here, my functionpc12545
is called by a command Data.class pc12545_nodalDialog : public GeModalDialog { public: Bool CreateLayout(void) override { AddEditText(1000, BFH_LEFT, SizePix(150)); AddButton(1001, BFH_LEFT, 50, 20, "OK"_s); return true; } Bool InitValues(void) override { SetString(1000, "temporary"_s); return true; } Bool AskClose(void) override { return false; } Bool Command(Int32 id, const BaseContainer& msg) override { if (id == 1001) { GetString(1000, _password); if (_password.IsPopulated()) Close(true); else MessageDialog("Please Enter A password"_s); } return true; } maxon::Result<maxon::String> GetPass() const { if (_password.IsPopulated()) return _password; return maxon::UnknownError(MAXON_SOURCE_LOCATION); } private: maxon::String _password = ""_s; }; static maxon::Result<void> pc12545(BaseDocument* doc) { iferr_scope; maxon::JobRef::Enqueue( []() -> maxon::Result<void> { iferr_scope; pc12545_nodalDialog credentialsDialog; credentialsDialog.Open(-1, -1, 200, 200, true); if (credentialsDialog.GetResult()) { const maxon::String returnedString = credentialsDialog.GetPass() iferr_return; ApplicationOutput("you new password is @", returnedString); } else { ApplicationOutput("your password haven't been modified"); return maxon::UnknownError(MAXON_SOURCE_LOCATION); } // ... do something with the password.CoreMessage maybe. return maxon::OK; } , maxon::JobQueueRef::GetMainThreadQueue()) iferr_return; return maxon::OK; }
Cheers,
Manuel -
This post is deleted! -
Hmm, I can do the "to do" stuff inside the lambda, of course. But what would that change? The problem is, still, that the code is being called from
MessageData::CoreMessage()
(inside aCommandData
, like in your example, was never a problem), and therefore opening the dialog causes the warning to appear, no matter what code comes after opening it.And the other problem still persists, too: If I don't
Wait()
after enqueueing the lambda, the dialog doesn't even appear. And if IWait()
, Cinema freezes.Maybe it's simply not possible to do anything with modal dialogs in code that's called from
MessageData::CoreMessage
, regardless of any threading stunts we could do? -
hi,
using wait or getresult is really strange i agree, but you don't need them.I've added a MessageData and use a timer to trigger the CoreMessage. There i enqueue de job that is executed immediately,
The following code is not executed because
g_inTimer
is false. (the job is executed from main thread).if (g_inTimer) { DiagnosticOutput("You MUST NOT NEVER EVER use a modal dialog in a timer. Please run a job on the main thread (see job.h)."); }
the MessageData i've added :
class TimerMessage_pc12545 : public MessageData { virtual Int32 GetTimer(void); virtual Bool CoreMessage(Int32 id, const BaseContainer &bc); }; Int32 TimerMessage_pc12545::GetTimer() { return 10000; } Bool TimerMessage_pc12545::CoreMessage(Int32 id, const BaseContainer &bc) { if (id == MSG_TIMER) { iferr_scope_handler { return false; }; maxon::JobRef::Enqueue( []() -> maxon::Result<void> { iferr_scope; pc12545_nodalDialog credentialsDialog; credentialsDialog.Open(-1, -1, 200, 200, true); if (credentialsDialog.GetResult()) { const maxon::String returnedString = credentialsDialog.GetPass() iferr_return; ApplicationOutput("you new password is @", returnedString); } else { ApplicationOutput("your password haven't been modified"); return maxon::UnknownError(MAXON_SOURCE_LOCATION); } return maxon::OK; // ... do something with the password. } , maxon::JobQueueRef::GetMainThreadQueue()) iferr_return; } return true; }
Cheers,
Manuel -
Hm, thanks. Well, in my case, I don't even use the
MessageData
's timer. I am simply reacting to aCoreMessage
that is sent from another part of the plugin. And it seems, in that caseg_inTimer
istrue
. Is there a way to make itfalse
?My code looks basically similar to yours, I'm just listening to another message, not
MSG_TIMER
. -
Addition: I've also tried returning 0 from MessageData::GetTimer(), it changes nothing.
-
And 2nd addition: How do you proceed when you actually need the credentials from the dialog in the code after the lambda? I can't move the whole plugin with all its components to a separate enqueued job, just because of the problem with modal dialogs.
I need to show the user the dialog, and get their input. I need things to wait until the user has closed the dialog, then I need the credentials and do stuff with it that is not part of the same lambda.
-
hi,
I don't think the message i react to is important.You can call whatever function you need inside the lambda. You can pass that function some parameters. This will be executed from the mainThread.
Once it's done, the lambda will send a CoreMessage and your plugins could react to that.it's just like "hey job, do this for me and tell me once it's done"
Sorry i don't see where's the issu here, or at least i can't reproduce it.
Maybe you could send us some more information by email to keep it secret (as it's related to password etc) or code.Cheers,
Manuel -
Sending another CoreMessage... interesting... I will try that, too. Thank you!
-
hi,
did you tried out ?
Cheers,
Manuel -
hi,
I'll set this thread as solved without feedback from your side.
Cheers,
Manuel -
I did try it out, and did not experience any change in behavior. I guess it's rooted somewhere entirely else.
-
arff, that's really strange, I'll send you a simple example and see if the error still happen on your system.