Random memory page errors causing crashing

For everything that's not in any way related to PureBasic. General chat etc...
User avatar
DeanH
Enthusiast
Enthusiast
Posts: 279
Joined: Wed May 07, 2008 4:57 am
Location: Adelaide, South Australia
Contact:

Random memory page errors causing crashing

Post by DeanH »

Some of my users have been reporting random crashes. The program, written entirely in PureBasic for Windows, randomly shuts down and vanishes off the screen. In only one case, the program was still in the Task Manager but not visible. In all other cases the exe has shut down. More often than not, it happens after the program has been un-minimized but not always. It can happen at any point at any time. It can happen in the middle of typing something. I originally thought it might have something to do with input as it often happened when data was enter into a StringGadget but this behaviour has also happened on other statements, even LoadImage and DatabaseUpdtae. The latest was End.

I set up OnErrorCall to trap for errors. The only thing appearing is a Memory Page Error and that does not always appear. The exe can still shut down without reporting an error. The latest error took place on a MessageRequester line (below).

Code: Select all

;ErrorMessage$ is a string containing the ErrorMessage(), ErrorLine() and ErrorFile()
If MessageRequester("Error", ErrorMessage$,#PB_MessageRequester_YesNo|#PB_MessageRequester_Error)>#PB_MessageRequester_Yes
	End
EndIf
The error was reported on the End statement!

I have been investigating this for months. I have tried different compiler versions of PB, including 6.

I do not think it is a PureBasic problem but some type of interference. According to the users the folder or mapped drive is excluded from Defender checking.

This is only happening to a fraction of my users but there are several. I am stumped and it is driving these users crazy. Any ideas?
User avatar
Caronte3D
Addict
Addict
Posts: 1370
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: Random memory page errors causing crashing

Post by Caronte3D »

When I have randomly shuts down and vanishes off the screen, offten is because one of two reasons:
1.- Read or write global variables on a threaded program without mutex
2.- Invalid Memory read or write
User avatar
DeanH
Enthusiast
Enthusiast
Posts: 279
Joined: Wed May 07, 2008 4:57 am
Location: Adelaide, South Australia
Contact:

Re: Random memory page errors causing crashing

Post by DeanH »

Caronte3D, can you please clarify. The programs (there are several modules) were compiled unthreaded. I tried threaded but it made no difference. Can you explain the mutex aspect and what I could do. There are a great deal of global variables, arrays, lists and maps.

It is also odd this behaviour only started mid last year after over 10 years.

As to memory read/write, I checked for that. I do very little direct memory access. Just normal PB variable = assignment. I have also made sure libraries are not left open, files and databases (SQLite) are not left open. Callbacks are at a minimum.

I have tried the C-backend compiler but it keeps hanging on me during compilation.
User avatar
idle
Always Here
Always Here
Posts: 6026
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Random memory page errors causing crashing

Post by idle »

Do you have any threads? If you do are there any Global variables or resources that are written to over thread boundaries?
Bitblazer
Enthusiast
Enthusiast
Posts: 766
Joined: Mon Apr 10, 2017 6:17 pm
Location: Germany
Contact:

Re: Random memory page errors causing crashing

Post by Bitblazer »

DeanH wrote: Mon Jan 31, 2022 2:28 am It is also odd this behaviour only started mid last year after over 10 years.
  • Try to find backup versions as late as possible which always worked.
  • Make a diff to your current sources.
  • Start adding everything one by one to find out where the problem started.
  • Look at the last addition / change
There you have your bug.

Yes, it is a lot work. Work that should have happened a year ago ;)
But it does give you answers. If you think it is a compiler bug, go to the purebasic museum and get the compiler version you used back then and see if that works.

For large projects, a backup history is very useful. At every major stable point of an important project, do a seperate backup and keep it in your project history. Storage is dirt cheap nowadays.

If i had to do this, i would create two project folders, get good music, snacks and use WinMerge.
User avatar
Caronte3D
Addict
Addict
Posts: 1370
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: Random memory page errors causing crashing

Post by Caronte3D »

DeanH wrote: Mon Jan 31, 2022 2:28 am Caronte3D, can you please clarify.
If you program doesn´t use threads the mutex is not used so not problem accessing global variables at all.

Good luck, that type of bugs that occurs randomly being a pain
User avatar
Caronte3D
Addict
Addict
Posts: 1370
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: Random memory page errors causing crashing

Post by Caronte3D »

Some times using a "OnError" procedure helps a lot to find those bugs because you see the line number where it occurs
User avatar
DeanH
Enthusiast
Enthusiast
Posts: 279
Joined: Wed May 07, 2008 4:57 am
Location: Adelaide, South Australia
Contact:

Re: Random memory page errors causing crashing

Post by DeanH »

Thank you for the suggestions. I have tried all of those.

I have been using OnError. That's how I saw the Memory Page Error message. It reports the problem at seemingly random points. No consistency at all. Sometimes the error isn't even reported. The exe just shuts down. One user reported two instances of it happening yesterday.

I keep backups of various versions going back into the 90's. Current version is 10.8.1 and I have versions right back to 10.1. Database has evolved, though, so there's a limit as to how far back I can try. I put one of the slightly "older" versions (10.7.5) into a site but it, too, showed the same random vanishing behaviouir. I also tried compiling using an older version of PB, but that's limited as I have used some of the more recent functions like HttpRequest. No difference between using PB 5.73 and 6.00.

I am thinking some type of background task is causing this but have no idea what it might be. The schools involved claim their anti-virus systems have excluded the mapped drive. They're all using workstations, and I did try it on a local C: drive, which reduced the frequence but did not elmininate it.
Bitblazer
Enthusiast
Enthusiast
Posts: 766
Joined: Mon Apr 10, 2017 6:17 pm
Location: Germany
Contact:

Re: Random memory page errors causing crashing

Post by Bitblazer »

DeanH wrote: Mon Jan 31, 2022 12:37 am This is only happening to a fraction of my users but there are several. I am stumped and it is driving these users crazy. Any ideas?
DeanH wrote: Mon Jan 31, 2022 10:01 pm I have been using OnError. That's how I saw the Memory Page Error message. It reports the problem at seemingly random points. No consistency at all. Sometimes the error isn't even reported. The exe just shuts down. One user reported two instances of it happening yesterday.
Did you already try to run your project with the purifier settings set to very restrictive checks? Because a tricky memory heap corruption by under/overwriting could do that.
juergenkulow
Enthusiast
Enthusiast
Posts: 581
Joined: Wed Sep 25, 2019 10:18 am

Re: Random memory page errors causing crashing

Post by juergenkulow »

Do you still have the ErrorAddress() from the memory page error, the assembler instruction before ErrorAddress(), the complete stack ending at rsp or esp and the contents of the important registers and important variables like event?(LogError.txt) I prefer OnErrorGoto instead of OnErrorCall or the VS2008 debugger.
BarryG
Addict
Addict
Posts: 4219
Joined: Thu Apr 18, 2019 8:17 am

Re: Random memory page errors causing crashing

Post by BarryG »

Dean, these types of errors are annoying to find, I know. See my experience here -> https://www.purebasic.fr/english/viewto ... 25#p541025

I've also found other mysterious crashes by using a dedicated error handler procedure with ErrorLine support turned on. It was based on this -> https://www.purebasic.fr/english/viewto ... 92#p491192

Use that error handler code - it really helped me.
hoerbie
Enthusiast
Enthusiast
Posts: 137
Joined: Fri Dec 06, 2013 11:57 am
Location: DE/BY/MUC

Re: Random memory page errors causing crashing

Post by hoerbie »

Just one idea, when reading
functions like HttpRequest
and
were compiled unthreaded
do you use the async mode of HttpRequest?
I've had a lot of crashes, until I put the async HttpRequest commands in a thread and compiling thread safe. Using async HttpRequest around/between WaitWindowEvent(timeout) had crashes in real life on different and simple code lines, but never crashed when slowly going through the program with the debugger step by step.
TassyJim
Enthusiast
Enthusiast
Posts: 189
Joined: Sun Jun 16, 2013 6:27 am
Location: Tasmania (Australia)

Re: Random memory page errors causing crashing

Post by TassyJim »

It reminds me of the problems I had when I started to compile in 64bit.
I had used longs where I should have been using integers.

Jim
User avatar
DeanH
Enthusiast
Enthusiast
Posts: 279
Joined: Wed May 07, 2008 4:57 am
Location: Adelaide, South Australia
Contact:

Re: Random memory page errors causing crashing

Post by DeanH »

Thanks everyone.

I ran into the integer issue, too, when switching to 64-bit a few years ago. I went through the source code and took care of that. I had to go to 64-bit due to constant anti-virus false positives, especially after PureLocker turned up. I have tried both 32 and 64 bit in these sites but both behaved the same.

Have not had this problem with any HttpRequest. They are all separate from WindowEvent or WaitWindowEvent loops.

I'll try the purifier trick. I did try threadsafe but that made no difference. Still happened.

This morning I asked a user to revert back to a version from mid 2020. Back then this did not happen. But it happened this morning to them. I am now feeling the problem is caused by a background task. Unfortunately I do not have a clue as to what that might be. It happens mostly when a minimized window has been brought back up and the user tries to do something. But it can also happen without minimizing, too (check that).

Thank you everyone so far for the suggestions. This problem remains an annoying mystery.
User avatar
skywalk
Addict
Addict
Posts: 4241
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Random memory page errors causing crashing

Post by skywalk »

Are there any hardware similarities between the users that crash?
What windows version/build do you bless?
Do you have your own log you can use to dump time, procedure calls, etc?
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Post Reply