Ogre::Ocean creation bugfix

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


Lax
Orc Shaman
Posts: 711
Joined: Mon Aug 06, 2007 12:53 pm
Location: Saarland, Germany
x 75

Ogre::Ocean creation bugfix

Post by Lax »

Hi @dark_sylinc,

I see you are more active in Ogre-Next. Welcome back. A while ago I posted this:

in order that Ocean does not crash at the beginning, if there is no terra. In OgreHlmsPbs:

Code: Select all

uint32 HlmsPbs::fillBuffersFor( const HlmsCache *cache, const QueuedRenderable &queuedRenderable,
                                bool casterPass, uint32 lastCacheHash, CommandBuffer *commandBuffer,
                                bool isV1 )
{
    assert( dynamic_cast<const HlmsPbsDatablock *>( queuedRenderable.renderable->getDatablock() ) );
    const HlmsPbsDatablock *datablock =
        static_cast<const HlmsPbsDatablock *>( queuedRenderable.renderable->getDatablock() );

if( OGRE_EXTRACT_HLMS_TYPE_FROM_CACHE_HASH( lastCacheHash ) != mType )
{
    if( mCurrentPassBuffer == 0 )
        return 0;

...
}

This is necessary:

Code: Select all

if( mCurrentPassBuffer == 0 )
return 0;

Else i get early crashes.

Can you add that? For now i use a local patched version of Ogre-Next, so that I can have Ocean without terra. But it would be nice, to just have that check in Ogre-Next. It does not corrupt anything, but just makes Ogre-Next more save for developers.

Best Regards
Lax

http://www.lukas-kalinowski.com/Homepage/?page_id=1631
Please support Second Earth Technic Base built of Lego bricks for Lego ideas: https://ideas.lego.com/projects/81b9bd1 ... b97b79be62

User avatar
sercero
Bronze Sponsor
Bronze Sponsor
Posts: 549
Joined: Sun Jan 18, 2015 4:20 pm
Location: Buenos Aires, Argentina
x 204

Re: Ogre::Ocean creation bugfix

Post by sercero »

Hello,

Why don't you submit a pull request?

Lax
Orc Shaman
Posts: 711
Joined: Mon Aug 06, 2007 12:53 pm
Location: Saarland, Germany
x 75

Re: Ogre::Ocean creation bugfix

Post by Lax »

Ok, of course. I did it that way. Thanks for the clue.

http://www.lukas-kalinowski.com/Homepage/?page_id=1631
Please support Second Earth Technic Base built of Lego bricks for Lego ideas: https://ideas.lego.com/projects/81b9bd1 ... b97b79be62

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

Re: Ogre::Ocean creation bugfix

Post by dark_sylinc »

In vanilla HlmsPbs, mCurrentPassBuffer will and must never be 0 by the time we reach there.

If you want to simply return (which basically aborts HlmsPbs::fillBuffersFor) why can't this be solved by doing:

Code: Select all

uint32 HlmsOcean::fillBuffersFor(...)
{
    if( OGRE_EXTRACT_HLMS_TYPE_FROM_CACHE_HASH( lastCacheHash ) == mType || mCurrentPassBuffer != 0 )
   {
      HlmsPbs::fillBuffersFor( ... );
   }
}

Which basically the custom implementation accommodates to what the base logic expects.

Am I missing something?

Lax
Orc Shaman
Posts: 711
Joined: Mon Aug 06, 2007 12:53 pm
Location: Saarland, Germany
x 75

Re: Ogre::Ocean creation bugfix

Post by Lax »

Hi,

i have already such guards:

Code: Select all

uint32 HlmsOcean::fillBuffersFor(const HlmsCache* cache,
    const QueuedRenderable& queuedRenderable,
    bool casterPass, uint32 lastCacheHash,
    CommandBuffer* commandBuffer, bool isV1)
{
    if (mBufferSize == 0)
        return 0;

if (mCurrentPassBuffer == 0)
{
    // Return lastCacheHash to indicate we couldn't process this renderable
    // It will be retried on the next frame when buffers are ready
    return lastCacheHash;
}

const HlmsOceanDatablock* datablock =
    static_cast<const HlmsOceanDatablock*>(queuedRenderable.renderable->getDatablock());

// Changed HLMS type? Rebind everything
if (OGRE_EXTRACT_HLMS_TYPE_FROM_CACHE_HASH(lastCacheHash) != mType)
{
   

    // 1. Bind pass buffer (slot 0)
    ConstBufferPacked* passBuffer = mPassBuffers[mCurrentPassBuffer - 1];
    *commandBuffer->addCommand<CbShaderBuffer>() = CbShaderBuffer(
        VertexShader, 0, passBuffer, 0, (uint32)passBuffer->getTotalSizeBytes());
    *commandBuffer->addCommand<CbShaderBuffer>() =
        CbShaderBuffer(PixelShader, 0, passBuffer, 0, (uint32)passBuffer->getTotalSizeBytes());

    uint32 constBufferSlot = 3u;

    // 2. Bind light buffers (slots 3,4,5)
    if (mUseLightBuffers)
    {
        ConstBufferPacked* light0Buffer = mLight0Buffers[mCurrentPassBuffer - 1];
        *commandBuffer->addCommand<CbShaderBuffer>() = CbShaderBuffer(
            VertexShader, 3, light0Buffer, 0, (uint32)light0Buffer->getTotalSizeBytes());
        *commandBuffer->addCommand<CbShaderBuffer>() = CbShaderBuffer(
            PixelShader, 3, light0Buffer, 0, (uint32)light0Buffer->getTotalSizeBytes());

        ConstBufferPacked* light1Buffer = mLight1Buffers[mCurrentPassBuffer - 1];
        *commandBuffer->addCommand<CbShaderBuffer>() = CbShaderBuffer(
            VertexShader, 4, light1Buffer, 0, (uint32)light1Buffer->getTotalSizeBytes());
        *commandBuffer->addCommand<CbShaderBuffer>() = CbShaderBuffer(
            PixelShader, 4, light1Buffer, 0, (uint32)light1Buffer->getTotalSizeBytes());

        ConstBufferPacked* light2Buffer = mLight2Buffers[mCurrentPassBuffer - 1];
        *commandBuffer->addCommand<CbShaderBuffer>() = CbShaderBuffer(
            VertexShader, 5, light2Buffer, 0, (uint32)light2Buffer->getTotalSizeBytes());
        *commandBuffer->addCommand<CbShaderBuffer>() = CbShaderBuffer(
            PixelShader, 5, light2Buffer, 0, (uint32)light2Buffer->getTotalSizeBytes());

        constBufferSlot = 6u;
    }
    ...

But it does crash, before even that can be called. It has something todo with Terra and Ocean together. So if i at early stage in Ogre-Nextl, if this code is set:

Code: Select all

if( mCurrentPassBuffer == 0 )
return 0;

Then no crash and all can be created an loaded. Its the only way i see how to get it working and its the most dynamic way. I have NOWA-Design editor: So i add stuff at runtime, remove at runtime, so this:

Code: Select all

if( mCurrentPassBuffer == 0 )
return 0;

Which is also called at runtime is truly necessary!

Best Regards
Lax

http://www.lukas-kalinowski.com/Homepage/?page_id=1631
Please support Second Earth Technic Base built of Lego bricks for Lego ideas: https://ideas.lego.com/projects/81b9bd1 ... b97b79be62