Skip to content

Commit

Permalink
alternative to stringstream for 4.15 crash for recording
Browse files Browse the repository at this point in the history
  • Loading branch information
sytelus committed Jul 26, 2017
1 parent b5f9a05 commit 6c413e6
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 28 deletions.
20 changes: 17 additions & 3 deletions AirLib/include/common/common_utils/FileSystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,23 @@ class FileSystem
std::string logfolder = Utils::to_string(Utils::now(), "%Y-%m-%d");
std::string fullPath = combine(getAppDataFolder(), logfolder);
std::string timestamp = add_timestamp ? Utils::to_string(Utils::now()) : "";
std::stringstream filename_ss;
filename_ss << ensureFolder(fullPath) << kPathSeparator << prefix << suffix << timestamp << extension;
return filename_ss.str();

//TODO: because this bug we are using alternative code with stringstream
//https://answers.unrealengine.com/questions/664905/unreal-crashes-on-two-lines-of-extremely-simple-st.html

std::string filename;
filename.append(ensureFolder(fullPath))
.push_back(kPathSeparator);
filename.append(prefix)
.append(suffix)
.append(timestamp)
.append(extension);

return filename;

//std::stringstream filename_ss;
//filename_ss << ensureFolder(fullPath) << kPathSeparator << prefix << suffix << timestamp << extension;
//return filename_ss.str();
}

static void openTextFile(std::string filepath, std::ifstream& file){
Expand Down
16 changes: 0 additions & 16 deletions AirLib/include/common/common_utils/Utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,6 @@
#include <queue>
#include "type_utils.hpp"

#ifndef _WIN32
#include <limits.h> // needed for CHAR_BIT used below
#endif

//Stubs for C++17 optional type
#if (defined __cplusplus) && (__cplusplus >= 201700L)
#include <optional>
#else
#include "optional.hpp"
#endif

#if (defined __cplusplus) && (__cplusplus >= 201700L)
using std::optional;
#else
using std::experimental::optional;
#endif

#define _USE_MATH_DEFINES
#include <cmath>
Expand Down
38 changes: 29 additions & 9 deletions Unreal/Plugins/AirSim/Source/Recording/RecordingFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,41 @@ void RecordingFile::appendRecord(TArray<uint8>& image_data, const msr::airlib::P
if (imageSavedOk) {
auto kinematics = physics_body->getKinematics();

uint64_t timestamp_millis = static_cast<uint64_t>(msr::airlib::ClockFactory::get()->nowNanos() / 1.0E6);

std::stringstream ss;
ss << timestamp_millis << "\t";
ss << kinematics.pose.position.x() << "\t" << kinematics.pose.position.y() << "\t" << kinematics.pose.position.z() << "\t";
ss << kinematics.pose.orientation.w() << "\t" << kinematics.pose.orientation.x() << "\t" << kinematics.pose.orientation.y() << "\t" << kinematics.pose.orientation.z() << "\t";
ss << "\n";

writeString(ss.str());
writeString(getLine(kinematics));

UAirBlueprintLib::LogMessage(TEXT("Screenshot saved to:"), filePath, LogDebugLevel::Success);
images_saved_++;
}
}

std::string RecordingFile::getLine(const msr::airlib::Kinematics::State& kinematics)
{
uint64_t timestamp_millis = static_cast<uint64_t>(msr::airlib::ClockFactory::get()->nowNanos() / 1.0E6);

//TODO: because this bug we are using alternative code with stringstream
//https://answers.unrealengine.com/questions/664905/unreal-crashes-on-two-lines-of-extremely-simple-st.html

std::string line;
line.append(std::to_string(timestamp_millis)).append("\t")
.append(std::to_string(kinematics.pose.position.x())).append("\t")
.append(std::to_string(kinematics.pose.position.y())).append("\t")
.append(std::to_string(kinematics.pose.position.z())).append("\t")
.append(std::to_string(kinematics.pose.orientation.w())).append("\t")
.append(std::to_string(kinematics.pose.orientation.x())).append("\t")
.append(std::to_string(kinematics.pose.orientation.y())).append("\t")
.append(std::to_string(kinematics.pose.orientation.z())).append("\t")
.append("\n");

return line;

//std::stringstream ss;
//ss << timestamp_millis << "\t";
//ss << kinematics.pose.position.x() << "\t" << kinematics.pose.position.y() << "\t" << kinematics.pose.position.z() << "\t";
//ss << kinematics.pose.orientation.w() << "\t" << kinematics.pose.orientation.x() << "\t" << kinematics.pose.orientation.y() << "\t" << kinematics.pose.orientation.z() << "\t";
//ss << "\n";
//return ss.str();
}

void RecordingFile::createFile(const std::string& file_path)
{
try {
Expand Down
1 change: 1 addition & 0 deletions Unreal/Plugins/AirSim/Source/Recording/RecordingFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class RecordingFile {
void writeString(const std::string& line);
bool isFileOpen();
std::string getLogFileFullPath();
std::string getLine(const msr::airlib::Kinematics::State& kinematics);


private:
Expand Down

0 comments on commit 6c413e6

Please sign in to comment.