Jump to content
Software FX Community

Annotation List Remove BUG!


User (Legacy)
 Share

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...