首先,spawn_actor指令是在carla/PythonAPI/carla/source/libcarla/World.cpp——L281中传送给Python端的。
L202 的 “CityObjectLabel”是否要改?cr::CityObjectLabel 对应carla/Libcarla/source/carla/rpc中的ObjectLabel.h
spawn_actor放的blueprint是cc::ActorBlueprint
找到cc::World.h里的L109
SharedPtr<Actor> SpawnActor(
const ActorBlueprint &blueprint,
const geom::Transform &transform,
Actor *parent = nullptr,
rpc::AttachmentType attachment_type = rpc::AttachmentType::Rigid);
到cr::Actor.h 得知SpawnActor返回的是指向Actor类的指针
Actor更详细的信息到cr::ActorDescription.h
但发现cc::World中的SpawnActor不是其定义,还是调用了别的所以继续找
另一路径:从cc::World.h到cc::detail::EpisodeProxy.cpp到Simulator.h和cpp
Simulator.cpp的L315
SharedPtr<Actor> Simulator::SpawnActor(
const ActorBlueprint &blueprint,
const geom::Transform &transform,
Actor *parent,
rpc::AttachmentType attachment_type,
GarbageCollectionPolicy gc) {
rpc::Actor actor;
if (parent != nullptr) {
actor = _client.SpawnActorWithParent(
blueprint.MakeActorDescription(),
transform,
parent->GetId(),
attachment_type);
} else {
actor = _client.SpawnActor(
blueprint.MakeActorDescription(),
transform);
}
# DUBUG_ASSERT是一个调试断,如果后面为空指针,则会引发一个错误,追究报错是否是在这里产生?结合DEBUG_ASSERT源码及习惯,基本可排除
DEBUG_ASSERT(_episode != nullptr);
_episode->RegisterActor(actor);
const auto gca = (gc == GarbageCollectionPolicy::Inherit ? _gc_policy : gc);
auto result = ActorFactory::MakeActor(GetCurrentEpisode(), actor, gca);
log_debug(
result->GetDisplayId(),
"created",
gca == GarbageCollectionPolicy::Enabled ? "with" : "without",
"garbage collection");
return result;
}
可以看到有三个与spawn actor相关的代码,逐个排查:
①actor = _client.SpawnActor(
blueprint.MakeActorDescription(),
transform)②_episode->RegisterActor(actor);
③auto result = ActorFactory::MakeActor(GetCurrentEpisode(), actor, gca);
现排查①,找到cc::detail::Client.h和cpp,在Client.cpp文件中有:
rpc::Actor Client::SpawnActor(
const rpc::ActorDescription &description,
const geom::Transform &transform) {
return _pimpl->CallAndWait<rpc::Actor>("spawn_actor", description, tr