Page 2 of 5

Posted: Tue Jul 17, 2007 6:11 pm
by Xombie
Karbon - it'd take me about an hour or two to fix up (read: update horribly old code) my autocomplete routines if you want me to do it.

<Xombie slowly sneaks out of freak's thread>

Posted: Tue Jul 17, 2007 6:13 pm
by Karbon
Just heard back. 5 reports already of the crash with the new memory lib... I asked them to report the contents of the message requester (to see if the heap invalid message is displaying) but no one has said that they saw it. That shouldn't be taken to mean that no one did, people are pretty notorious for not reporting that stuff.

I'll send it to a few people specifically and see if they can tell me if the heap invalid message is shown.

Posted: Tue Jul 17, 2007 6:14 pm
by Karbon
Hey Xombie -- I actually like the API's flexibility in the different styles it supports but I can't use it if it keeps crashing without explanation.

If I can't get this moving in the next couple of days I'll have to switch!

Posted: Tue Jul 17, 2007 6:53 pm
by Trond
It could also be that the actual AllocateMemory() is overwritten by some garbage.

Posted: Tue Jul 17, 2007 7:20 pm
by Karbon
Just heard back.. The crash happens and does *not* display the heap invalid error, so according to that code you sent it's valid..

Crazy, eh?

See... A few thousand users can break anything! :-)

Posted: Thu Jul 19, 2007 2:00 pm
by freak
I just realized i made a mistake with the heap validation.
The AllocateMemory() command actually has its separate heap from the one used
by the other PB libraries (which makes sense). So we were testing the wrong one.

Here we go again:
This one tests the heap used for string storage, the one
from AllocateMemory(), and the one for the PB libraries

Code: Select all

Procedure ValidatePBHeap(LineNumber)
  Protected StringHeap, MemoryHeap, InternalHeap
  
  !extrn _PB_Memory_Heap
  !extrn _PB_StringHeap
  
  !mov eax, dword [_PB_MemoryBase]
  !mov [p.v_InternalHeap], eax
  !mov eax, dword [_PB_StringHeap]
  !mov [p.v_StringHeap], eax
  !mov eax, dword [_PB_Memory_Heap]
  !mov [p.v_MemoryHeap], eax    
  
  If HeapValidate_(StringHeap, 0, 0) = 0
    MessageRequester("Error", "String Heap invalid at Line: "+Str(LineNumber))
  EndIf    
  If HeapValidate_(MemoryHeap, 0, 0) = 0
    MessageRequester("Error", "Memory Heap invalid at Line: "+Str(LineNumber))
  EndIf   
  If HeapValidate_(InternalHeap, 0, 0) = 0
    MessageRequester("Error", "Internal Memory Heap invalid at Line: "+Str(LineNumber))
  EndIf 
EndProcedure

Macro _validate
  ValidatePBHeap(#PB_Compiler_Line)
EndMacro
Please test it again.

Posted: Thu Jul 19, 2007 2:55 pm
by Karbon
Got it and just sent it out... I should hear something back in a few hours..

Posted: Thu Jul 19, 2007 4:17 pm
by Karbon
Wow, sure enough, I can reproduce it on another Windows XP Pro computer here..

Code: Select all

Procedure New_EnumString(StringArray$(1), StringCount)
  *THIS.EnumString = 0
  
  Size = 4 + StringCount * 4
  For i = 0 To StringCount-1
    Size + Len(StringArray$(i)) * 2 + 2
  Next i
  
  _validate ; THIS REPORTS INVALID HEAP AND CRASHES RIGHT AFTER
  
  *StringBuffer.EnumStringBuffer = AllocateMemory(Size)
  If *StringBuffer
    *StringBuffer\RefCount = 1
    *Pointer = *StringBuffer + 4 + StringCount * 4
    
    For i = 0 To StringCount - 1     
      *StringBuffer\Strings[i] = *Pointer 
      PokeS(*Pointer, StringArray$(i), -1, #PB_Unicode)
      *Pointer + Len(StringArray$(i)) * 2 + 2
    Next i
    
    _validate
    
    *THIS = AllocateMemory(SizeOf(EnumString))
    If *THIS
      *THIS\Vtbl        = ?IEnumStringVtbl
      *THIS\RefCount    = 1
      *THIS\StringCount = StringCount
      *THIS\Enumerator  = 0
      *THIS\Buffer      = *StringBuffer
    Else
      FreeMemory(*StringBuffer)
    EndIf
  EndIf   
  
  ProcedureReturn *THIS
EndProcedure

Posted: Thu Jul 19, 2007 4:46 pm
by freak
Atleast a step in the right direction... :)

Now the problem must be somewhere before this line is reached.
Some pointer stuff, PokeS() or other memory access must be going wrong.

You'll just have to throw some _validate lines around the code to find out where.

(I just hope its not in my code :))

Posted: Thu Jul 19, 2007 7:10 pm
by Karbon
Found it.

Looks like this isn't very unicode friendly.. I'll give it a go at re-writing it.

Code: Select all

Procedure.l AddODBCConnection(Driver$,Attributes$)
  While Right(Attributes$,2)<>";;"
    Attributes$+";"
  Wend
  
  _validate
  
  *LPAttribMem=AllocateMemory(Len(Attributes$)*SizeOf(CHARACTER))
  
  _validate
  
  PokeS(*LPAttribMem,Attributes$,Len(Attributes$))
  
  _validate ; < - INVALID HERE
  
  For l=1 To Len(Attributes$)
    CompilerIf #PB_Compiler_Unicode
    If PeekW(*LPAttribMem + (l-1) * SizeOf(CHARACTER))=Asc(";")
      PokeW(*LPAttribMem + (l-1) * SizeOf(CHARACTER),0)
    EndIf
    CompilerElse
    If PeekB(*LPAttribMem + l -1)=Asc(";")
      PokeB(*LPAttribMem + l -1,0)
    EndIf
    CompilerEndIf
  Next
  
  _validate
  
  result=SQLConfigDataSource_(0,#ODBC_ADD_DSN,Driver$,*LPAttribMem)
  
  FreeMemory(*LPAttribMem)
  
  ProcedureReturn result
  
EndProcedure

Posted: Thu Jul 19, 2007 7:46 pm
by freak
You are not allocating enough space for *LPAttribMem
PokeS() also writes the ending NULL, so you need (Len(Attributes$)+1)*SizeOf(CHARACTER) bytes of space.

Posted: Thu Jul 19, 2007 8:52 pm
by Karbon
Wow! Forest for the trees on that one.

THANK YOU!

Posted: Fri Jul 20, 2007 7:56 am
by ABBKlaus

Posted: Fri Jul 20, 2007 12:20 pm
by Karbon
Yea, I never knew it was updated since you just hit "edit" instead of "reply" :-)

Posted: Fri Nov 30, 2007 1:33 am
by kinglestat
is it possible to have diff gadgets with different arrays with autocomplete at the same time?

And how do you add items to list while program is running?