Skip to content

Commit ae06153

Browse files
committed
(roseus_bt) define result_ member as Document to avoid having the allocator go out of scope
1 parent c2e9ba7 commit ae06153

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

roseus_bt/include/roseus_bt/ws_action_client.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ class RosbridgeActionClient
1414
RosbridgeActionClient(const std::string& master, int port, const std::string& server_name, const std::string& action_type):
1515
rbc_(fmt::format("{}:{}", master, std::to_string(port))),
1616
server_name_(server_name),
17-
is_active_(false)
17+
result_(rapidjson::kObjectType),
18+
is_active_(false),
1819
{
1920
if (server_name_.front() != '/') {
2021
server_name_ = '/' + server_name_;
@@ -89,7 +90,7 @@ class RosbridgeActionClient
8990
RosbridgeWsClient rbc_;
9091

9192
bool is_active_;
92-
rapidjson::Value result_;
93+
rapidjson::Document result_;
9394

9495
std::string server_name_;
9596
std::string goal_topic_;
@@ -108,10 +109,7 @@ class RosbridgeActionClient
108109
std::cout << "resultCallback(): Message Received: " << message << std::endl;
109110
#endif
110111

111-
rapidjson::Document document(rapidjson::kObjectType);
112-
document.Parse(message.c_str());
113-
rapidjson::Value res(document, document.GetAllocator());
114-
result_ = res;
112+
result_.Parse(message.c_str());
115113

116114
is_active_ = false;
117115
}

roseus_bt/include/roseus_bt/ws_service_client.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ class RosbridgeServiceClient
1414
RosbridgeServiceClient(const std::string& master, int port, const std::string& service_name):
1515
rbc_(fmt::format("{}:{}", master, std::to_string(port))),
1616
service_name_(service_name),
17-
is_active_(false)
17+
result_(rapidjson::kObjectType),
18+
is_active_(false),
1819
{
1920
if (service_name_.front() != '/') {
2021
service_name_ = '/' + service_name_;
@@ -46,7 +47,9 @@ class RosbridgeServiceClient
4647
}
4748

4849
void waitForResult() {
50+
#ifdef DEBUG
4951
std::cout << "RemoteService: waiting for result: " << service_name_ << std::endl;
52+
#endif
5053
while (is_active_) {
5154
std::this_thread::sleep_for(std::chrono::milliseconds(10));
5255
}
@@ -58,7 +61,7 @@ class RosbridgeServiceClient
5861
RosbridgeWsClient rbc_;
5962

6063
bool is_active_;
61-
rapidjson::Value result_;
64+
rapidjson::Document result_;
6265

6366
std::string service_name_;
6467

@@ -71,10 +74,7 @@ class RosbridgeServiceClient
7174
std::cout << "serviceResponseCallback(): Message Received: " << message << std::endl;
7275
#endif
7376

74-
rapidjson::Document document(rapidjson::kObjectType);
75-
document.Parse(message.c_str());
76-
rapidjson::Value res(document, document.GetAllocator());
77-
result_ = res;
77+
result_.Parse(message.c_str());
7878

7979
is_active_ = false;
8080
connection->send_close(1000);

0 commit comments

Comments
 (0)