Oh, I didn't realize it was the lite-c section. I decided to search for a thread on the issue instead of starting a new topic. @DLively, I've already confirmed that the problem is with that one line of code (by commenting it out). I also have a workaround that I've tested and seen that it works, but duplicating the workaround in each place the function is needed will result in too many lines of code. I'll try different image formats because it seems the code is perfect.
My workaround is to use pan_create to create the panel at runtime, then delete the panel and recreate it with the new bmap whenever I need to change the panel.