[2.2] assert in Image2 uploadTo Topic is solved

Discussion area about developing with Ogre2 branches (2.1, 2.2 and beyond)
Post Reply
dermont
Orc Shaman
Posts: 782
Joined: Thu Dec 09, 2004 2:51 am
x 9

[2.2] assert in Image2 uploadTo

Post by dermont » Fri Mar 15, 2019 6:10 am

Linux, OpenGL, NVidia 418.31.03

I'm attempting to create a textureArray(Type2DArray) to use with a v1 Renderable (entity) and legacy material.

When uploading an image with slices i.e. "image.uploadTo(texture,....." I encounter the following assert:

Code: Select all

scaling: /media/sdb5/Libraries/OGRE/src/v2-2/OgreMain/src/OgreStagingTexture.cpp:130: virtual void Ogre::StagingTexture::upload(const Ogre::TextureBox&, Ogre::TextureGpu*, Ogre::uint8, const Ogre::TextureBox*, const Ogre::TextureBox*, bool): Assertion `!dstBox || fullDstTextureBox.fullyContains( *dstBox )' failed.
Aborted (core dumped)
Manually copying across the image slice works OK, so I'm not sure if this is the correct approach in creating a texture array.

This is example code:

Code: Select all

    void saveSlice(const Ogre::String& name, TextureBox& texBox, Ogre::PixelFormatGpu pixelFormat, uint32 slice, uint32 numSlices, TextureTypes::TextureTypes texType)
    {
        Image2 sliceImageTest;
        sliceImageTest._setAutoDelete(false);
        sliceImageTest.loadDynamicImage( texBox.at( 0, 0, slice ), texBox.width, texBox.height*numSlices, 
                                         1u, texType, pixelFormat, false, 1 );
        sliceImageTest.save(name,0,0);
    }


    virtual void createScene(void) {

        uint32 numSlices=4;

        Ogre::Image2 baseImage;
        baseImage.load("1d_debug.png",Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME);
        baseImage.save("./Data.png",0,0);

        Ogre::Image2 sliceImage;
        sliceImage.loadDynamicImage( baseImage.getData(0).data, baseImage.getWidth(), baseImage.getHeight()/numSlices, numSlices,
                                   Ogre::TextureTypes::Type2DArray, baseImage.getPixelFormat(),
                                   false, 1 );
        assert( sliceImage.getNumSlices()>1);
        TextureBox texBox = sliceImage.getData(0);

        // save slice2 
        saveSlice("./2DArray_Slice2.png", texBox, sliceImage.getPixelFormat(), 2 ,1,Ogre::TextureTypes::Type2D);

        // save all image slices(vertical) 
        saveSlice("./2DArray_SliceAll.png", texBox, sliceImage.getPixelFormat(), 0 ,sliceImage.getNumSlices(),Ogre::TextureTypes::Type2D);

        Ogre::TextureGpuManager *textureManager = Ogre::Root::getSingletonPtr()->getRenderSystem()->getTextureGpuManager();

        Ogre::TextureGpu* texture = textureManager->createTexture("TestArray",
                                            Ogre::GpuPageOutStrategy::Discard, //AlwaysKeepSystemRamCopy,
                                            Ogre::TextureFlags::ManualTexture, 
                                            Ogre::TextureTypes::Type2DArray, 
                                            Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME );

        texture->setPixelFormat( sliceImage.getPixelFormat() );
        texture->setNumMipmaps(  1 );
        texture->setResolution(  sliceImage.getWidth(), sliceImage.getHeight(), sliceImage.getNumSlices());

        if (texture->getResidencyStatus() != Ogre::GpuResidency::Resident) {
             texture->_transitionTo( Ogre::GpuResidency::Resident, (Ogre::uint8*)0);
        }
        texture->_setNextResidencyStatus( Ogre::GpuResidency::Resident );

        // crash        
        assert( sliceImage.getNumMipmaps()==1);
        assert( sliceImage.getNumSlices()==4);
        assert( sliceImage.getWidth()==128);
        assert( sliceImage.getHeight()==32);
        assert( sliceImage.getBytesPerRow(0)==4*128);
        assert( sliceImage.getBytesPerImage(0)==4*128*32);
        assert( sliceImage.getSizeBytes()==16384*4);

        //sliceImage.uploadTo(texture,0,0,0,0);
        //sliceImage.uploadTo(texture,0,0,0,numSlices);

        // OK
        Ogre::StagingTexture* stagingTexture = 0;
        stagingTexture = textureManager->getStagingTexture( sliceImage.getWidth(), sliceImage.getHeight(),
                                                            1u, sliceImage.getNumSlices(),
                                                            sliceImage.getPixelFormat()); //, 100u );
        stagingTexture->startMapRegion();
        Ogre::TextureBox dstTexBox = stagingTexture->mapRegion( sliceImage.getWidth(), sliceImage.getHeight(),
                                                                1u, sliceImage.getNumSlices(),
                                                                sliceImage.getPixelFormat() );

        TextureBox srcTexBox = sliceImage.getData(0);

        for (int i=0;i<sliceImage.getNumSlices(); i++) {
            void *dstData  = dstTexBox.at( 0, 0, i );
            void *srcData  = srcTexBox.at( 0, 0, i );
            memcpy( dstData, srcData, srcTexBox.bytesPerImage );
        }
        stagingTexture->stopMapRegion();
        stagingTexture->upload( dstTexBox,texture, 0,0, 0, false );
        textureManager->removeStagingTexture( stagingTexture );
        stagingTexture = 0;
        texture->notifyDataIsReady();

        Image2 imgConvert;
        imgConvert.convertFromTexture( texture, 0, 0, true );
        TextureBox texBoxConvert = imgConvert.getData(0);

        // save image slice 2
        saveSlice("./2DArray_Slice2_C.png", texBoxConvert, imgConvert.getPixelFormat(), 2 ,1,Ogre::TextureTypes::Type2D);

        // save all image slices(vertical) 
        saveSlice("./2DArray_SliceAll_C.png", texBoxConvert, imgConvert.getPixelFormat(), 0 ,imgConvert.getNumSlices(),Ogre::TextureTypes::Type2D);

    }    

0 x

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 4120
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 245
Contact:

Re: [2.2] assert in Image2 uploadTo

Post by dark_sylinc » Fri Mar 15, 2019 3:09 pm

I can't see anything outstanding wrong yet with the code you posted, but I suspect you have memory corruption, because the code you posted calls StagingTexture::upload with dstBox=nullptr yet the assert is triggering:

Code: Select all

assert( !dstBox || fullDstTextureBox.fullyContains( *dstBox ) );
That is impossible unless the stack is corrupted or the DLL is out of date (i.e. it isn't the build your headers are being compiled with).
0 x

dermont
Orc Shaman
Posts: 782
Joined: Thu Dec 09, 2004 2:51 am
x 9

Re: [2.2] assert in Image2 uploadTo

Post by dermont » Fri Mar 15, 2019 3:55 pm

Sorry if my post wasn't clear, the stagingTexture->upload works fine. The assert is raised when I try to upload to the texture directly from an image with slices.

Image2::uploadTo( TextureGpu *texture, uint8 minMip, uint8 maxMip,
uint32 dstZorSliceStart=0u, uint32 srcDepthOrSlices=0u );


The above works for a texture with a single slice, maybe I'm misunderstanding it's usage.

Thanks.
0 x

dermont
Orc Shaman
Posts: 782
Joined: Thu Dec 09, 2004 2:51 am
x 9

Re: [2.2] assert in Image2 uploadTo

Post by dermont » Fri Mar 15, 2019 6:18 pm

I compared the Image2::uploadTo code against my code, the Texture box depth always appears to be the number of slices (line 437), changing as follows resolves the issue , not sure if it's correct.

Code: Select all

    void Image2::uploadTo( TextureGpu *texture, uint8 minMip, uint8 maxMip,
                           uint32 dstZorSliceStart, uint32 srcDepthOrSlices )
    {
.....
        for( size_t i=minMip; i<=maxMip; ++i )
        {
            TextureBox box = getData( static_cast<uint8>( i ) );
           //box.depth       = mTextureType == TextureTypes::Type3D ? srcDepthOrSlices : box.numSlices;
            box.depth       = mTextureType == TextureTypes::Type3D ? srcDepthOrSlices : 1u;
This is the backtrace:

Code: Select all

#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#1  0x00007ffff6aa1535 in __GI_abort () at abort.c:79
#2  0x00007ffff6aa140f in __assert_fail_base (
    fmt=0x7ffff6c2d858 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", 
    assertion=0x7ffff7d4bef0 "!dstBox || fullDstTextureBox.fullyContains( *dstBox )", 
    file=0x7ffff7d4bb80 "/media/sdb5/Libraries/OGRE/src/v2-2/OgreMain/src/OgreStagingTexture.cpp", line=130, function=<optimized out>) at assert.c:92
#3  0x00007ffff6ab1142 in __GI___assert_fail (
    assertion=0x7ffff7d4bef0 "!dstBox || fullDstTextureBox.fullyContains( *dstBox )", 
    file=0x7ffff7d4bb80 "/media/sdb5/Libraries/OGRE/src/v2-2/OgreMain/src/OgreStagingTexture.cpp", line=130, 
    function=0x7ffff7d4c2e0 <Ogre::StagingTexture::upload(Ogre::TextureBox const&, Ogre::TextureGpu*, unsigned char, Ogre::TextureBox const*, Ogre::TextureBox const*, bool)::__PRETTY_FUNCTION__> "virtual void Ogre::StagingTexture::upload(const Ogre::TextureBox&, Ogre::TextureGpu*, Ogre::uint8, const Ogre::TextureBox*, const Ogre::TextureBox*, bool)") at assert.c:101
#4  0x00007ffff7b61f20 in Ogre::StagingTexture::upload (this=0x555555f73c10, 
    srcBox=..., dstTexture=0x555555be17b0, mipLevel=0 '\000', 
    cpuSrcBox=0x7fffffff9480, dstBox=0x7fffffff5440, skipSysRamCopy=false)
    at /media/sdb5/Libraries/OGRE/src/v2-2/OgreMain/src/OgreStagingTexture.cpp:130
--Type <RET> for more, q to quit, c to continue without paging--
#5  0x00007ffff21aad6d in Ogre::GL3PlusStagingTexture::upload (
    this=0x555555f73c10, srcBox=..., dstTexture=0x555555be17b0, 
    mipLevel=0 '\000', cpuSrcBox=0x7fffffff9480, dstBox=0x7fffffff5440, 
    skipSysRamCopy=false)
    at /media/sdb5/Libraries/OGRE/src/v2-2/RenderSystems/GL3Plus/src/OgreGL3PlusStagingTexture.cpp:153
#6  0x00007ffff7899329 in Ogre::Image2::uploadTo (this=0x7fffffffd530, 
    texture=0x555555be17b0, minMip=0 '\000', maxMip=0 '\000', 
    dstZorSliceStart=0, srcDepthOrSlices=4)
    at /media/sdb5/Libraries/OGRE/src/v2-2/OgreMain/src/OgreImage2.cpp:498
#7  0x0000555555573593 in SampleDemo::createScene (this=0x5555555b7e00)
    at /media/sdb15/Development/OGRE/v2-2/VIDEO/ffmpegscalingTest/entitytexarray.cpp:800
#8  0x000055555556cdac in SampleApplication::start (this=0x5555555b7e00)
    at /media/sdb15/Development/OGRE/v2-2/VIDEO/ffmpegscalingTest/SampleApplication.h:142
#9  0x000055555556bcf3 in main ()
    at /media/sdb15/Development/OGRE/v2-2/VIDEO/ffmpegscalingTest/entitytexarray.cpp:1064
(gdb) 

    void Image2::uploadTo( TextureGpu *texture, uint8 minMip, uint8 maxMip,
                           uint32 dstZorSliceStart, uint32 srcDepthOrSlices )
0 x

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 4120
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 245
Contact:

Re: [2.2] assert in Image2 uploadTo

Post by dark_sylinc » Fri Mar 15, 2019 7:27 pm

This indeed looks like a bug rather than bad usage
0 x

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 4120
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 245
Contact:

Re: [2.2] assert in Image2 uploadTo

Post by dark_sylinc » Mon Mar 18, 2019 12:09 am

Fix arrived.

It was indeed a bug in the line you pointed out, but your solution was slightly wrong.

Thanks for the report!

Cheers
Matias
0 x

dermont
Orc Shaman
Posts: 782
Joined: Thu Dec 09, 2004 2:51 am
x 9

Re: [2.2] assert in Image2 uploadTo

Post by dermont » Mon Mar 18, 2019 3:13 am

Thank you.
0 x

Post Reply