Gazebo Crashes when I add a camera and use the plugin libgazebo_ros_camera.so

Hi!
I am trying to add a camera to the iris model in gazebo and get those topics on ros2. I referred to this post and added the snippet to the iris.sdf.jinja file and ran make px4_sitl_rtps gazebo. The following is the output:

[0/4] Performing build step for 'sitl_gazebo'
[1/1] Generating /home/madhav/PX4-Auto...Tools/sitl_gazebo/models/iris/iris.sdf
/home/madhav/PX4-Autopilot/Tools/sitl_gazebo/models/iris/iris.sdf.jinja -> /home/madhav/PX4-Autopilot/Tools/sitl_gazebo/models/iris/iris.sdf
[3/4] cd /home/madhav/PX4-Autopilot/bu...dhav/PX4-Autopilot/build/px4_sitl_rtps
SITL ARGS
sitl_bin: /home/madhav/PX4-Autopilot/build/px4_sitl_rtps/bin/px4
debugger: none
program: gazebo
model: none
world: none
src_path: /home/madhav/PX4-Autopilot
build_path: /home/madhav/PX4-Autopilot/build/px4_sitl_rtps
empty model, setting iris as default
GAZEBO_PLUGIN_PATH /usr/lib/x86_64-linux-gnu/gazebo-11/plugins:/usr/lib/x86_64-linux-gnu/gazebo-11/plugins:/usr/lib/x86_64-linux-gnu/gazebo-11/plugins::/home/madhav/PX4-Autopilot/build/px4_sitl_rtps/build_gazebo
GAZEBO_MODEL_PATH /usr/share/gazebo-11/models:/usr/share/gazebo-11/models:/usr/share/gazebo-11/models::/home/madhav/PX4-Autopilot/Tools/sitl_gazebo/models
LD_LIBRARY_PATH /home/madhav/px4_ros_com_ros2/install/px4_ros_com/lib:/home/madhav/px4_ros_com_ros2/install/px4_msgs/lib:/opt/ros/foxy/opt/yaml_cpp_vendor/lib:/opt/ros/foxy/opt/rviz_ogre_vendor/lib:/opt/ros/foxy/lib/x86_64-linux-gnu:/opt/ros/foxy/lib::/usr/lib/x86_64-linux-gnu/gazebo-11/plugins::/usr/lib/x86_64-linux-gnu/gazebo-11/plugins:/usr/lib/x86_64-linux-gnu/gazebo-11/plugins::/usr/lib/x86_64-linux-gnu/gazebo-11/plugins:/usr/lib/x86_64-linux-gnu/gazebo-11/plugins:/usr/lib/x86_64-linux-gnu/gazebo-11/plugins::/home/madhav/PX4-Autopilot/build/px4_sitl_rtps/build_gazebo
empty world, setting empty.world as default
Using: /home/madhav/PX4-Autopilot/Tools/sitl_gazebo/models/iris/iris.sdf
Warning [parser.cc:833] XML Attribute[version] in element[sdf] not defined in SDF, ignoring.
/home/madhav/PX4-Autopilot/Tools/sitl_run.sh: line 216: 11233 Segmentation fault      (core dumped) gzserver $verbose $world_path $ros_args
SITL COMMAND: "/home/madhav/PX4-Autopilot/build/px4_sitl_rtps/bin/px4" "/home/madhav/PX4-Autopilot/build/px4_sitl_rtps"/etc -s etc/init.d-posix/rcS -t "/home/madhav/PX4-Autopilot"/test_data
Creating symlink /home/madhav/PX4-Autopilot/build/px4_sitl_rtps/etc -> /home/madhav/PX4-Autopilot/build/px4_sitl_rtps/t

_____  __   __    ___ 
| ___ \ \ \ / /   /   |
| |_/ /  \ V /   / /| |
|  __/   /   \  / /_| |
| |     / /^\ \ \___  |
\_|     \/   \/     |_/

px4 starting.

INFO  [px4] Calling startup script: /bin/sh etc/init.d-posix/rcS 0
INFO  [init] found model autostart file as SYS_AUTOSTART=10016
INFO  [param] selected parameter default file eeprom/parameters_10016
INFO  [parameters] BSON document size 291 bytes, decoded 291 bytes (INT32:12, FLOAT:3)
[param] Loaded: eeprom/parameters_10016
INFO  [dataman] data manager file './dataman' size is 7866640 bytes
PX4 SIM HOST: localhost
INFO  [simulator] Waiting for simulator to accept connection on TCP port 4560
Gazebo multi-robot simulator, version 11.13.0
Copyright (C) 2012 Open Source Robotics Foundation.
Released under the Apache 2 License.
http://gazebosim.org

[Msg] Waiting for master.
[Err] [ConnectionManager.cc:121] Failed to connect to master in 30 seconds.
[Err] [gazebo_shared.cc:78] Unable to initialize transport.
[Err] [gazebo_client.cc:56] Unable to setup Gazebo

You can see that the gzserver had a seg fault and crashed after the warning.
I have used the migration article for adding ros2 plugins and this is how the plugin is written in the iris.sdf.jinja file:

<sensor name="down_camera" type="camera">          
            <pose>0 0 0 -1.5708 0 0</pose>
            <camera>
                <horizontal_fov>2.0</horizontal_fov>
                <image>
                    <format>R8G8B8</format>
                    <width>640</width>
                    <height>480</height>
                </image>
                <clip>
                    <near>0.05</near>
                    <far>15000</far>
                </clip>
            </camera>
            <always_on>1</always_on>
            <update_rate>10</update_rate>
            <visualize>true</visualize>
            
            <plugin filename="libgazebo_ros_camera.so" name="camera_en_ros">
            	<ros>
		      <namespace>iris</namespace>
		      <remapping>image_raw:=custom_img</remapping>
		      <remapping>camera_info:=custom_info</remapping>
            	</ros>
           
                <cameraName>down_camera_link</cameraName>
                <FrameName>downCameraImage</FrameName>
                <Cy>0</Cy>
                <Cx>0</Cx>
                <updateRate>30.0</updateRate>
            </plugin>
            
            <plugin name="GstCameraPlugin" filename="libgazebo_gst_camera_plugin.so">
                <robotNamespace></robotNamespace>
                <udpPort>5600</udpPort>
            </plugin>
            <plugin name="GeotaggedImagesPlugin" filename="libgazebo_geotagged_images_plugin.so">
                <robotNamespace>iris</robotNamespace>
                <interval>1</interval>
                <width>3840</width>
                <height>2160</height>
                <maximum_zoom>8.0</maximum_zoom>
            </plugin>
        </sensor>

If I comment out the libgazebo_ros_camera.so plugin, I am able to get the camera and the image published on gazebo topics without errors. I can see that the plugin binary is in the folder /opt/ros/foxy/lib I suspect something is wrong with this plugin. Can someone please help me out? Thank you so much!

Try this

<sensor name="down_camera" type="camera">
            <pose>0 0 0 -1.5708 0 0</pose>
            <camera>
                <horizontal_fov>2</horizontal_fov>
                <image>
                    <format>R8G8B8</format>
                    <width>1080</width>
                    <height>2560</height>
                </image>
                <clip>
                    <near>0.05</near>
                    <far>15000</far>
                </clip>
            </camera>
            <always_on>1</always_on>
            <update_rate>30</update_rate>
            <visualize>true</visualize>
            <plugin filename="libgazebo_ros_camera.so" name="camera_en_ros">
                <robotNamespace>iris</robotNamespace>
                <cameraName>down_camera_link</cameraName>
                <imageTopicName>down_raw_image</imageTopicName>
                <cameraInfoTopicName>down_info_image</cameraInfoTopicName>
                <FrameName>downCameraImage</FrameName>
                <Cy>0</Cy>
                <Cx>0</Cx>
                <updateRate>30.0</updateRate>
            </plugin>
            <plugin name="GstCameraPlugin" filename="libgazebo_gst_camera_plugin.so">
                <robotNamespace></robotNamespace>
                <udpPort>5600</udpPort>
            </plugin>
            <plugin name="GeotaggedImagesPlugin" filename="libgazebo_geotagged_images_plugin.so">
                <robotNamespace>iris</robotNamespace>
                <interval>1</interval>
                <width>3840</width>
                <height>2160</height>
                <maximum_zoom>8.0</maximum_zoom>
            </plugin>
        </sensor>

I am trying to spawn multiple drones with the camera but I am getting this error. I am able to get camera input and ros topics if I spawn single drone. How can I fix this?

╭─munawwar at munawwar-ASUS in ~/PX4-Autopilot on main✘✘✘
╰─± ./Tools/simulation/gazebo-classic/sitl_multiple_run.sh -m iris -n 2

killing running instances
GAZEBO_PLUGIN_PATH /usr/lib/x86_64-linux-gnu/gazebo-11/plugins:/usr/lib/x86_64-linux-gnu/gazebo-11/plugins::/home/munawwar/PX4-Autopilot/Tools/simulation/gazebo-classic/../../../build/px4_sitl_default/build_gazebo-classic
GAZEBO_MODEL_PATH /usr/share/gazebo-11/models:/usr/share/gazebo-11/models::/home/munawwar/PX4-Autopilot/Tools/simulation/gazebo-classic/../../../Tools/simulation/gazebo-classic/sitl_gazebo-classic/models
LD_LIBRARY_PATH /home/munawwar/ws_offboard_control/install/px4_ros_com/lib:/home/munawwar/ws_offboard_control/install/px4_msgs/lib:/usr/lib/x86_64-linux-gnu/gazebo-11/plugins:/opt/ros/humble/opt/rviz_ogre_vendor/lib:/opt/ros/humble/lib/x86_64-linux-gnu:/opt/ros/humble/lib:/usr/lib/x86_64-linux-gnu/gazebo-11/plugins::/usr/lib/x86_64-linux-gnu/gazebo-11/plugins:/usr/lib/x86_64-linux-gnu/gazebo-11/plugins::/home/munawwar/PX4-Autopilot/Tools/simulation/gazebo-classic/../../../build/px4_sitl_default/build_gazebo-classic
Starting gazebo
Gazebo multi-robot simulator, version 11.10.2
Copyright (C) 2012 Open Source Robotics Foundation.
Released under the Apache 2 License.
http://gazebosim.org

[Msg] Waiting for master.
[Msg] Connected to gazebo master @ http://127.0.0.1:11345
[Msg] Publicized address: 10.3.13.191
[Msg] Loading world file [/home/munawwar/PX4-Autopilot/Tools/simulation/gazebo-classic/../../../Tools/simulation/gazebo-classic/sitl_gazebo-classic/worlds/postoffice.world]
[Wrn] [OBJLoader.cc:79] Both `d` and `Tr` parameters defined for "SUV_Body". Use the value of `d` for dissolve (line 8 in .mtl.)
Both `d` and `Tr` parameters defined for "SUV_Wheels". Use the value of `d` for dissolve (line 22 in .mtl.)

starting instance 1 in /home/munawwar/PX4-Autopilot/build/px4_sitl_default/rootfs/0
Running /home/munawwar/PX4-Autopilot/Tools/simulation/gazebo-classic/sitl_gazebo-classic/scripts/jinja_gen.py
/home/munawwar/PX4-Autopilot/Tools/simulation/gazebo-classic/../../../Tools/simulation/gazebo-classic/sitl_gazebo-classic/models/iris/iris.sdf.jinja -> /tmp/iris_1.sdf
Spawning iris_1 at 0.0 2
starting instance 2 in /home/munawwar/PX4-Autopilot/build/px4_sitl_default/rootfs/1
Running /home/munawwar/PX4-Autopilot/Tools/simulation/gazebo-classic/sitl_gazebo-classic/scripts/jinja_gen.py
/home/munawwar/PX4-Autopilot/Tools/simulation/gazebo-classic/../../../Tools/simulation/gazebo-classic/sitl_gazebo-classic/models/iris/iris.sdf.jinja -> /tmp/iris_2.sdf
Spawning iris_2 at 0.0 4
[Wrn] [Event.cc:61] Warning: Deleting a connection right after creation. Make sure to save the ConnectionPtr from a Connect call
[INFO] [1732488068.753167244] [depth_camera_controller]: Publishing camera info to [/camera/camera_info]
[INFO] [1732488068.753603943] [depth_camera_controller]: Publishing depth camera info to [/camera/depth/camera_info]
[INFO] [1732488068.753856459] [depth_camera_controller]: Publishing pointcloud to [/camera/points]
[Wrn] [gazebo_gps_plugin.cpp:77] [gazebo_gps_plugin]: iris_1::gps0 using gps topic "gps0"
[Wrn] [gazebo_gps_plugin.cpp:202] [gazebo_gps_plugin] Using default update rate of 5hz 
[Msg] Connecting to PX4 SITL using TCP
[Msg] Lockstep is enabled
[Msg] Speed factor set to: 1
[Msg] Using MAVLink protocol v2.0
Starting gazebo client
[Wrn] [OBJLoader.cc:79] Both `d` and `Tr` parameters defined for "Hybrid". Use the value of `d` for dissolve (line 8 in .mtl.)
Both `d` and `Tr` parameters defined for "Wheels3". Use the value of `d` for dissolve (line 22 in .mtl.)
Both `d` and `Tr` parameters defined for "Hybrid_Interior". Use the value of `d` for dissolve (line 36 in .mtl.)
Both `d` and `Tr` parameters defined for "Windows". Use the value of `d` for dissolve (line 50 in .mtl.)

[Wrn] [FuelModelDatabase.cc:313] URI not supported by Fuel [House_1_Normal.png]
[Wrn] [SystemPaths.cc:459] File or path does not exist [""] [House_1_Normal.png]
[ERROR] [1732488069.606850562] [gazebo_ros_node]: Found multiple nodes with same name: /depth_camera_controller. This might be due to multiple plugins using the same name. Try changing one of the the plugin names or use a different ROS namespace. This error might also result from a custom plugin inheriting from another gazebo_ros plugin and the custom plugin trying to access the ROS node object hence creating multiple nodes with same name. To solve this try providing the optional node_name argument in gazebo_ros::Node::Get() function. 
^C./Tools/simulation/gazebo-classic/sitl_multiple_run.sh: line 153: 312631 Segmentation fault      (core dumped) gzserver ${src_path}/Tools/simulation/gazebo-classic/sitl_gazebo-classic/worlds/${world}.world --verbose $ros_args```

Please open a new issue, this post is 1 year old you won’t be getting any help here and the codebase has changed enough that it will be hard to regain context to help you based on the original post.