Background not loading

I’m currently working on integrating my panda3d python file into an API.
The background was working before I made a new function now it’s not showing.

class Render(ShowBase):
    def __init__(self):
        super().__init__()

    def renderImage(self, jsonFile, variants, layoutVar, output_path):
        my code here...

        dr2d = self.win.makeDisplayRegion()
        cam2dp = NodePath(Camera('cam2dp'))

        render2dp = NodePath('render2dp')

        print(variants[0])
        self.background = OnscreenImage(parent=render2dp,image=variants[0])
        #background image ^^

        cam2dp.reparentTo(render2dp)
        dr2d.setCamera(cam2dp)

        cam2dp.node().getDisplayRegion(0).setSort(20)
        self.cam.node().getDisplayRegion(0).setSort(30)

        self.graphicsEngine.renderFrame()
        self.graphicsEngine.renderFrame()
        self.win.saveScreenshot(output_path)

render = Render()
render.renderImage("layout.json", ["models/backgrounds/coral-background.png",
 "models/wall-decor/art.egg"], 1, "render.png")

Fixed by adding the creation of the display region in the initializer