]> git.tdb.fi Git - libs/gl.git/blobdiff - source/texture2d.cpp
Ensure that mapped memory is unmapped in Texture2D::AsyncLoader
[libs/gl.git] / source / texture2d.cpp
index cee932f7231e9fb23adcfb4ce86ba28e736dd17a..1e8e3db8fefe659a8b46390719e14177c29e5315 100644 (file)
@@ -26,6 +26,7 @@ private:
 
 public:
        AsyncLoader(Texture2D &, IO::Seekable &);
+       ~AsyncLoader();
 
        virtual bool needs_sync() const;
        virtual bool process();
@@ -165,7 +166,7 @@ void Texture2D::image(const Graphics::Image &img, unsigned lv, bool from_buffer)
        PixelStore pstore = PixelStore::from_image(img);
        BindRestore _bind_ps(pstore);
 
-       image(0, from_buffer ? 0 : img.get_data());
+       image(0, from_buffer ? 0 : img.get_pixels());
 }
 
 unsigned Texture2D::get_n_levels() const
@@ -249,6 +250,12 @@ Texture2D::AsyncLoader::AsyncLoader(Texture2D &t, IO::Seekable &i):
        phase(0)
 { }
 
+Texture2D::AsyncLoader::~AsyncLoader()
+{
+       if(mapped_address)
+               pixel_buffer.unmap();
+}
+
 bool Texture2D::AsyncLoader::needs_sync() const
 {
        return phase%2;
@@ -270,12 +277,13 @@ bool Texture2D::AsyncLoader::process()
        }
        else if(phase==2)
        {
-               const char *data = reinterpret_cast<const char *>(image.get_data());
+               const char *data = reinterpret_cast<const char *>(image.get_pixels());
                copy(data, data+n_bytes, mapped_address);
        }
        else if(phase==3)
        {
                Bind _bind_buf(pixel_buffer, PIXEL_UNPACK_BUFFER);
+               mapped_address = 0;
                if(!pixel_buffer.unmap())
                {
                        phase = 1;