IMA error with #SCI_SETDOCPOINTER

Just starting out? Need help? Post your questions and find answers here.
User avatar
RSBasic
Moderator
Moderator
Posts: 1218
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

IMA error with #SCI_SETDOCPOINTER

Post by RSBasic »

Hello

It's not a direct PB bug, but when I use the Scintilla function #SCI_SETDOCPOINTER for the PureBasic ScintillaGadget, PB crashes when I press Ctrl+A and Ctrl+X.
I have developed a new tool for PureBasic to use the SplitView function of Scintilla.
The tool works, but when I press Ctrl+A and Ctrl+X PureBasic crashes with an IMA error.

Example code to enable #SCI_SETDOCPOINTER and reproduce the error:

Code: Select all

EnableExplicit

Procedure GetCurrentScintillaHandle(hwnd, lParam)
  Protected String$
  
  If GetWindowLongPtr_(hwnd, #GWL_STYLE) & #WS_VISIBLE
    String$ = Space(1024)
    GetClassName_(hwnd, @String$, Len(String$))
    If String$ = "Scintilla"
      PokeI(lParam, hwnd)
      ProcedureReturn #False
    EndIf
  EndIf
  
  ProcedureReturn #True
EndProcedure

Procedure GetLastScintillaHandle(hwnd, lParam)
  Protected String$
  Protected ScintillaLength
  
  If GetWindowLongPtr_(hwnd, #GWL_STYLE)
    String$ = Space(1024)
    GetClassName_(hwnd, @String$, Len(String$))
    If String$ = "Scintilla"
      ScintillaLength = SendMessage_(hwnd, #WM_GETTEXTLENGTH, 0, 0)
      If ScintillaLength = 0
        PokeI(lParam, hwnd)
        ProcedureReturn #False
      EndIf
    EndIf
  EndIf
  
  ProcedureReturn #True
EndProcedure

Define PBHandle
Define PBScintillaHandle
Define PBSplitViewScintillaHandle
Define PBScintillaPointer
Define ExampleCode$

ExampleCode$ + "If OpenWindow(0, 0, 0, 500, 400, " + Chr(34) + "Window" + Chr(34) + ", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)" + #LFCR$
ExampleCode$ + "  Repeat" + #LFCR$
ExampleCode$ + "    Select WaitWindowEvent()" + #LFCR$
ExampleCode$ + "      Case #PB_Event_CloseWindow" + #LFCR$
ExampleCode$ + "        End" + #LFCR$
ExampleCode$ + "    EndSelect" + #LFCR$
ExampleCode$ + "  ForEver" + #LFCR$
ExampleCode$ + "EndIf" + #LFCR$

SetClipboardText(ExampleCode$)

PBHandle = FindWindow_("WindowClass_2", 0)
If PBHandle
  SendMessage_(PBHandle, #WM_COMMAND, 0, 0)
  
  Delay(250)
  
  keybd_event_(#VK_CONTROL, #Null, #Null, #Null)
  keybd_event_(#VK_V, #Null, #Null, #Null)
  keybd_event_(#VK_CONTROL, #Null, #KEYEVENTF_KEYUP, #Null)
  keybd_event_(#VK_V, #Null, #KEYEVENTF_KEYUP, #Null)
  
  Delay(250)
  
  EnumChildWindows_(PBHandle, @GetCurrentScintillaHandle(), @PBScintillaHandle)
  SendMessage_(PBHandle, #WM_COMMAND, 0, 0)
  
  Delay(250)
  
  EnumChildWindows_(PBHandle, @GetLastScintillaHandle(), @PBSplitViewScintillaHandle)
  If PBScintillaHandle And PBSplitViewScintillaHandle
    
    PBScintillaPointer = SendMessage_(PBScintillaHandle, #SCI_GETDOCPOINTER, 0, 0)
    SendMessage_(PBSplitViewScintillaHandle, #SCI_SETDOCPOINTER, 0, PBScintillaPointer)
    
    
  Else
    Debug "ScintillaGadget not found"
  EndIf
  
Else
  Debug "PB window not found"
EndIf

Steps to reproduce the Invalid Memory Access error:
1. start the code.
2. you now have two new tabs.
2.1 The first new tab is the original tab.
2.2 The second new tab is a pointer tab.
3. choose the original tab.
4. press Ctrl+A and Ctrl+X

Video: https://www.rsbasic.de/temp/PBScintillaBug.mp4

@Fred & @freak:
Is it possible to fix the error so that I can use my tool?
Image
Image
Fred
Administrator
Administrator
Posts: 16622
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: IMA error with #SCI_SETDOCPOINTER

Post by Fred »

It does look like a hack to hook the IDE gadget, I don't think we will start to investigate such cases.
Post Reply