Print Page | Close Window

Report Control crash when deleting items

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Report Control
Forum Description: Topics Related to Codejock Report Control
URL: http://forum.codejock.com/forum_posts.asp?TID=5315
Printed Date: 27 November 2024 at 8:20pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Report Control crash when deleting items
Posted By: JemeraldSoft
Subject: Report Control crash when deleting items
Date Posted: 18 October 2006 at 8:55am
Hi, I just started using the report control in the toolkit in my application but found some issues with it.

My application has some background thread that dynamically add/delete entries to/from the report control. However, sometimes the control crashes when items are deleted. Deletion are done using (index is a valid index):

m_lstAlarm.GetRecords()->RemoveAt(index);

If I run it in the debug mode, I can see that the crashing happens in one of the following places:
1. drawing routine
2. tooltip routine
3. on mouse move

seems like it''s trying to access the deleted record.

Did I do something wrong.



Replies:
Posted By: rmercer
Date Posted: 18 October 2006 at 3:21pm
Did you call Populate() after you removed the record?
 
m_lstAlarm.GetRecords()->RemoveAt(index);
m_lstAlarm.Populate();
 


Posted By: JemeraldSoft
Date Posted: 18 October 2006 at 6:33pm
Yes I do, is the following code right? or do I need to call Populate() after every RemoveAt():

            // delete the alarms associated with the disconnected server
            for(int i = 0; i < m_lstAlarm.GetRecords()->GetCount();)
            {
                CAlarmRecord * pRecord = (CAlarmRecord*)m_lstAlarm.GetRecords()->GetAt(i);
                if(pRecord && pRecord->m_iHostId == pHost->m_hostId)
                {
                    m_lstAlarm.GetRecords()->RemoveAt(i);
                }
                else
                    i++;
            }
            m_lstAlarm.Populate();



Posted By: JemeraldSoft
Date Posted: 18 October 2006 at 6:36pm
I also tried delete the row before deleting the record:
m_lstAlarm.GetRows()->RemoveAt(i);


Posted By: rmercer
Date Posted: 19 October 2006 at 10:50am
Originally posted by JemeraldSoft JemeraldSoft wrote:

I also tried delete the row before deleting the record:
m_lstAlarm.GetRows()->RemoveAt(i);
I don't see anything wrong with your code, however I just noticed that you mentioned this is running in a seperate thread.  I would guess that's where your issue is at.
 
I've ran into this in the past where a thread removes records while the window thread is trying to process messages and is getting data that no longer exists.
 
You will probably need to do your removes using a custom windows message or figure out a way to lock the control from updating while you're making your changes.
 
To test the idea, can you just setup a WM_TIMER handler to run the code your thread would normally execute?  Just fire up the timer to run every 500ms or something.  I wouldn't recommend this as your actual solution, but it's a good way to confirm what's going on since everything will be processed in the same window thread.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net