Invalid memory access problem ...

Just starting out? Need help? Post your questions and find answers here.
marc_256
Addict
Addict
Posts: 858
Joined: Thu May 06, 2010 10:16 am
Location: Belgium
Contact:

Invalid memory access problem ...

Post by marc_256 »

Hi,

For my CAD program, HPGL .plt file converter, I need a lot of data input.
See image below (Industrial electrical scheme part).
The first part of the drawing conversions works well to a point I get this message.
The program passes for about 100 times in the loop and then I get the error...

Where can I find some info about [Invalid memory access] ?
And what is the reason i get this error ?
[17:06:33] Executable type: Windows - x64 (64bit, Unicode, Thread)
[17:06:33] Executable started.
[17:06:34] [ERROR] DecodeCommand_Code_A.pbi (Line: 243)
[17:06:34] [ERROR] Invalid memory access. (read error at address 18446744073709551615)
[17:06:53] The Program was killed.

Code: Select all

Global Hpgl_ArcAbsolute_BeginAngle.f
Global Hpgl_ArcAbsolute_DeltaX.l
Global Hpgl_ArcAbsolute_DeltaY.l

Line 243:
Hpgl_ArcAbsolute_BeginAngle = Degree ( ATan2 (Hpgl_ArcAbsolute_DeltaX, Hpgl_ArcAbsolute_DeltaY))
OS: Win 10 x64
PB: 5.73 LTS x64
Debugger: ON

Thanks,
Marc,

Image
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
User avatar
spikey
Enthusiast
Enthusiast
Posts: 778
Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom

Re: Invalid memory access problem ...

Post by spikey »

IMA's are usually caused by dereferencing a null or invalid pointer, a jump to an incorrect entry point, or stack corruption - but I suspect that information isn't going to tell you anything helpful right now! I can't see anything wrong with that code and I did some tests which seem to work ok (but on 6.00 and 6.03 because I don't have 5.73 installed right now).

Are you using the ASM or the C backend? It may make a difference.

Does it always fail at the same point, in which case what are the specific values of Hpgl_ArcAbsolute_DeltaX or Hpgl_ArcAbsolute_DeltaY that cause the problem?
juergenkulow
Enthusiast
Enthusiast
Posts: 581
Joined: Wed Sep 25, 2019 10:18 am

Re: Invalid memory access problem ...

Post by juergenkulow »

Have you tried using x64dbg to find out where in the exe file to read memory $FFFFFFFFFFFFFFFFFFFF , -1, 18446744073709551615, with which ASM command, what do the registers and the stack look like?
Please ask your questions, because switch on the cognition apparatus decides on the only known life in the universe.Wersten :DDüsseldorf NRW Germany Europe Earth Solar System Flake Bubble Orionarm
Milky Way Local_Group Virgo Supercluster Laniakea Universe
User avatar
idle
Always Here
Always Here
Posts: 6044
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Invalid memory access problem ...

Post by idle »

If your application is threaded the reported ima won't be the right one so try what Jurgen says above. Memory addresses are 48bits so you can often see a bad pointer, look at you loops, are you performing one step to many and reading over the end of some memory.
Are you reading some shared memory that's been freed elsewhere.
marc_256
Addict
Addict
Posts: 858
Joined: Thu May 06, 2010 10:16 am
Location: Belgium
Contact:

Re: Invalid memory access problem ...

Post by marc_256 »

Hallo guys,

thanks for your help,
Sorry for late reaction, I was working very late this night to find the problem ...
without any result, and slept only a few hours ...


@spikey
- I use only ASM (I think PB5.73 LTS is only ASM)
- I just cute this part of my program,
and tested without this part, then I have an other problem.
- The program starts but don't work at all and gave me this time a windows error.


@juergenkulow
Thanks for the tip,
I'm NOT that good in programming, so I will need to learn to use that program.
Just downloaded it ...


@idle
are you performing one step to many and reading over the end of some memory
- Well, I open a HDD .plt file.
- I read line by line and store it in a (string) array.
- Then I decode and correct the text to correct HPGL code
(I found, there are a lot of CAD programs who exporting not correct HPGL codes.)
- Then I draw the corrected HPGL code on an created image. (and show it on the screen)

Yes, I will look in that direction now, maybe it is in reading memory.


thanks,
Marc,
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
juergenkulow
Enthusiast
Enthusiast
Posts: 581
Joined: Wed Sep 25, 2019 10:18 am

Re: Invalid memory access problem ...

Post by juergenkulow »

Code: Select all

; Sample Thread with wrong Error line
Procedure myThread(i)
  Delay(100)
  PeekA(-1)
EndProcedure

CreateThread(@myThread(),0)
For i=1 To 100000000:Next 
Delay(1000)

; [11:35:15] Warte auf den Start des Executable...
; [11:35:15] Executable-Typ: Windows - x64  (64bit, Unicode)
; [11:35:15] Executable gestartet.
; [11:35:15] [ERROR] myThread.pb (Zeile: 8)
; [11:35:15] [ERROR] Ungültiger Speicherzugriff. (Lesefehler an der Adresse 18446744073709551615)

; pbcompiler /Commented myThread.pb
; ; Procedure myThread(i)
; _Procedure0:
;   MOV    qword [rsp+8],rcx
;   PS0=48
;   SUB    rsp,40
; ; Delay(100)
;   PUSH   qword 100
;   POP    rcx
;   CALL   PB_Delay
; ; PeekA(-1)
;   PUSH   qword -1
;   POP    rcx
;   CALL   PB_PeekA
; ; EndProcedure
; _EndProcedureZero1:
;   XOr    rax,rax
; _EndProcedure1:
;   ADD    rsp,40
;   RET

; x64dbg Load myThread.exe Klick on 00000001400010E8  F4 F7 F7 
; 0000000140001000 <mythread.EntryPoi | 48:83EC 28      | sub rsp,28                        |
; 0000000140001004                    | 49:C7C0 2800000 | mov r8,28                         | 28:'('
; 000000014000100B                    | 48:31D2         | XOr rdx,rdx                       | rdx:"Hƒì(IÇÀ("
; 000000014000100E                    | 48:B9 985200400 | mov rcx,mythread.140005298        |
; 0000000140001018                    | E8 E30F0000     | call <JMP.&memset>                |
; 000000014000101D                    | 48:31C9         | XOr rcx,rcx                       |
; 0000000140001020                    | E8 E10F0000     | call <JMP.&GetModuleHandleW>      |
; 0000000140001025                    | 48:8905 7442000 | mov qword ptr ds:[1400052A0],rax  |
; 000000014000102C                    | 4D:31C0         | XOr r8,r8                         |
; 000000014000102F                    | 48:C7C2 0010000 | mov rdx,1000                      | rdx:"Hƒì(IÇÀ("
; 0000000140001036                    | 48:31C9         | XOr rcx,rcx                       |
; 0000000140001039                    | E8 CE0F0000     | call <JMP.&HeapCreate>            |
; 000000014000103E                    | 48:8905 5342000 | mov qword ptr ds:[140005298],rax  |
; 0000000140001045                    | E8 5A100000     | call mythread.1400020A4           |
; 000000014000104A                    | E8 E10F0000     | call mythread.140002030           |
; 000000014000104F                    | 68 00000000     | push 0                            |
; 0000000140001054                    | 48:8D05 7300000 | lea rax,qword ptr ds:[1400010CE]  |
; 000000014000105B                    | 48:89C1         | mov rcx,rax                       |
; 000000014000105E                    | 5A              | pop rdx                           | rdx:"Hƒì(IÇÀ("
; 000000014000105F                    | E8 EC100000     | call mythread.140002150           |
; 0000000140001064                    | 48:C705 4942000 | mov qword ptr ds:[1400052B8],1    |
; 000000014000106F                    | EB 00           | jmp mythread.140001071            |
; 0000000140001071                    | 48:C7C0 00E1F50 | mov rax,5F5E100                   |
; 0000000140001078                    | 48:3B05 3942000 | cmp rax,qword ptr ds:[1400052B8]  |
; 000000014000107F                    | 7C 09           | jl mythread.14000108A             |
; 0000000140001081                    | 48:FF05 3042000 | inc qword ptr ds:[1400052B8]      |
; 0000000140001088                    | 71 E7           | jno mythread.140001071            |
; 000000014000108A                    | 48:B9 E80300000 | mov rcx,3E8                       |
; 0000000140001094                    | E8 67120000     | call mythread.140002300           |
; 0000000140001099                    | E8 18000000     | call mythread.1400010B6           |
; 000000014000109E                    | 48:8B0D F341000 | mov rcx,qword ptr ds:[140005298]  |
; 00000001400010A5                    | E8 680F0000     | call <JMP.&HeapDestroy>           |
; 00000001400010AA                    | 48:8B0D F741000 | mov rcx,qword ptr ds:[1400052A8]  |
; 00000001400010B1                    | E8 620F0000     | call <JMP.&RtlExitUserProcess>    |
; 00000001400010B6                    | 48:83EC 28      | sub rsp,28                        |
; 00000001400010BA                    | E8 950F0000     | call mythread.140002054           |
; 00000001400010BF                    | E8 6C110000     | call mythread.140002230           |
; 00000001400010C4                    | E8 570F0000     | call mythread.140002020           |
; 00000001400010C9                    | 48:83C4 28      | add rsp,28                        |
; 00000001400010CD                    | C3              | ret                               |
; 00000001400010CE                    | 48:894C24 08    | mov qword ptr ss:[rsp+8],rcx      |
; 00000001400010D3                    | 48:83EC 28      | sub rsp,28                        |
; 00000001400010D7                    | 68 64000000     | push 64                           |
; 00000001400010DC                    | 59              | pop rcx                           |
; 00000001400010DD                    | E8 1E120000     | call mythread.140002300           |
; 00000001400010E2                    | 68 FFFFFFFF     | push FFFFFFFFFFFFFFFF             |
; 00000001400010E7                    | 59              | pop rcx                           |
; 00000001400010E8                    | E8 630F0000     | call mythread.140002050           |
; 00000001400010ED                    | 48:31C0         | XOr rax,rax                       |
; 00000001400010F0                    | 48:83C4 28      | add rsp,28                        |
; 00000001400010F4                    | C3              | ret                               |

; 0000000140002050                    | 0FB601          | movzx eax,byte ptr ds:[rcx]       |

; byte ptr ds:[rcx]=[FFFFFFFFFFFFFFFF]=???

; Register
; RAX : 0000000000000000
; RBX : 0000000000000000
; RCX : FFFFFFFFFFFFFFFF
; RDX : 0000000000000000
; RBP : 0000000000000000
; RSP : 0000000001B4FF28     &"H1ÀHƒÄ(Ã"
; RSI : 0000000000000000
; RDI : 0000000000000000
; R8  : 0000000001B4FE88     &"‹ð‰„$°"
; R9  : 0000000000000000
; R10 : 0000000000000000
; R11 : 0000000000000246     L'Ɇ'
; R12 : 0000000000000000
; R13 : 0000000000000000
; R14 : 0000000000000000
; R15 : 0000000000000000
; RIP : 0000000140002050     mythread.0000000140002050
; RFLAGS : 0000000000010302

; Stack: 
; 0000000001B4FF28   00000001400010ED   zurück zu mythread.00000001400010ED von mythread.0000000140002050
; 0000000001B4FF30   0000000000000000   
; 0000000001B4FF38   0000000000000000   
; 0000000001B4FF40   0000000000000000   
; 0000000001B4FF48   0000000000000000   
; 0000000001B4FF50   0000000000000000   
; 0000000001B4FF58   0000000076D55A4D   zurück zu kernel32.0000000076D55A4D von ???
User avatar
spikey
Enthusiast
Enthusiast
Posts: 778
Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom

Re: Invalid memory access problem ...

Post by spikey »

marc_256 wrote: Sun Nov 26, 2023 10:53 am @spikey - I use only ASM (I think PB5.73 LTS is only ASM)
:oops: You're right - my memory is starting to go I'm afraid!
marc_256
Addict
Addict
Posts: 858
Joined: Thu May 06, 2010 10:16 am
Location: Belgium
Contact:

Re: Invalid memory access problem ...

Post by marc_256 »

@spikey

Well, I'm happy to see i'm not alone ...


I did some tests:

Code: Select all

Global TestAngle.f
TestAngle = ATan2 (80.0, 60.0)                                       ; BAD RESULT
Debug "Test Angle ATan2 : " + Str (TestAngle)                  ; BAD RESULT

Code: Select all

Debug "Test Angle ATan2 : " + Str ( ATan2 (80.0, 60.0))         ; THIS WORKS WELL

Q) Is there a limit on usable numbers of variables in PB ?


marc,
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
infratec
Always Here
Always Here
Posts: 7665
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Invalid memory access problem ...

Post by infratec »

Code: Select all

Global TestAngle.f
TestAngle = ATan2 (80.0, 60.0)                                       ; BAD RESULT
Debug "Test Angle ATan2 : " + StrF (TestAngle)                  ; BAD RESULT

Debug "Test Angle ATan2 : " + StrF ( ATan2 (80.0, 60.0))         ; THIS WORKS WELL
Results in:
Test Angle ATan2 : 0.6435011029
Test Angle ATan2 : 0.6435011029
WIth PB6.03 x86 ASM backend WIndiws 10

You need StrF(), else it is rounded to 1
marc_256
Addict
Addict
Posts: 858
Joined: Thu May 06, 2010 10:16 am
Location: Belgium
Contact:

Re: Invalid memory access problem ...

Post by marc_256 »

@infratec

Thanks, at least one thing solved...
It was only a test, but you are right. :oops:

thanks,
marc,
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
marc_256
Addict
Addict
Posts: 858
Joined: Thu May 06, 2010 10:16 am
Location: Belgium
Contact:

Re: Invalid memory access problem ...

Post by marc_256 »

Hi,

I lost almost 3 days (and some parts of the night) to find the problem in my program.
I reduced the program to the minimum code of 100 lines to work,
and still had the same problem ... :evil: :twisted:

So, today I had an of of it and installed PB5.73 x32 (32 bits version) on my WIN 8.1 x64 computer.
and re-used my original program, and YES it works as a dream.
No errors at all ... 8)
see result below

Q)
What can be the problem here in PB 5.73 x64 ?
- Even 'ATan2' was not working at all.
- And the use of 'Debug' was blocking my program.
They both gave me the [Invalid memory access] error.

Thanks,
marc


Image
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
User avatar
idle
Always Here
Always Here
Posts: 6044
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Invalid memory access problem ...

Post by idle »

If you've reduced your code to 100 lines why not post the code and sample so we can see where the problem was.
BarryG
Addict
Addict
Posts: 4225
Joined: Thu Apr 18, 2019 8:17 am

Re: Invalid memory access problem ...

Post by BarryG »

marc_256 wrote: Mon Nov 27, 2023 7:52 pm'Debug' was blocking my program
Don't forget that "Debug" commands are removed from executables, so this might be causing the IMA problem if you're using it with a command or function, instead of just using it to show a variable value.
infratec
Always Here
Always Here
Posts: 7665
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Invalid memory access problem ...

Post by infratec »

That's always the problem:

No code, no help.
juergenkulow
Enthusiast
Enthusiast
Posts: 581
Joined: Wed Sep 25, 2019 10:18 am

Re: Invalid memory access problem ...

Post by juergenkulow »

This reminds me of a two-week search for a .l that should be called .i.
Post Reply