Im trying to debug a crashing thread, but I cant seem to determine what is causing the crash. (Im using an older version of Real Studio, btw)
In this window, I have a listbox which needs to list details from many files dropped on it. The process which extracts the data from the files can take a while, so its called from a thread subclass to keep the interface responsive, and display a counter of the current file. Ive added a constant constBYPASS_THREAD to the window, which allows me to bypass using the thread (the method executed by the thread is executed in the main thread instead), and that works without crashing (although the interface is obviously locked up while it processes all of the files). When the thread is used, sometimes the crash comes while it’s processing the files, and other times, it finishes processing but crashes when that window is closed.
When files/folders are dropped on the listbox, it passes those to a recursive method AddFolderItem, which adds them to the threads array, then runs the thread (If the thread is bypassed, it instead starts the timer which finalizes the process)
[code]// DROP OBJECT CODE
Do
If Obj.FolderItemAvailable Then
AddFolderItem(obj.FolderItem)
End if
Loop Until Not Obj.NextItem
if constBYPASS_THREAD then
// Thread has been skipped, Finalize
timEndThread.Mode = timer.ModeSingle
timEndThread.Enabled = true
else
// Run thread
Self.threadAddFiles.Run
end if
[/code]
The AddFolderItem method recurses though any subdirectories, and adds the files to the thread (or, if bypassed, directly processes the files)
// AddFolderItem CODE
if NOT(f is nil) then
if f.Directory then
// Run AddFolderItem on each child - recursive code omitted for brevity
else
if f.Visible then
if constBYPASS_THREAD then
ProcessFile(f) // This is the same method call that the thread uses
else
self.threadAddFiles.FolderItem = f
end if
end if
end if
end if
The thread has 2 events, When it runs, it loops through all files that have been added to its array, and calls the ProcessFile method on each, then raises a Complete event.
// threadAddFiles ACTION
ProcessFile(f)
[code] // threadAddFiles COMPLETE
self.mFileCount = me.Count
self.mFileIndex = 0
timEndThread.Mode = timer.ModeSingle
timEndThread.Enabled = true
[/code]
The ProcessFile method does all of the heavy lifting, and does not access any user interface elements (I’m double and triple checking that now, as it’s a lot of code, which calls a few other methods, and uses another class instance to parse the file data). At the end, it creates an instance of a class which contains all of the collected data for the file, and passes that to an AddFiles Timer, which adds a row to the listbox and populates the data.
[code]//AddFiles TIMER CODE
Dim currentRow as integer
self.mFileIndex = self.mFileIndex + 1
Self.lblFileProcessing.Visible = true
Self.lblFileProcessing.Caption = "Processing file " + str(self.mFileIndex) + " of " + str(Self.mFileCount) + “…”
’ Add image
if NOT (imageData is nil) then
Self.lbxFileList.AddRow("")
currentRow = Self.lbxFileList.LastIndex
Self.lbxFileList.RowTag(currentRow) = imageData
Call setRowData(currentRow)
end if[/code]
At one point, I found that I had code within the ‘ProcessFile’ method which read the values of a few checkboxes (but didn’t update anything in the user interface). I have since made sure that all of these were removed, and changes to the UI elements set private properties of the window, which are accessed within the method. I had hoped that would fix the crashing issue, but it did not.
I can post crash logs (Mac OS 10.10.5); I’m not sure what parts are relevant (they are quite long), and they don’t seem to have any consistency. I didn’t see anything that I could tell indicated what part of the code was the cause.
Does anyone have any suggestions on where I can look for the cause of this crash?