FreeStructure() crash

Just starting out? Need help? Post your questions and find answers here.
Joubarbe
Enthusiast
Enthusiast
Posts: 703
Joined: Wed Sep 18, 2013 11:54 am
Location: France

Re: FreeStructure() crash

Post by Joubarbe »

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?)
tored
User
User
Posts: 86
Joined: Wed Feb 16, 2022 12:47 pm
Location: Sweden

Re: FreeStructure() crash

Post by tored »

Antivirus software? Faulty RAM memory sticks?
Joubarbe
Enthusiast
Enthusiast
Posts: 703
Joined: Wed Sep 18, 2013 11:54 am
Location: France

Re: FreeStructure() crash

Post by Joubarbe »

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.
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: FreeStructure() crash

Post by Fred »

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?)
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
Enthusiast
Enthusiast
Posts: 703
Joined: Wed Sep 18, 2013 11:54 am
Location: France

Re: FreeStructure() crash

Post by Joubarbe »

Thanks Fred for confirming this. There's no crash without the debugger, and crash with the debugger only with ASM backend.
Joubarbe
Enthusiast
Enthusiast
Posts: 703
Joined: Wed Sep 18, 2013 11:54 am
Location: France

Re: FreeStructure() crash

Post by Joubarbe »

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:

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
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()).
User avatar
jacdelad
Addict
Addict
Posts: 1992
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: FreeStructure() crash

Post by jacdelad »

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
User avatar
mk-soft
Always Here
Always Here
Posts: 6204
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: FreeStructure() crash

Post by mk-soft »

Works here with windows, macOS and linux.
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
Joubarbe
Enthusiast
Enthusiast
Posts: 703
Joined: Wed Sep 18, 2013 11:54 am
Location: France

Re: FreeStructure() crash

Post by Joubarbe »

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...)
infratec
Always Here
Always Here
Posts: 7577
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: FreeStructure() crash

Post by infratec »

Is a virus scanner running?
Disable it.
Joubarbe
Enthusiast
Enthusiast
Posts: 703
Joined: Wed Sep 18, 2013 11:54 am
Location: France

Re: FreeStructure() crash

Post by Joubarbe »

infratec wrote: Tue Oct 15, 2024 9:08 am Is a virus scanner running?
Disable it.
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.
User avatar
SPH
Enthusiast
Enthusiast
Posts: 561
Joined: Tue Jan 04, 2011 6:21 pm

Re: FreeStructure() crash

Post by SPH »

@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!

!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
Joubarbe
Enthusiast
Enthusiast
Posts: 703
Joined: Wed Sep 18, 2013 11:54 am
Location: France

Re: FreeStructure() crash

Post by Joubarbe »

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:

Code: Select all

    ForEach \controls()
      If \controls() <> #Null
        FreeStructure(\controls()) ; crashes here.
      EndIf
      \controls() = #Null
    Next
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)
User avatar
spikey
Enthusiast
Enthusiast
Posts: 750
Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom

Re: FreeStructure() crash

Post by spikey »

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.)...
So far I can't see that you're doing anything wrong (now you've added null pointer checks).

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.
User avatar
spikey
Enthusiast
Enthusiast
Posts: 750
Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom

Re: FreeStructure() crash

Post by spikey »

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?
Post Reply