C4D 2023 on macOS: GeUserArea::DrawBitmap() not working anymore?
-
Hi,
I am using
GeUserArea::DrawBitmap()
to draw a 32-bit greyscale bitmap into aGeUserArea
in aGeDialog
. On macOS, the code works nicely in R20 - R25, but in C4D 2023, nothing happens. All my drawing operations in theGeUserArea
work as expected, but theDrawBitmap()
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 aGeUserArea
in aGeDialog
.
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 -
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 ofBaseBitmap
.I would suggest using
COLORBYTES_RGB
and just writing the same value to all channels. Another thing you could do, is also use the underlyingImageRef
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 -
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 -
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 inImageInterface
days.But be reassured, when you still have problems or there is a bug, we will have a look at it.
Cheers,
Ferdinand -
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 -
By the way, interesting fact: Using the 32-Bit greyscale
BaseBitmap
in aBITMAPBUTTON
CustomGUI works flawlessly. I would have expected it also uses aGeUserArea
internally to draw the bitmap. So, if it was a "known limitation" in theGeUserArea
/ImageInterface
, it shouldn't draw there either, should it?I still suspect a bug
Cheers,
Frank -
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 aGeDialog
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 -
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