Fwd: bug in nShaderParams::Clear ?

View: New views
2 Messages — Rating Filter:   Alert me  

Parent Message unknown Fwd: bug in nShaderParams::Clear ?

by ZHANG Zikai :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

hi,

in nebula2\code\nebula2\inc\gfx2\nshaderparams.h
the function nShaderParams::Clear() may cause crash:

inline
void
nShaderParams::Clear()
{
   int i;
   for (i = 0; i < nShaderState::NumParameters; i++)
   {
       this->paramIndex[i] = -1;
   }
   this->paramArray.Reset();
}

the paramArray is defined like this

  nArray<ParamAndArg> paramArray;

nArray::Reset() only set the numElements to 0, it will not call destructor.
Thus ParamAndArg::arg which contains a nRef<nTexture2> tex will not be
destroyed correctly, and referenecd count of the nTexture2 will go
wrong.

luckyly, the nArray free its elements at its destructor and calls the
~nRef, the symptom will not show up then.

better change the nShaderParams::Clear() to
inline
void
nShaderParams::Clear()
{
   int i;
   for (i = 0; i < nShaderState::NumParameters; i++)
   {
       this->paramIndex[i] = -1;
   }
   this->paramArray.Clear();
}

and use a corrected nArray. I'll send a nArray patch to pangu.


Regards,
kaikai

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642

*** NOTE: To reply to the list use "reply to all",  ***
***       to reply direct to the sender use "reply" ***
_______________________________________________
Nebuladevice-discuss mailing list
Nebuladevice-discuss@...
https://lists.sourceforge.net/lists/listinfo/nebuladevice-discuss

Re: Fwd: bug in nShaderParams::Clear ?

by M.A. Garcias :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Calling Clear() on an array releases the memory and more memory is
allocated for new elements to be added. Resetting shader params looks
like something that can happen often, so doing this is not a good idea.
Manually invalidating the reference would be better.
By the way, remember that the nref<nTexture2> arguments are soft
references, therefore the refcount for the texture is not incremented.

ZHANG Zikai wrote:

> hi,
>
> in nebula2\code\nebula2\inc\gfx2\nshaderparams.h
> the function nShaderParams::Clear() may cause crash:
>
> inline
> void
> nShaderParams::Clear()
> {
>    int i;
>    for (i = 0; i < nShaderState::NumParameters; i++)
>    {
>        this->paramIndex[i] = -1;
>    }
>    this->paramArray.Reset();
> }
>
> the paramArray is defined like this
>
>   nArray<ParamAndArg> paramArray;
>
> nArray::Reset() only set the numElements to 0, it will not call destructor.
> Thus ParamAndArg::arg which contains a nRef<nTexture2> tex will not be
> destroyed correctly, and referenecd count of the nTexture2 will go
> wrong.
>
> luckyly, the nArray free its elements at its destructor and calls the
> ~nRef, the symptom will not show up then.
>
> better change the nShaderParams::Clear() to
> inline
> void
> nShaderParams::Clear()
> {
>    int i;
>    for (i = 0; i < nShaderState::NumParameters; i++)
>    {
>        this->paramIndex[i] = -1;
>    }
>    this->paramArray.Clear();
> }
>
> and use a corrected nArray. I'll send a nArray patch to pangu.

--

maGarcias | tragnarionStudios

lists@...


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

*** NOTE: To reply to the list use "reply to all",  ***
***       to reply direct to the sender use "reply" ***
_______________________________________________
Nebuladevice-discuss mailing list
Nebuladevice-discuss@...
https://lists.sourceforge.net/lists/listinfo/nebuladevice-discuss