Jump to content
Software FX Community

Annotation List Remove BUG!


User (Legacy)

Recommended Posts

In the annotation extension, how do you remove more than one item from the

annotation list?

I need to remove all items that have non-zero "tag" data. When I loop

through the list, I can delete one item, but when I get the next item to

check the tag data, I get an exception from the annotation dll.

I try the following:

{

long alistcnt = m_pAnnList->GetCount();

for( long i = alistcnt-1 ; i >= 0 ; i-- ) // count down

//for( long i = 0 ; i < alistcnt ; i++ ) // count up

{

long tag;

{

IAnnObjectPtr pAObj;

pAObj = m_pAnnList->Item( i ); // get an item

tag = pAObj->GetTag(); // get item tag

}

if( tag & RemoveMe )

{ // tag has some data in it, remove it

m_pAnnList->Remove( i );

// HERE COMES A BUG CRASH

IAnnObjectPtr p;

if( alistcnt > 0 )

// get another item

p = m_pAnnList->Item( (long)(alistcnt - 1) ); // BUG CRASH BUG !

}

}

}

Link to comment
Share on other sites

  • 5 months later...

was this ever fixed/replied to?

I have the same problem in VB.

Thanks,

Paul

In article <kaidu9yr8GA.1696@webserver1.softwarefx.com>, Pedro Ramirez

wrote:

> In the annotation extension, how do you remove more than one item from

> the annotation list? I need to remove all items that have non-zero "tag"

> data. When I loop through the list, I can delete one item, but when I

> get the next item to check the tag data, I get an exception from the

> annotation dll.

>

> I try the following:

>

> {

> long alistcnt = m_pAnnList->GetCount(); for( long i = alistcnt-1 ; i >=

> 0 ; i-- ) // count down

> //for( long i = 0 ; i < alistcnt ; i++ ) // count up

> {

> long tag;

> {

> IAnnObjectPtr pAObj;

>

> pAObj = m_pAnnList->Item( i ); // get an item tag = pAObj->GetTag();

> // get item tag

> }

> if( tag & RemoveMe )

> { // tag has some data in it, remove it

> m_pAnnList->Remove( i );

>

> // HERE COMES A BUG CRASH

> IAnnObjectPtr p; if( alistcnt > 0 )

> // get another item

> p = m_pAnnList->Item( (long)(alistcnt - 1) ); // BUG CRASH BUG !

> }

> }

> }

>

>

>

Link to comment
Share on other sites

Pedro,

It looks to me like you are actually accessing an element that no longer

exists.

At the beginning of the scope you the count of values in the list, say you

get 10.

long alistcnt = m_pAnnList->GetCount();

Then you loop though the list until you find something you want deleted

pAObj = m_pAnnList->Item( i ); // get an item

And delete it if you need to

if( tag & RemoveMe )

{ // tag has some data in it, remove it

m_pAnnList->Remove( i );

That's all well and good, here's the problem...

You check alistcnt to see if any values remain, but you never update the

value.

if( alistcnt > 0 )

// get another item

Since you've just removed one of the elements, the new size is (alistcnt -

1), so the last entry would be m_pAnnList->Item( (long)(alistcnt - 2)).

OR, you could just update the value with alistcnt = m_pAnnList->GetCount();

p = m_pAnnList->Item( (long)(alistcnt - 1) ); // BUG CRASH BUG !

That's the reason for the problem in C++. It actually would probably throw

an exception that you could catch in the debugger or with a try{

blah }catch(...) expression.

Eric

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...