January 16, 2021, 09:40:55 PM

Author Topic: Memory Access Violation  (Read 3373 times)

Offline windman

  • Jr. Member
  • **
  • Posts: 30
Memory Access Violation
« on: April 09, 2018, 09:04:53 PM »
What is wrong with the code?
Code: [Select]
While MilliSecs()-ST<3500
LL=Rand(80,644)
For H=1 To LL:C=Rand(32,126)
S$=S$+Chr$(C)
Next
WriteLine(FH1,S$);5:Print S$:HALT
S$=""
Wend
;Text 20,20,"FW: "+LN:VWait:Flip:Cls
CloseFile(FH1)

It looks right to me but continually get the Memory Access Violation error

Offline Pakz

  • Full Member
  • ***
  • Posts: 192
    • My homepage
Re: Memory Access Violation
« Reply #1 on: April 09, 2018, 09:44:17 PM »
Did you create the file? I think you need to open a file before it can be written to.

Offline STEVIE G

  • Sr. Member
  • ****
  • Posts: 498
Re: Memory Access Violation
« Reply #2 on: April 09, 2018, 09:47:44 PM »
What is wrong with the code?
Code: [Select]
While MilliSecs()-ST<3500
LL=Rand(80,644)
For H=1 To LL:C=Rand(32,126)
S$=S$+Chr$(C)
Next
WriteLine(FH1,S$);5:Print S$:HALT
S$=""
Wend
;Text 20,20,"FW: "+LN:VWait:Flip:Cls
CloseFile(FH1)

It looks right to me but continually get the Memory Access Violation error

Compile in debug mode for a better idea.  Looks like you aren't creating the file to write to unless this part of the code is missing?   i.e. FH1 = WriteFile( Filename )

There's also no such command in B3d as HALT, so assume it's your own.  What does that do?

p.s. Flip (true by default) automatically does a Vwait so no need for a separate command unless you are using Flip false.

Offline windman

  • Jr. Member
  • **
  • Posts: 30
Re: Memory Access Violation
« Reply #3 on: April 09, 2018, 10:35:34 PM »
Code: [Select]
FH1=WriteFile("C:FN$+".TXT"):LN=LN+1

While MilliSecs()-ST<3500
LL=Rand(80,644)
For H=1 To LL:C=Rand(32,126)
S$=S$+Chr$(C)
Next
WriteLine(FH1,S$);5:Print S$:HALT
S$=""
Wend
CloseFile(FH1)

Sorry about that.
Here's the top portion before dropping into the loop

Offline windman

  • Jr. Member
  • **
  • Posts: 30
Re: Memory Access Violation
« Reply #4 on: April 10, 2018, 12:10:31 AM »
I found the problem. The variable FH1 gets reset to zero after it enters the while loop for some reason.
I tried GLOBAL but it changes nothing.

Any Suggestions?

Online Matty

  • Hero Member
  • *****
  • Posts: 1332
    • MattiesGames
Re: Memory Access Violation
« Reply #5 on: April 10, 2018, 12:54:52 AM »
Your writefile expression is completely wrong - unmatched quotes.
I eat cheese in the trees when its eight degrees

Offline windman

  • Jr. Member
  • **
  • Posts: 30
Memory Access Violation
« Reply #6 on: April 10, 2018, 01:55:54 AM »
I fixed that and still get an error.
Might be the compiler

Offline windman

  • Jr. Member
  • **
  • Posts: 30
Memory Access Violation
« Reply #7 on: April 10, 2018, 01:57:24 AM »
Code: [Select]
While Not KeyDown(1)

ST=MilliSecs()
FN$=RFN():
LN=LN+1

If MilliSecs()-ST<3500
FH1=WriteFile("C:"+FN$+".TXT")
LL=Rand(80,644)
For H=1 To LL:
C=Rand(32,126)
S$=S$+Chr$(C)
Next
WriteLine(FH1,S$)
S$=""
EndIf

CloseFile(FH1)

Wend

Offline windman

  • Jr. Member
  • **
  • Posts: 30
Memory Access Violation
« Reply #8 on: April 10, 2018, 02:35:21 AM »
I found the problem. It was another part of the code.
The portion that was generating the name was at times generating some special character that windows would not allow.
The program would then return a zero for the file handle because of windows.

Offline RemiD

  • Hero Member
  • *****
  • Posts: 1128
Re: Memory Access Violation
« Reply #9 on: April 10, 2018, 09:47:57 AM »
Hence the usefulness of DebugLog()... (to check how the strings that you generate with parts, look like)
DualCore AMD E-450, 1646 MHz - 6 Go DDR3 1333 SDRAM - AMD Radeon HD 6320 Graphics (384 Mo) - Windows 7 Home Premium - DirectX 11.0

Online Matty

  • Hero Member
  • *****
  • Posts: 1332
    • MattiesGames
Re: Memory Access Violation
« Reply #10 on: April 10, 2018, 12:10:09 PM »
I'm surprised it works without a backslash after the c colon.
I eat cheese in the trees when its eight degrees

Offline windman

  • Jr. Member
  • **
  • Posts: 30
Memory Access Violation
« Reply #11 on: April 10, 2018, 09:08:00 PM »
Quote
Hence the usefulness of DebugLog()... (to check how the strings that you generate with parts, look like)

Actually the Debug log never indicated that the code generating the name was giving the error. The Debug log showed the:

WriteLine(FH1,S$)

instruction to be the error. But that was because the:

FH1=WriteFile("C:"+FN$+".TXT")

had an illegal character that was generated in the name, within FN$ making FH1 return a value of zero.
I found that there are 8 characters that cannot be used in a filename. So I wrote a different routine that generated a valid name excluding those characters.
The Microsoft web page also mentions that Unicode characters are allowed but I am lost at how to get them to show in the name algorithm.

Quote
I'm surprised it works without a backslash after the c colon.

The BB compiler allows that and it is convenient. The compiler also allows some interesting nested logical functions that, though confusing, can abbreviate the source code that you write.

Offline RemiD

  • Hero Member
  • *****
  • Posts: 1128
Re: Memory Access Violation
« Reply #12 on: April 11, 2018, 05:19:30 PM »
Quote
Actually the Debug log never indicated that the code generating the name was giving the error.
what i meant was using debuglog to display the string value made of string parts, something like :

Code: [Select]
PathAndFilename$ = "C:"+FN$+".TXT"
debuglog(PathAndFilename)
FH1=WriteFile(PathAndFilename)
DualCore AMD E-450, 1646 MHz - 6 Go DDR3 1333 SDRAM - AMD Radeon HD 6320 Graphics (384 Mo) - Windows 7 Home Premium - DirectX 11.0

Offline windman

  • Jr. Member
  • **
  • Posts: 30
Memory Access Violation
« Reply #13 on: April 11, 2018, 09:36:10 PM »
Oh that

I never knew that I could do that inside of BB.
thanks for the tip

Offline 3DzForMe

  • Hero Member
  • *****
  • Posts: 1177
Re: Memory Access Violation
« Reply #14 on: April 13, 2018, 06:31:12 PM »
I created a Read Write Debug function to try and get to the bottom of some 'path' hiccups, Windows is very fickle when it comes to paths depending upon which OS you're using.
 :-X

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal