FreeStructure() crash
Re: FreeStructure() crash
Doesn't work either in 6.11. But thanks for suggesting.
Now for something even weirder: my app is available in both English and French. I was testing in French (translation recently done), and when I switch back to English, it doesn't crash anymore.
Could it be possible that the C compiler manages to detect and fix what I'm doing wrong...? (prevent memory problems while the ASM wouldn't?)
Now for something even weirder: my app is available in both English and French. I was testing in French (translation recently done), and when I switch back to English, it doesn't crash anymore.
Could it be possible that the C compiler manages to detect and fix what I'm doing wrong...? (prevent memory problems while the ASM wouldn't?)
Re: FreeStructure() crash
Antivirus software? Faulty RAM memory sticks?
Re: FreeStructure() crash
No antivirus. I think I would see other programs act weird if it was a faulty RAM?
I've just compiled my Dev version... and it doesn't crash after 10 tests (running from the .exe). Same thing, same state, same steps. I really don't get it.
I've just compiled my Dev version... and it doesn't crash after 10 tests (running from the .exe). Same thing, same state, same steps. I really don't get it.
Re: FreeStructure() crash
It shouldn't, but as the generated code isn't the same (different size, positions), it could be that a crash that occurs in ASM backend doesn't show up in C backend and vice-versa. It can happen when a pointer get crazy.Joubarbe wrote: Mon Oct 14, 2024 1:40 pm Could it be possible that the C compiler manages to detect and fix what I'm doing wrong...? (prevent memory problems while the ASM wouldn't?)
Re: FreeStructure() crash
Thanks Fred for confirming this. There's no crash without the debugger, and crash with the debugger only with ASM backend.
Re: FreeStructure() crash
This morning, all my tests crash at "AddElement()". The list is valid, ListSize() returns the proper result, but AddElement() gives a read error at address 0. How can this happen?
This is my function:
I'm under the impression that this error has the same cause as the FreeStructure() crash.
Could this be related to the computer I'm using? RAM problem? None of the other apps I'm using seem to be faulty, and it always crashes at those two same locations (AddElement() or FreeStructure()).
This is my function:
Code: Select all
Structure _FormattedWord
text$
color.i
background_color.i
underlined.b
EndStructure
Procedure CatchFormattedWordsFromText(List words._FormattedWord(), text$, default_color = -1, background_color = -1, underlined.b = #False)
ClearList(words())
Define color = default_color
Define n
Define spaces = CountString(text$, " ")
For n = 1 To spaces + 1
Define word$ = StringField(text$, n, " ")
Debug ListSize(words()) ; Debug, no problem, works as intended.
ForEach words()
Debug words() ; Also works as intended.
Next
AddElement(words()) ; Crash here: "Invalid memory access. Read error at address 0."
words()\text$ = word$
words()\color = color
words()\background_color = background_color
words()\underlined = underlined
Next n
EndProcedure
Could this be related to the computer I'm using? RAM problem? None of the other apps I'm using seem to be faulty, and it always crashes at those two same locations (AddElement() or FreeStructure()).
Re: FreeStructure() crash
I once had the same problem. The hardware was ok, a new Windows installation helped.
Good morning, that's a nice tnetennba!
PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
Re: FreeStructure() crash
Works here with windows, macOS and linux.
Perhaps use threads or at AddElement out of memory ...
Perhaps use threads or at AddElement out of memory ...
Code: Select all
Structure _FormattedWord
text$
color.i
background_color.i
underlined.b
EndStructure
Procedure CatchFormattedWordsFromText(List words._FormattedWord(), text$, default_color = -1, background_color = -1, underlined.b = #False)
ClearList(words())
Define color = default_color
Define n
Define spaces = CountString(text$, " ")
For n = 1 To spaces + 1
Define word$ = StringField(text$, n, " ")
Debug ListSize(words()) ; Debug, no problem, works as intended.
ForEach words()
Debug words() ; Also works as intended.
Next
AddElement(words()) ; Crash here: "Invalid memory access. Read error at address 0."
words()\text$ = word$
words()\color = color
words()\background_color = background_color
words()\underlined = underlined
Next n
EndProcedure
Global NewList words._FormattedWord()
temp.s = "Procedure CatchFormattedWordsFromText(List words._FormattedWord(), text$, default_color = -1, background_color = -1, underlined.b = #False)"
CatchFormattedWordsFromText(words(), temp)
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: FreeStructure() crash
Sorry I did not say that this snip of code was only for showing where the crash happens. I don't expect this to crash. But thanks for trying 
Also, my app takes 40MB of RAM when it crashes, and I don't use threads.
(reinstalling Windows now, just to make sure...)

Also, my app takes 40MB of RAM when it crashes, and I don't use threads.
(reinstalling Windows now, just to make sure...)
Re: FreeStructure() crash
Is a virus scanner running?
Disable it.
Disable it.
Re: FreeStructure() crash
I've deactivated all Windows security modules, and it still crashes. I don't have other antivirus / firewall installed.
My computer is a MSI GP76 laptop. I've just tried on another computer and after 10 tries, I had no crash.
UPDATE: Reinstalling Windows via the recovery repair update didn't help.
Re: FreeStructure() crash
@Joubarbe :
Frankly, if you have already played the latest video games (or big programs) and you have not had any crashes, it is because your memory sticks are OK!
Frankly, if you have already played the latest video games (or big programs) and you have not had any crashes, it is because your memory sticks are OK!
!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Portable LENOVO ideapad 110-17ACL 64 bits
Version de PB : 6.12LTS - 64 bits
Re: FreeStructure() crash
Little heads up on this. I thought I did something to fix this crash, but no it came back for no obvious reason, except I now have a "write error at address 0" error:
How can you have an address 0 error if controls() is different from 0? This code is inside a With *view / EndWith block, but if *view was #Null, it would crash at the ForEach line or the If \controls() <> #Null line.
EDIT: Also interesting to note is that every time I use AllocateStructure(), I check the pointer and returns an error if it's #Null.
EDIT 2: Sometimes it's a read error, but so far, it's never been 0.
EDIT 3: The only solution I see now is to rewrite my _View structure (see OP), and have a unique list for every gadget I use (labels, buttons, etc.). Then I would keep a list of control references (pointers) to process all my controls at once when needed (cannot remove all in one line though). Would be happy to have opinions of people who did a GUI framework.
EDIT 4: I did the points above in EDIT 3, no manual memory allocation at all, and now it crashes on a ClearList() (same place as the previous FreeStructure()). (I added a ClearList() for every gadget I had; the first one crashes)
Code: Select all
ForEach \controls()
If \controls() <> #Null
FreeStructure(\controls()) ; crashes here.
EndIf
\controls() = #Null
Next
EDIT: Also interesting to note is that every time I use AllocateStructure(), I check the pointer and returns an error if it's #Null.
EDIT 2: Sometimes it's a read error, but so far, it's never been 0.
EDIT 3: The only solution I see now is to rewrite my _View structure (see OP), and have a unique list for every gadget I use (labels, buttons, etc.). Then I would keep a list of control references (pointers) to process all my controls at once when needed (cannot remove all in one line though). Would be happy to have opinions of people who did a GUI framework.
EDIT 4: I did the points above in EDIT 3, no manual memory allocation at all, and now it crashes on a ClearList() (same place as the previous FreeStructure()). (I added a ClearList() for every gadget I had; the first one crashes)
Re: FreeStructure() crash
So far I can't see that you're doing anything wrong (now you've added null pointer checks).Joubarbe wrote: Wed Oct 23, 2024 10:25 am The only solution I see now is to rewrite my _View structure (see OP), and have a unique list for every gadget I use (labels, buttons, etc.)...
From what you've described the problem seems to be an interference one rather than a static bug in a specific library function. In fact, if you hadn't already said you weren't using threads, I'd be thinking that you've compiled a threaded program without the threadsafe compiler option because this is exactly the sort of behaviour I've seen in the past if I forgot to switch it on.
At the moment I'm thinking you have a stack corruption somewhere along the line (but this is a guess). Debugging this could be really time consuming and might need to be done at the assembly level which is a PITA because PB doesn't export a symbol table that an external debugger can use.
I guess its a question of which way you want to consume your time, reworking or debugging. If you have a production deadline of some sort then the rework may be your only choice because a hardcore debug is not a time-limited exercise.
The downside is that, if I am right and it is an interference problem; there is the potential for the rework not to solve the problem if you don't eliminate the source in the rework.
(FTR - I started writing this before EDIT 4 was posted).
Last edited by spikey on Wed Oct 23, 2024 1:55 pm, edited 1 time in total.
Re: FreeStructure() crash
1) Humour me would you? Switch the threadsafe compiler option on and retest - I'd like to know if it makes any difference at all.
2) Are you still using 'With' in your reworked code?
2) Are you still using 'With' in your reworked code?