#include <simgear/scene/util/OsgMath.hxx>
#include <simgear/scene/util/parse_color.hxx>
#include <simgear/misc/sg_path.hxx>
-#include <simgear/io/HTTPClient.hxx>
#include <osg/Array>
#include <osg/Geometry>
//----------------------------------------------------------------------------
Image::~Image()
{
-
+ if( _http_request )
+ _http_request->abort("image destroyed");
}
//----------------------------------------------------------------------------
if( name == "file" )
SG_LOG(SG_GL, SG_WARN, "'file' is deprecated. Use 'src' instead");
+ // Abort pending request
+ if( _http_request )
+ {
+ _http_request->abort("setting new image");
+ _http_request.reset();
+ }
+
static const std::string PROTOCOL_SEP = "://";
std::string url = child->getStringValue(),
else if( protocol == "http" || protocol == "https" )
// TODO check https
{
- Canvas::getSystemAdapter()
+ _http_request =
+ Canvas::getSystemAdapter()
->getHTTPClient()
->load(url)
+ // TODO handle capture of 'this'
->done(this, &Image::handleImageLoadDone);
}
else
//----------------------------------------------------------------------------
void Image::handleImageLoadDone(HTTP::Request* req)
{
+ // Ignore stale/expired requests
+ if( _http_request != req )
+ return;
+ _http_request.reset();
+
if( req->responseCode() != 200 )
{
SG_LOG(SG_IO, SG_WARN, "failed to download '" << req->url() << "': "
#include "CanvasElement.hxx"
#include <simgear/canvas/canvas_fwd.hxx>
+#include <simgear/io/HTTPClient.hxx>
#include <simgear/misc/CSSBorder.hxx>
#include <osg/Texture2D>
osg::ref_ptr<osg::Texture2D> _texture;
// TODO optionally forward events to canvas
CanvasWeakPtr _src_canvas;
+ HTTP::Request_ptr _http_request;
osg::ref_ptr<osg::Geometry> _geom;
osg::ref_ptr<osg::DrawArrays>_prim;
{
_responseStatus = code;
_responseReason = reason;
- setReadyState(FAILED);
+
+ if( !isComplete() )
+ setReadyState(FAILED);
}
//------------------------------------------------------------------------------
//----------------------------------------------------------------------------
void Request::abort(const std::string& reason)
{
- if( isComplete() )
- return;
-
setFailure(-1, reason);
_willClose = true;
}