Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation fault when I try to create a custom sensor from PostprocessMaterial #8579

Open
23wjj opened this issue Jan 16, 2025 · 0 comments

Comments

@23wjj
Copy link

23wjj commented Jan 16, 2025

I want to create a custom camera sensor for carla simulator to render albedo(diffuse) of the image. So I create a Postprocess Material AlbedoEffectMaterial.uasset and place it under the folder Plugins/Content/PostProcessingMaterials as the following picture.
image
The postprocess material is:

Image

To make the blueprints binary know this kind of material, I create a class of camera just like the official depth camera.
The code is as following:
AlbedoCamera.cpp

// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.

#include "Carla.h"
#include "Carla/Sensor/AlbedoCamera.h"
#include "Carla/Actor/ActorBlueprintFunctionLibrary.h"

#include "Carla/Sensor/PixelReader.h"

FActorDefinition AAlbedoCamera::GetSensorDefinition()
{
  return UActorBlueprintFunctionLibrary::MakeCameraDefinition(TEXT("albedo"));
}

AAlbedoCamera::AAlbedoCamera(const FObjectInitializer &ObjectInitializer)
  : Super(ObjectInitializer)
{
  AddPostProcessingMaterial(
      TEXT("Material'/Carla/PostProcessingMaterials/PhysicLensDistortion.PhysicLensDistortion'"));
  AddPostProcessingMaterial(
      TEXT("Material'/Carla/PostProcessingMaterials/AlbedoEffectMaterial.AlbedoEffectMaterial'"));
}

void AAlbedoCamera::PostPhysTick(UWorld *World, ELevelTick TickType, float DeltaSeconds)
{
  TRACE_CPUPROFILER_EVENT_SCOPE(AAlbedoCamera::PostPhysTick);
  FPixelReader::SendPixelsInRenderThread(*this);
}

And AlbedoCamera.h

// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.

#pragma once

#include "Carla/Sensor/ShaderBasedSensor.h"

#include "Carla/Actor/ActorDefinition.h"

#include "AlbedoCamera.generated.h"

/// Sensor that produces "albedo" images.
UCLASS()
class CARLA_API AAlbedoCamera : public AShaderBasedSensor
{
  GENERATED_BODY()

public:

  static FActorDefinition GetSensorDefinition();

  AAlbedoCamera(const FObjectInitializer &ObjectInitializer);

protected:

  void PostPhysTick(UWorld *World, ELevelTick TickType, float DeltaSeconds) override;
};

And these two files are put under the same folder of other camera sensors.
To serialize the new kind of camera, I bind it with the pre-complemented s11n::ImageSerializer like following:
std::pair<AAlbedoCamera *, s11n::ImageSerializer>, in the file LibCarla/source/carla/sensor/SensorRegistry.h.
And I remake the whole carla from source code, and launch the UEEditor succesfully.
But when I want to control the vehicle through pygame widget, and render the images through this sensor.camera.albedo, I got segmentation fault(core dumped).

camera_bp = self.world.get_blueprint_library().find('sensor.camera.albedo')
disp_size = self.display_man.get_display_size()
camera_bp.set_attribute('image_size_x', str(disp_size[0]))
camera_bp.set_attribute('image_size_y', str(disp_size[1]))
camera_bp.set_attribute('fov', str(120))
camera_bp.set_attribute('sensor_tick', str(0))
camera = self.world.spawn_actor(camera_bp, transform, attach_to=attached)
camera.listen(self.save_rgb_image)

image
I guess the problem may comes from the serialization part or the prostprocess material but I'm not quite sure. Can someone kindly helps me? Thanks a lot!
And I've checked the blueprints binary has keyword "sensor.camera.albedo" in it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant