qSort invald memory access at Compare

Just starting out? Need help? Post your questions and find answers here.
LiK137
Enthusiast
Enthusiast
Posts: 279
Joined: Wed Jun 23, 2010 5:13 pm

qSort invald memory access at Compare

Post by LiK137 »

I am sorting list and get invalid memory access after several (5-7) sorts in:
; qsort(@idList(), ListSize(idList()) + 1, SizeOf(idStruct), @Compare())

Code: Select all

ImportC ""
  qsort(*base, num, size, *comparator)
EndImport 
ProcedureC.i Compare(*a.idStruct, *b.idStruct)
      If MemoryStringLength(@*a\name$)   ;I have added to track the problem
        If MemoryStringLength(@*b\name$) ; This throws IMAxess
    Protected Result.i
    
    Result = *a\Score - *b\Score
    
    If Result = 0
      Result = CompareMemoryString(@*a\name$, @*b\name$)
    EndIf
    
    ProcedureReturn Result
  EndIf:EndIf
EndProcedure
[13:11:13] Waiting for executable to start...
[13:11:13] Executable type: Windows - x64 (64bit, Unicode, Thread, Purifier)
[13:11:13] Executable started.
[13:15:08] [ERROR] Invalid memory access. (read error at address 1430224109825)
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: qSort invald memory access at Compare

Post by IdeasVacuum »

IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Post Reply