Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware 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
    • Register
    • Login

    C4D 2023 on macOS: GeUserArea::DrawBitmap() not working anymore?

    Cinema 4D SDK
    2023 c++ macos
    2
    8
    879
    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

      Hi,

      I am using GeUserArea::DrawBitmap() to draw a 32-bit greyscale bitmap into a GeUserArea in a GeDialog. On macOS, the code works nicely in R20 - R25, but in C4D 2023, nothing happens. All my drawing operations in the GeUserArea work as expected, but the DrawBitmap() call does nothing.

      This is how I create the bitmap:

      AutoAlloc<BaseBitmap> bitmap;
      const maxon::Int32 pixelBytes = COLORBYTES_GRAYf;
      const maxon::Int32 pixelBits = pixelBytes * 8;
      
      if (bitmap->Init((maxon::Int32)_width, (maxon::Int32)_height, pixelBits, INITBITMAPFLAGS::GRAYSCALE) != IMAGERESULT::OK)
      	return maxon::OutOfMemoryError(MAXON_SOURCE_LOCATION, "Could not initialize BaseBitmap!"_s);
      
      auto populateBitmapWorker = [&bitmap, pixelBytes] (maxon::Int z)
      {
      	iferr (maxon::Float32* bufferPtr = NewMem(maxon::Float32, _width))
      		return;
      
      	for (maxon::Int x = 0; x < _width; ++x)
      	{
      		// Get value between 0.0 and 1.0
      		const maxon::Float value = GetTheValue(x, z);
      		bufferPtr[x] = (maxon::Float32)value;
      	}
      	bitmap->SetPixelCnt(0, (Int32)z, (Int32)_width, (UChar*)bufferPtr, pixelBytes, COLORMODE::GRAYf, PIXELCNT::NONE);
      	DeleteMem(bufferPtr);
      };
      maxon::ParallelFor::Dynamic(0, _height, populateBitmapWorker);
      

      Calling ShowBitmap() to display the bitmap in the Picture Viewer works fine, it looks exactly as I'd expect.

      Now, in GeUserArea::DrawMsg() I want to draw the bitmap in a GeUserArea in a GeDialog.
      theBitmapPtr has been allocated, initialised, and populated by the above shown code.

      OffScreenOn(); 
      SetClippingRegion(x1, y1, x2, y2);
      
      // Fill background with standard background color
      DrawSetPen(COLOR_BG);
      DrawRectangle(0, 0, GetWidth(), GetHeight());
      
      // Draw the bitmap
      DrawBitmap(theBitmapPtr, 20, 0, 500, 500, 0, 0, theBitmapPtr->GetBw(), theBitmapPtr->GetBh(), BMP_NORMAL);
      

      Again, this works perfectly fine in R25 and older releases. After drawing the bitmap, I also draw some text, and that text still appears in C4D 2023. Just the bitmap is missing. Any ideas?

      Sporadically (but not always), I get messages like this in the Xcode console:

      2023-09-12 15:07:53.549687+0200 Cinema 4D[5384:86871] [net.maxon.cinema4d] CGImageCreate: invalid image bits/component: 8 bits/pixel 32 alpha info = kCGImageAlphaNoneSkipFirst
      outofmemory [mac_gui_tools.mm(291)]
      

      Also, it seems (but I'll double check to validate) that it only fails on macOS, but works on Windows.
      In deed, it works on Windows, but not on macOS.

      Thanks in advance!

      Cheers,
      Frank

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

      ferdinandF 1 Reply Last reply Reply Quote 0
      • ferdinandF
        ferdinand @fwilleke80
        last edited by ferdinand

        Hey @fwilleke80,

        Thank you for reaching out to us. Have you tried using a non-floating point and a non-gray-space mode? Because I am not so sure that the ancient GeUserArea supports any of them.

        You create there a bitmap with a singular four bytes channel, i.e., what falls into the domain of "HDR". The problem with all this is that BaseBitmap these days is only a thin wrapper for ImageInterface and not everything in the classic API supports the complexity of the underlying maxon API. Here we had a bit of a talk about the oddities of BaseBitmap.

        I would suggest using COLORBYTES_RGB and just writing the same value to all channels. Another thing you could do, is also use the underlying ImageRef interface of your bitmap directly, but that is not so fun to do.

        If you still have problems in RGB mode, drop me a note, I will have a look.

        Cheers,
        Ferdinand

        MAXON SDK Specialist
        developers.maxon.net

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

          Thank you Ferdinand! Yes, going 8 bits RGB or greyscale is the next thing Iโ€˜ll try.

          Itโ€™s just strange that it works with R25, and on Windows in 2023, too. Only macOS with C4D 2023 is affected by this. Therefore, I respectfully suspect itโ€™s a bug ๐Ÿ˜‰

          Cheers,
          Frank

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

          ferdinandF 1 Reply Last reply Reply Quote 0
          • ferdinandF
            ferdinand @fwilleke80
            last edited by

            Hey @fwilleke80,

            It could very well be a bug, but you should keep in mind that some code of the image API is OS dependent. It could simply be that the Windows code is a bit cleverer when interpreting malformed inputs.

            My hunch would be more "known" limitation since the bitmaps were conceived much more simplistically in the GeUserArea/BaseBitmap days as they were in ImageInterface days.

            But be reassured, when you still have problems or there is a bug, we will have a look at it.

            Cheers,
            Ferdinand

            MAXON SDK Specialist
            developers.maxon.net

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

              That would be the first time ever that Windows code is more clever than macOS, especially when it comes to media ๐Ÿ˜

              Iโ€™d say, if the API offers a format COLORBYTES_GRAYf, it should work. The fact that it fails only on one OS and in one C4D release does hint to a bug.

              However, Iโ€™ll try going 8 Bit ๐Ÿ™‚

              Cheers,
              Frank

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

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

                By the way, interesting fact: Using the 32-Bit greyscale BaseBitmap in a BITMAPBUTTON CustomGUI works flawlessly. I would have expected it also uses a GeUserArea internally to draw the bitmap. So, if it was a "known limitation" in the GeUserArea/ImageInterface, it shouldn't draw there either, should it?

                I still suspect a bug ๐Ÿ˜›

                Cheers,
                Frank

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

                ferdinandF 1 Reply Last reply Reply Quote 0
                • ferdinandF
                  ferdinand @fwilleke80
                  last edited by ferdinand

                  Hey @fwilleke80,

                  It could very well be that this is a bug, but it is still faster for you to test if changing these few lines will fix it than me unwinding your project.

                  Alternatively, you could provide a compileable project as lined out in our guidelines. Because to check your code, I would have to implement quite a lot of stuff around it right now. The more users provide us with such fragments of code, the more I will ask them to test things themselves. When you provide me with a zip from the get-go which I can either include into one of our solutions or which even better itself contains a solution, I am much more inclined to quickly give it a spin myself.

                  Here I would have first to implement a GeUserArea and a GeDialog and in doing so risk changing the outcome of any tests.

                  For simple things and beginners, I sometimes do that - infer code and intentions. But the problems of expert users such as yourself usually are too complex that I could just easily do that all the time without having exhausted other routes first. And this does not even touch the problem that users show us a snippet and then five lines below that cause a problem they do not show us, with us then running in circles trying to reproduce the problem.

                  Long story short and a bit blunt: When you want quick answers, provide compileable and executable code.

                  Cheers,
                  Ferdinand

                  MAXON SDK Specialist
                  developers.maxon.net

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

                    I already tried using 8 bit greyscale. Still doesn't work in 2023 on macOS, but on the other C4D/OS combinations.

                    Will try RGB, too.

                    If that doesn't work either, I'll be back and try to write a minimal example.

                    Cheers,
                    Frank

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

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