PNMImage.set_alpha() raises AssertionError

Hello everyone, so recently, I’ve been trying to generate a procedural texture using panda3d.core.PNMImage, and it works great, for the most part, that is. Setting R, G and B values are easy enough, via PNMImage.set_red(), and so on and so forth, however, setting the alpha value via PNMImage.set_alpha() raises this error:

    proc_img.set_alpha(x, z, 1)
AssertionError: _alpha != nullptr && x >= 0 && x < _x_size && y >=
0 && y < _y_size at line 560 of built1.10/include/pnmImage.

Any help would be appreciated, and please tell me if this is a stupid question, or something along the lines of an embarassingly obvious question. Also, this isn’t related to me trying to write a pixel beyond the texture’s size, by the way. set_red() and others work just fine on the same iteration, it’s just set_alpha().


When you create your PNMImage, how many channels are you specifying? If you’ve only specified three, then you’re ending up with an image that has no alpha-channel, and thus an error when the code attempts to address an alpha-channel.

To add an alpha channel after the fact, call proc_img.make_alpha().

1 Like

Thanks for the reply, however, it seems that there is no such function. I forgot to add more context, sorry. proc_img is a PNMImage. The docs don’t state that such a function exists, either

Oh, it seems it’s add_alpha(), not make_alpha(). Thanks for the replies, both of you. Have a good day!