Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Open a GeModalDialog from a Job Observer

    Cinema 4D SDK
    r20 r21 s22 r23 c++ maxon api
    2
    4
    423
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • fwilleke80F
      fwilleke80
      last edited by fwilleke80

      Hello,

      I read this thread about ObservableFinished(), and it works fine so far: I have all the data I need in my result struct, and it's available in the Lambda I pass to AddObserver().

      However, when my job is finished, I want to display a GeModalDialog. Opening a simple OS message box with GeOutString() works fine. But when I instead try to open a custom dialog, nothing happens.

      Here's the code:

      // Create job
      auto checkForUpdate = CheckForUpdateJob::Create() iferr_return;
      checkForUpdate.ObservableFinished().AddObserver([checkForUpdate]() -> maxon::Result<void>
      																								{
      	iferr_scope;
      
      	// Get job's result. this works fine.
      	MyResultStruct result = checkForUpdate.GetResult() iferr_return;
      	if (result.updateAvailable)
      	{
      		// This works:
      		if (GeOutString(GeLoadString(IDS_UPDATECHECK_RESULT_AVAILABLE), GEMB::YESNO) == GEMB_R::V_YES)
      		{
      			DoSomething();
      		}
      
      		// This does not work:
      		MyModalDialog theDialog;
      		theDialog.Open();
      	}
      	return maxon::OK;
      }) iferr_return;
      
      // Enqueue job
      checkForUpdate.Enqueue();
      

      Why is a GeModalDialog not working? And how can I make it work?

      Thanks in advance,
      greetings,
      Frank

      www.frankwilleke.de
      Only asking personal code questions here.

      1 Reply Last reply Reply Quote 0
      • ManuelM
        Manuel
        last edited by

        hi,

        That's because you are not in the main thread. So i would use maxon::ExecuteOnMainThread to open the GeDialog.
        I don't have memory leak but maybe with a more complexe example you could end up with some. Be aware of that.

        checkForUpdate.ObservableFinished().AddObserver([checkForUpdate]() -> maxon::Result<void>
        		{
        			iferr_scope;
        			// Get job's result. this works fine.
        			HttpResponse result = checkForUpdate.GetResult() iferr_return;
        			if (result.updateAvailable)
        			{
        				// This works:
        			if (GeOutString("hello"_s, GEMB::YESNO) == GEMB_R::V_YES)
        				{
        					// DoSomething();
        				ApplicationOutput("hello");
        				}
        
        			maxon::ExecuteOnMainThread([]()
        			{
        					MyModalDialog theDialog;
        					theDialog.Open(DLG_TYPE::MODAL, 123456);
        			}, false); // false here so we don't wait the dialog to be closed.
        			ApplicationOutput("thread is going away");
        			}
        			return maxon::OK;
        		}) iferr_return;
        

        Cheers,
        Manuel

        MAXON SDK Specialist

        MAXON Registered Developer

        1 Reply Last reply Reply Quote 0
        • fwilleke80F
          fwilleke80
          last edited by

          Oh, that sounds like an idea! I'll check that out, thanks!

          So, if GUI stuff is not permitted in threads other than the main thread, should even OS dialogs like GeOutString() not be used in a threaded context? Yes, it works, but is it a good idea?

          Thanks & greetings,
          Frank

          www.frankwilleke.de
          Only asking personal code questions here.

          1 Reply Last reply Reply Quote 0
          • fwilleke80F
            fwilleke80
            last edited by

            It works perfectly, thanks again!

            Cheers,
            Frank

            www.frankwilleke.de
            Only asking personal code questions here.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post