Application crashing because thread is running longer - is it possible
Application crashing because thread is running longer - is it possible
Hi, ALL,
I have an application that runs 1 thread where it connects to the DB and performs some queries.
When the application connects to the SQLite - everything works fine. No issues.
When the application connects thru the ODBC to the MS SQL Server - the application crashes about 70% of the time.
The thread is running longer when I am connected to SQL Server - that's the only difference.
I am using mutex to lock the shared data between the main (GUI) thread and my own (in both cases).
Thread do not access any GUI - it operates on the DB.
The only difference is the execution time in case of MS SQL vs SQLite.
One more thing - the crash always happens at the same place.
How to approach the debugging of such issues?
The versions:
Windows 8.1, MSVC 2017, wxWidgets 3.1.
Thank you.
I have an application that runs 1 thread where it connects to the DB and performs some queries.
When the application connects to the SQLite - everything works fine. No issues.
When the application connects thru the ODBC to the MS SQL Server - the application crashes about 70% of the time.
The thread is running longer when I am connected to SQL Server - that's the only difference.
I am using mutex to lock the shared data between the main (GUI) thread and my own (in both cases).
Thread do not access any GUI - it operates on the DB.
The only difference is the execution time in case of MS SQL vs SQLite.
One more thing - the crash always happens at the same place.
How to approach the debugging of such issues?
The versions:
Windows 8.1, MSVC 2017, wxWidgets 3.1.
Thank you.
Re: Application crashing because thread is running longer - is it possible
That's a strange combination, but if it always crashes at the same place, then that's the place to start.
Why does it crash there? If it's a bad pointer, why is it bad? Then work your way backwards from there.
Use the source, Luke!
Re: Application crashing because thread is running longer - is it possible
doublemax,
An assert message says "Bad HWND()... for a scrolled window"
And yes - it is strange, but this is the only difference between those 2 scenarios.
Thank you.
An assert message says "Bad HWND()... for a scrolled window"
And yes - it is strange, but this is the only difference between those 2 scenarios.
Thank you.
Re: Application crashing because thread is running longer - is it possible
That's not much to work with.
How is the window related to the DB access? What's its lifetime? If it's supposed to exist all the time, maybe something corrupted its memory?
How is the window related to the DB access? What's its lifetime? If it's supposed to exist all the time, maybe something corrupted its memory?
Use the source, Luke!
Re: Application crashing because thread is running longer - is it possible
doublemax,
It shuold.
But then why its not crashing/asserting for SQLite
It shuold.
But then why its not crashing/asserting for SQLite
Re: Application crashing because thread is running longer - is it possible
That's secondary.
At the time of the crash/assert, you should have a wxWindow pointer. Is it valid? If yes, does the wxWindow data look ok?
Use the source, Luke!
Re: Application crashing because thread is running longer - is it possible
doblemax,
At the time of the crash the window pointer is good and valid.
Inspecting the data seems good.
And as you can see - hWnd is NULL.
Thank you.
At the time of the crash the window pointer is good and valid.
Inspecting the data seems good.
And as you can see - hWnd is NULL.
Thank you.
Re: Application crashing because thread is running longer - is it possible
I really looks as if you're calling SetScrollPos too early. Set a breakpoint in the FieldWindow ctor and single-step through the code. Either the window is not fully constructed yet, or something deletes the HWND entry at some time.
Use the source, Luke!
Re: Application crashing because thread is running longer - is it possible
doublemax,
Sometimes I see "Handle is valid" and sometimes "No handle".
I just added those if() / else with the wxMessageBox for debugging purposes.
Besides, with SQLite everything works every time...
Thank you.
Code: Select all
Create( parent, wxID_ANY, pos == wxDefaultPosition ? wxDefaultPosition : pos, wxSize( width == -1 ? parent->GetSize().GetWidth() : width, 55 ), wxBORDER_SIMPLE | wxHSCROLL | wxALWAYS_SHOW_SB );
if( GetHwnd() )
wxMessageBox( "Handle is valid" );
else
wxMessageBox( "No handle" );
SetVirtualSize( 1000, 30 );
if( GetHwnd() )
wxMessageBox( "Hcoandle is valid" );
else
wxMessageBox( "No handle" );
SetScrollRate( 20, 0 );
SetCanvasColour( *wxWHITE );
I just added those if() / else with the wxMessageBox for debugging purposes.
Besides, with SQLite everything works every time...
Thank you.
Re: Application crashing because thread is running longer - is it possible
I'm afraid printf-type debugging won't be enough here, You need to catch the bug in the act by single-stepping through the code.
If the handle doesn't get overwritten somehow, maybe the window construction fails. This could happen if the parent is NULL, but then the GetSize() call would crash. What's the value of "width" when you get the assert?
If the handle doesn't get overwritten somehow, maybe the window construction fails. This could happen if the parent is NULL, but then the GetSize() call would crash. What's the value of "width" when you get the assert?
Yes, this is strange. Hopefully that gets explained when you find the reason for the issue.Besides, with SQLite everything works every time...
Use the source, Luke!
Re: Application crashing because thread is running longer - is it possible
doublemax,
On the failure the value f the width is -1.
Thank you.
On the failure the value f the width is -1.
Thank you.
Re: Application crashing because thread is running longer - is it possible
Code: Select all
FieldWindow::FieldWindow(wxWindow *parent, int type, const wxPoint &pos, int width) : wxSFShapeCanvas()
{
m_draggingField = nullptr;
m_isDragging = false;
Create( parent, wxID_ANY, pos == wxDefaultPosition ? wxDefaultPosition : pos,
wxSize( width == -1 ? parent->GetSize().GetWidth() : width, 55 ), wxBORDER_SIMPLE | wxHSCROLL | wxALWAYS_SHOW_SB );
Check if that changes anything.
Use the source, Luke!
Re: Application crashing because thread is running longer - is it possible
doublemax,
It is calling bool wxSFShapeCanvas::Create().
Thank you.
It is calling bool wxSFShapeCanvas::Create().
Thank you.
Re: Application crashing because thread is running longer - is it possible
Yeah, sorry. Guess i wasn't fully awake yet when i looked into the sources.
It still feels like an issue that can be found by setting a breakpoint at the FieldWindow ctor and single-stepping through the code. But it's always such a pain to build your project... I wish it was monolithic without the dozens of DLLs.
Use the source, Luke!
Re: Application crashing because thread is running longer - is it possible
doublemax,
I changed it so now it uses environment variable to locate wx.
All DLLs are building inside the executable directory. You just need to copy libmysql, libpq and VLD ones before building.
And to reproduce - install SQL Server if not already there and create a DB. Then make ODBC profile.
One other thing - an assert is not always happening...
Thank you.
I changed it so now it uses environment variable to locate wx.
All DLLs are building inside the executable directory. You just need to copy libmysql, libpq and VLD ones before building.
And to reproduce - install SQL Server if not already there and create a DB. Then make ODBC profile.
One other thing - an assert is not always happening...
Thank you.