PureBasic Forum
http://forums.purebasic.com/english/

[Windows] AutoComplete for StringGadgets
http://forums.purebasic.com/english/viewtopic.php?f=12&t=24721
Page 2 of 5

Author:  Xombie [ Tue Jul 17, 2007 6:11 pm ]
Post subject: 

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>

Author:  Karbon [ Tue Jul 17, 2007 6:13 pm ]
Post subject: 

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.

Author:  Karbon [ Tue Jul 17, 2007 6:14 pm ]
Post subject: 

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!

Author:  Trond [ Tue Jul 17, 2007 6:53 pm ]
Post subject: 

It could also be that the actual AllocateMemory() is overwritten by some garbage.

Author:  Karbon [ Tue Jul 17, 2007 7:20 pm ]
Post subject: 

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! :-)

Author:  freak [ Thu Jul 19, 2007 2:00 pm ]
Post subject: 

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:
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.

Author:  Karbon [ Thu Jul 19, 2007 2:55 pm ]
Post subject: 

Got it and just sent it out... I should hear something back in a few hours..

Author:  Karbon [ Thu Jul 19, 2007 4:17 pm ]
Post subject: 

Wow, sure enough, I can reproduce it on another Windows XP Pro computer here..

Code:
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

Author:  freak [ Thu Jul 19, 2007 4:46 pm ]
Post subject: 

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 :))

Author:  Karbon [ Thu Jul 19, 2007 7:10 pm ]
Post subject: 

Found it.

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

Code:
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

Author:  freak [ Thu Jul 19, 2007 7:46 pm ]
Post subject: 

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.

Author:  Karbon [ Thu Jul 19, 2007 8:52 pm ]
Post subject: 

Wow! Forest for the trees on that one.

THANK YOU!

Author:  ABBKlaus [ Fri Jul 20, 2007 7:56 am ]
Post subject: 

you did not use my latest version :twisted:

http://www.purebasic.fr/english/viewtopic.php?p=197128#197128

Author:  Karbon [ Fri Jul 20, 2007 12:20 pm ]
Post subject: 

Yea, I never knew it was updated since you just hit "edit" instead of "reply" :-)

Author:  kinglestat [ Fri Nov 30, 2007 1:33 am ]
Post subject: 

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?

Page 2 of 5 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/