wxThread->Delete() - Exception thrown: read access violation. Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
User avatar
doublemax
Moderator
Moderator
Posts: 15170
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxThread->Delete() - Exception thrown: read access violation.

Post by doublemax » Tue Jul 21, 2020 5:27 pm

Is there a reason you cant take a look with wxListCtrl included ..as you say its not part of the problem, so why remove it?
The more code i have to read, understand and dig through, the less motivated i am to do so. I might look into it, but it will take longer.
Use the source, Luke!

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2566
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxThread->Delete() - Exception thrown: read access violation.

Post by PB » Tue Jul 21, 2020 5:34 pm

And the more irrelevant the code is there, the higher the noise-to-signal ratio, which makes finding a bug more difficult.

User avatar
doublemax
Moderator
Moderator
Posts: 15170
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxThread->Delete() - Exception thrown: read access violation.

Post by doublemax » Tue Jul 21, 2020 7:22 pm

I just ran your unmodified sample and could not get it to crash with any of the four methods.

Is the info from your footer correct and you're using wxWidgets 3.0.5? If yes, please try again with a current version.
Use the source, Luke!

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2566
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxThread->Delete() - Exception thrown: read access violation.

Post by PB » Tue Jul 21, 2020 7:57 pm

I also could not reproduce the issue with the OP's code with none of the 4 methods described, using recentish master.

I then tried the same code with 3.0.5 and succeeded to make it crash on my first try just by clicking on "Start thread" rapidly several times.

I did not investigate the issue any further and would also recommend trying with the wxWidgets master or at least v3.1.3. BTW, v3.1.4 should be officially released this week.

tuk1
Experienced Solver
Experienced Solver
Posts: 95
Joined: Sun Oct 08, 2017 9:36 am

Re: wxThread->Delete() - Exception thrown: read access violation.

Post by tuk1 » Wed Jul 22, 2020 5:16 am

PB wrote:
Tue Jul 21, 2020 5:26 pm
FWIW: the code posted in viewtopic.php?f=1&t=47358#p199921 lacks the source of origin but looks as one of mine.

I cannot reproduce the issue there; however, race conditions are very timing sensitive and may not demonstrate on specific setup. I certainly do not have a gamer mouse or click speed.

I hazily remember that one of my such examples may have had a race condition but looking at the code now, I cannot see it.

The event handling is done in the main thread so it is always serialized and the execution of event handlers (and hence StartDataLoadingThread() and StopDataLoadingThread() cannot overlap.

But I wasted at almost an hour (very frustrating one) hunting for a superstupid bug of mine in a very simple code just few days ago, so my confidence in debugging abilities is not very high....
Yes, the origin of the code was yourself. It was actually very helpful in getting my head around the complicated subject of wxthreads and threads in general. I did suspect it was some kind of race condition issue, but it seemed to even confuse the visual studio debugger at times, sometimes the thread showing as null sometimes as initialised but always throwing the read exception...and then the issue of defeating the if statement, not easy to debug. I was wondering if it was an os issue but looking at the comments it now seems like something deep in the wx code.
wxWidgets(v3.1.3) - Vs2019(v142) - Win10(x64) - DialogBlocks(v5.16.5_Unicode)

tuk1
Experienced Solver
Experienced Solver
Posts: 95
Joined: Sun Oct 08, 2017 9:36 am

Re: wxThread->Delete() - Exception thrown: read access violation.

Post by tuk1 » Wed Jul 22, 2020 5:34 am

ONEEYEMAN wrote:
Tue Jul 21, 2020 5:17 pm
Hi,
There is a reason it's called MINIMAL...

Thank you.
doublemax wrote:
Tue Jul 21, 2020 5:27 pm
Is there a reason you cant take a look with wxListCtrl included ..as you say its not part of the problem, so why remove it?
The more code i have to read, understand and dig through, the less motivated i am to do so. I might look into it, but it will take longer.
I get it, but..

Its 2 lines of code to both increment and reset the counter, which is about as minimal as it gets. It doesn't matter how that data get managed and displayed, by a wxListCtrl or by miniature willie nelsons running around with wheelbarrows...unless you go looking for it, which is unlikely as its pretty obvious this is a thread issue.

Code: Select all

// handler for wxEVT_INC_COUNT
    void MAIN_FRAME::OnIncCount(wxThreadEvent& evt)
    {        
        m_counter->inc();

        this->m_count_view->SetItemCount(m_counter->size());
        this->m_count_view->Refresh();                
    }

    // handler for wxEVT_RESET_COUNT
    void MAIN_FRAME::OnResetCount(wxThreadEvent&)
    {        
        m_counter->reset();
    }

It's even clearer in the debugger where to look and once you open up the 2 most likely classes there is about about 15 lines of total code to look at ...it's so minimal it almost has its own zen garden :D
Capture.PNG
Capture.PNG (30.47 KiB) Viewed 389 times
Of course as it turn out, there is almost no need to look at the code, because just copy-n-pasting the 'working' code into a compiler tells the tale....
Last edited by tuk1 on Wed Jul 22, 2020 5:48 am, edited 1 time in total.
wxWidgets(v3.1.3) - Vs2019(v142) - Win10(x64) - DialogBlocks(v5.16.5_Unicode)

tuk1
Experienced Solver
Experienced Solver
Posts: 95
Joined: Sun Oct 08, 2017 9:36 am

Re: wxThread->Delete() - Exception thrown: read access violation.

Post by tuk1 » Wed Jul 22, 2020 5:40 am

doublemax wrote:
Tue Jul 21, 2020 7:22 pm
I just ran your unmodified sample and could not get it to crash with any of the four methods.

Is the info from your footer correct and you're using wxWidgets 3.0.5? If yes, please try again with a current version.
PB wrote:
Tue Jul 21, 2020 7:57 pm
I also could not reproduce the issue with the OP's code with none of the 4 methods described, using recentish master.

I then tried the same code with 3.0.5 and succeeded to make it crash on my first try just by clicking on "Start thread" rapidly several times.

I did not investigate the issue any further and would also recommend trying with the wxWidgets master or at least v3.1.3. BTW, v3.1.4 should be officially released this week.
Thanks guys, yeah Im using the 3.0.5 version as per my footer ..let me try the other versions you mention.
wxWidgets(v3.1.3) - Vs2019(v142) - Win10(x64) - DialogBlocks(v5.16.5_Unicode)

tuk1
Experienced Solver
Experienced Solver
Posts: 95
Joined: Sun Oct 08, 2017 9:36 am

Re: wxThread->Delete() - Exception thrown: read access violation.

Post by tuk1 » Wed Jul 22, 2020 2:48 pm

Used the usual steps and commands to manually build v3.1.3. but projects wont compile:
Error LNK1104 cannot open file 'wxmsw30ud_xrc.lib'
Tried using vcpkg to resolve but still the same linker error, any ideas?
wxWidgets(v3.1.3) - Vs2019(v142) - Win10(x64) - DialogBlocks(v5.16.5_Unicode)

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 4423
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxThread->Delete() - Exception thrown: read access violation.

Post by ONEEYEMAN » Wed Jul 22, 2020 3:13 pm

Hi,
Did you change the project accordingly?
Looks like it's still used 3.0 libraries...

Thank you.

User avatar
doublemax
Moderator
Moderator
Posts: 15170
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxThread->Delete() - Exception thrown: read access violation.

Post by doublemax » Wed Jul 22, 2020 3:22 pm

tuk1 wrote:
Wed Jul 22, 2020 2:48 pm
Used the usual steps and commands to manually build v3.1.3. but projects wont compile:
Error LNK1104 cannot open file 'wxmsw30ud_xrc.lib'
Tried using vcpkg to resolve but still the same linker error, any ideas?
wx 3.1.x libs have "31" in their name instead of "30". Adjust your linker settings accordingly. E.g. wxmsw30ud_xrc.lib -> wxmsw31ud_xrc.lib
Use the source, Luke!

tuk1
Experienced Solver
Experienced Solver
Posts: 95
Joined: Sun Oct 08, 2017 9:36 am

Re: wxThread->Delete() - Exception thrown: read access violation.

Post by tuk1 » Wed Jul 22, 2020 3:45 pm

So I should change all these files from 30 to 31?
Capture.PNG
Capture.PNG (62.57 KiB) Viewed 343 times
wxWidgets(v3.1.3) - Vs2019(v142) - Win10(x64) - DialogBlocks(v5.16.5_Unicode)

User avatar
doublemax
Moderator
Moderator
Posts: 15170
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxThread->Delete() - Exception thrown: read access violation.

Post by doublemax » Wed Jul 22, 2020 3:46 pm

tuk1 wrote:
Wed Jul 22, 2020 3:45 pm
So I should change all these files from 30 to 31?
Yes.
Use the source, Luke!

tuk1
Experienced Solver
Experienced Solver
Posts: 95
Joined: Sun Oct 08, 2017 9:36 am

Re: wxThread->Delete() - Exception thrown: read access violation.

Post by tuk1 » Wed Jul 22, 2020 3:56 pm

Ok, thats cleared the link error but 99 other compile errors have now appeared, must be something else going on, never had to rename files like that before, normally its quite painless upgrading build versions.
Capture.PNG
Capture.PNG (65.98 KiB) Viewed 340 times
wxWidgets(v3.1.3) - Vs2019(v142) - Win10(x64) - DialogBlocks(v5.16.5_Unicode)

User avatar
doublemax
Moderator
Moderator
Posts: 15170
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxThread->Delete() - Exception thrown: read access violation.

Post by doublemax » Wed Jul 22, 2020 4:00 pm

It looks there are still include files from the old wx version being used or are not found at all. I have no experience with vcpkg, so i don't know exactly what it does. I can only tell you to double check include paths.
Use the source, Luke!

tuk1
Experienced Solver
Experienced Solver
Posts: 95
Joined: Sun Oct 08, 2017 9:36 am

Re: wxThread->Delete() - Exception thrown: read access violation.

Post by tuk1 » Wed Jul 22, 2020 4:01 pm

Ok, I disabled vcpkg and everything magically righted itself.
Capture.PNG
Capture.PNG (32.14 KiB) Viewed 337 times
doublemax wrote:
Wed Jul 22, 2020 4:00 pm
I have no experience with vcpkg, so i don't know exactly what it does.
According to the page:
I can attest that it brings the overhead of working with third-party C++ libraries down to almost nil.
Set up with wxWidgets in 5 minutes
wxWidgets(v3.1.3) - Vs2019(v142) - Win10(x64) - DialogBlocks(v5.16.5_Unicode)

Post Reply