1
0
Fork 0

Fixed replay-from-url bug.

Need to use simgear::HTTP::FileRequestRef shared pointer, otherwise
HTTPFileRequest will delete it after the transfer.

Also changed callback to a lambda to match reinstated simgear API.
This commit is contained in:
Julian Smith 2021-02-20 13:24:49 +00:00
parent 9fdb3e2c2a
commit 32a066f810
3 changed files with 13 additions and 11 deletions

View file

@ -1992,7 +1992,7 @@ void FGReplay::call_indexContinuousRecording(void* ref, const void* data, size_t
* Actual data and signal configuration is not read when in "Preview" mode.
*/
bool
FGReplay::loadTape(const SGPath& Filename, bool Preview, SGPropertyNode& MetaMeta, simgear::HTTP::FileRequest* filerequest)
FGReplay::loadTape(const SGPath& Filename, bool Preview, SGPropertyNode& MetaMeta, simgear::HTTP::FileRequestRef filerequest)
{
SG_LOG(SG_SYSTEMS, SG_DEBUG, "loading Preview=" << Preview << " Filename=" << Filename);
@ -2026,14 +2026,16 @@ FGReplay::loadTape(const SGPath& Filename, bool Preview, SGPropertyNode& MetaMet
m_num_frames_multiplayer = 0;
m_continuous_indexing_in.open(Filename.str());
m_continuous_indexing_pos = in.tellg();
SG_LOG(SG_SYSTEMS, SG_DEBUG, "filerequest=" << filerequest);
SG_LOG(SG_SYSTEMS, SG_DEBUG, "filerequest=" << filerequest.get());
// Make an in-memory index of the recording.
if (filerequest) {
// Always call indexContinuousRecording once in case there is
// nothing to download.
indexContinuousRecording(nullptr, 1 /*Zero means EOF. */);
filerequest->setCallback(call_indexContinuousRecording, this);
filerequest->setCallback(
[this](const void* data, size_t numbytes)
{
indexContinuousRecording(data, numbytes);
}
);
}
else {
indexContinuousRecording(nullptr, 0);

View file

@ -133,7 +133,7 @@ public:
const SGPath& Filename,
bool Preview,
SGPropertyNode& MetaMeta,
simgear::HTTP::FileRequest* filerequest=nullptr
simgear::HTTP::FileRequestRef filerequest=nullptr
);
// Attempts to load Continuous recording header properties into

View file

@ -1595,7 +1595,7 @@ fgOptLoadTape(const char* arg)
//
struct DelayedTapeLoader : SGPropertyChangeListener {
DelayedTapeLoader( const char * tape, simgear::HTTP::FileRequest* filerequest) :
DelayedTapeLoader( const char * tape, simgear::HTTP::FileRequestRef filerequest) :
_tape(SGPath::fromUtf8(tape)),
_filerequest(filerequest)
{
@ -1627,11 +1627,11 @@ fgOptLoadTape(const char* arg)
}
private:
SGPath _tape;
simgear::HTTP::FileRequest* _filerequest;
simgear::HTTP::FileRequestRef _filerequest;
};
SGPropertyNode_ptr properties(new SGPropertyNode);
simgear::HTTP::FileRequest* filerequest = nullptr;
simgear::HTTP::FileRequestRef filerequest;
std::string path = urlToLocalPath(arg);
if (path == "") {
@ -1653,7 +1653,7 @@ fgOptLoadTape(const char* arg)
const char* url = arg;
FGHTTPClient* http = globals->add_new_subsystem<FGHTTPClient>();
http->init();
filerequest = new simgear::HTTP::FileRequest(url, path, true /*append*/);
filerequest.reset(new simgear::HTTP::FileRequest(url, path, true /*append*/));
long max_download_speed = fgGetLong("/sim/replay/download-max-bytes-per-sec");
if (max_download_speed != 0) {
// Can be useful to limite download speed for testing background