Skip to content

Vizard Memory Leak when using vizInterface.addCamMsgToModule() #1079

@mrbehrens48

Description

@mrbehrens48

Describe the bug
When using Vizard with simulated cameras, Vizard will memory leak and crash if Live Display is enabled. The speed of the leak is proportional to the image size of the simulated camera, so a 4096x4096 camera will cause a crash much sooner than a 1024x1024 camera. It seems like only in Live Display mode, Vizard is retaining copies of each camera message it generates. with No Display mode this is not an issue. Is there any way to turn this off?

To reproduce
this block of code is sufficient to cause the leak.
if self.config['SIMULATE_CAMERAS']:
for idx, (camera_name, camera_model) in enumerate(self.spacecraft.cameras.items()):
self.viz.addCamMsgToModule(camera_model.cameraConfigOutMsg)
camera_dict = self.otp4_config.cameras[camera_name]
self.spacecraft.SetCamera('spacecraft_camera', camera_model, camera_name, camera_dict, self.viz, idx, self.config)
self.logger.info(f'Added camera {camera_name} to Vizard')

def SetCamera(self, spacecraft_name, cameraModel: bskCamera.Camera, camera_name: str, camera_dict: dict, aVizInterface, camIdx, scenario_config_dict):

    cameraModel.ModelTag = f'{spacecraft_name}_{camera_name}'
    cameraModel.cameraIsOn = scenario_config['is_on'][camera_name]
    cameraModel.cameraID = camera_dict['ID']
    cameraModel.imageInMsg.subscribeTo(aVizInterface.opnavImageOutMsgs[camIdx])
    cameraModel.saveImages = 0
    

    camera_folder = imgFolder + camera_name
    cameraModel.saveDir = camera_folder + "/out"
    if cameraModel.saveImages:
        if not os.path.exists(cameraModel.saveDir):
            print(f'{camera_folder} does not exist. making it')
            os.makedirs(camera_folder, exist_ok=True)
        self.logger.info("Saving camera ID:" + str(cameraModel.cameraID) + " Images to: " + cameraModel.saveDir)

    # Noise parameters
    cameraModel.gaussian = 0.0
    cameraModel.darkCurrent = 0
    cameraModel.saltPepper = 0.0
    cameraModel.cosmicRays = 0
    cameraModel.blurParam = 3

    render_rate = scenario_config['time_between_frames'][camera_name]
    if render_rate <= 0:
        render_rate = mc.sec2nano(1)
        self.logger.warning(f'Camera {camera_name} has a render rate of {render_rate} seconds, turning this camera off.')
        cameraModel.cameraIsOn = False
        
    render_rate = int(mc.sec2nano(render_rate))
    self.logger.info(f'Setting camera render rate for {camera_name} to {render_rate} nanoseconds')
    cameraModel.renderRate = render_rate
    cameraModel.sigma_CB = rotation_mrp
    
    cameraModel.cameraPos_B = origin
    cameraModel.resolution = [width, height]
    cameraModel.fieldOfView = np.deg2rad(45)
    cameraModel.parentName = self.scObject.ModelTag
    cameraModel.skyBox = 'black' 
  
    self.logger.info(f'setting camera for {spacecraft_name}')

Expected behavior
No memory leak in live display mode, so that the simulated cameras can stream indefinately.

Desktop (please complete the following information):
uname -a
Linux computerName 6.8.0-65-generic #68~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue Jul 15 18:06:34 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

Vizard 2.2.3
Basilisk commit 6d29d10

Additional context
memory leak is in both RAM and VRAM
Basilisk is running in a Docker container, Vizard is not.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions