It is currently Tue Mar 09, 2021 9:11 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: RemoveGadgetItem on ComboBoxGadget Bug
PostPosted: Sat Dec 05, 2020 2:02 pm 
Offline
New User
New User

Joined: Thu Jul 05, 2018 11:52 pm
Posts: 2
Hello,

There seems to be a problem with the RemoveGadgetItem command when used on a ComboBoxGadget.

It occurs when #PB_ComboBox_Image flag is set, but no image has been applied to list item.

Tested on V5.73 (x86) and (x64) when using PB's example (with ImageID removed):
Code:
UsePNGImageDecoder()
LoadImage(0, #PB_Compiler_Home + "examples/sources/Data/world.png")
 
If OpenWindow(0, 0, 0, 270, 180, "ComboBoxGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ComboBoxGadget(0, 10, 10, 250, 21, #PB_ComboBox_Editable)
    AddGadgetItem(0, -1, "ComboBox editable...")

  ComboBoxGadget(1, 10, 40, 250, 21, #PB_ComboBox_Image)
    AddGadgetItem(1, -1, "ComboBox item with image") ;, ImageID(0)  -<<<< IMAGEID REMOVED

  ComboBoxGadget(2, 10, 70, 250, 21)
    For a = 1 To 5
      AddGadgetItem(2, -1,"ComboBox item " + Str(a))
    Next

  SetGadgetState(0, 0)
  SetGadgetState(1, 0)
  SetGadgetState(2, 2)   
   
  RemoveGadgetItem(1, 0)  ; -<<<< ERROR HERE
   
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf



Top
 Profile  
Reply with quote  
 Post subject: Re: RemoveGadgetItem on ComboBoxGadget Bug
PostPosted: Sat Dec 05, 2020 2:43 pm 
Offline
Addict
Addict

Joined: Thu Apr 18, 2019 8:17 am
Posts: 1337
Confirmed. Crashes here with an "Invalid memory access" error on the RemoveGadgetItem() line.

And here's another related bug: When an image is assigned to the added item, but then the item is removed before the event loop, the item is still visible (image and text) until the mouse is moved over it. But you can make it go away correctly with InvalidateRect_() API call. Try this:

Code:
UsePNGImageDecoder()
LoadImage(0, #PB_Compiler_Home + "examples/sources/Data/world.png")

If OpenWindow(0, 0, 0, 270, 180, "ComboBoxGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ComboBoxGadget(0, 10, 10, 250, 21, #PB_ComboBox_Editable)
  AddGadgetItem(0, -1, "ComboBox editable...")
 
  ComboBoxGadget(1, 10, 40, 250, 21, #PB_ComboBox_Image)
  AddGadgetItem(1, -1, "ComboBox item with image", ImageID(0))
 
  ComboBoxGadget(2, 10, 70, 250, 21)
  For a = 1 To 5
    AddGadgetItem(2, -1,"ComboBox item " + Str(a))
  Next
 
  SetGadgetState(0, 0)
  SetGadgetState(1, 0)
  SetGadgetState(2, 2)   
 
  RemoveGadgetItem(1, 0) ; Item with image is still visible until the mouse is moved over it.
  ;InvalidateRect_(GadgetID(1),0,1) ; Uncomment this line to fix the bug.
 
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf


Top
 Profile  
Reply with quote  
 Post subject: Re: RemoveGadgetItem on ComboBoxGadget Bug
PostPosted: Sat Dec 05, 2020 6:36 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2890
Location: Germany
Very old mistake. Does not work with v5.46 already.

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: RemoveGadgetItem on ComboBoxGadget Bug
PostPosted: Sat Dec 05, 2020 6:48 pm 
Offline
New User
New User

Joined: Thu Jul 05, 2018 11:52 pm
Posts: 2
Quote:
RemoveGadgetItem(1, 0) ; Item with image is still visible until the mouse is moved over it.
; InvalidateRect_(GadgetID(1),0,1) ; Uncomment this line to fix the bug.

SetGadgetState(1, 0) also fixes that issue... even though item 0 should no longer exist.


Top
 Profile  
Reply with quote  
 Post subject: Re: RemoveGadgetItem on ComboBoxGadget Bug
PostPosted: Sat Dec 05, 2020 11:11 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2890
Location: Germany
Macro Workaround ...
Code:
;-TOP
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
  Macro _PB_(Function)
    Function
  EndMacro
 
  Macro FixRemoveGadgetItem(Gadget, Position)
    If GadgetType(Gadget) = #PB_GadgetType_ComboBox
      SetGadgetItemImage(Gadget, Position, 0)
      _PB_(RemoveGadgetItem)(Gadget, Position)
      SetGadgetState(Gadget, 0)
    Else
      _PB_(RemoveGadgetItem)(Gadget, Position)
    EndIf 
  EndMacro
 
  Macro RemoveGadgetItem(Gadget, Position)
    FixRemoveGadgetItem(Gadget, Position)
  EndMacro
CompilerEndIf

UsePNGImageDecoder()
LoadImage(0, #PB_Compiler_Home + "examples/sources/Data/world.png")
 
If OpenWindow(0, 0, 0, 270, 180, "ComboBoxGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ComboBoxGadget(0, 10, 10, 250, 21, #PB_ComboBox_Editable)
    AddGadgetItem(0, -1, "ComboBox editable...")

  ComboBoxGadget(1, 10, 40, 250, 21, #PB_ComboBox_Image)
    AddGadgetItem(1, -1, "ComboBox item with image"); ImageID(0)) ; -<<<< IMAGEID REMOVED

  ComboBoxGadget(2, 10, 70, 250, 21)
    For a = 1 To 5
      AddGadgetItem(2, -1,"ComboBox item " + Str(a))
    Next

  SetGadgetState(0, 0)
  SetGadgetState(1, 0)
  SetGadgetState(2, 2)   
 
  RemoveGadgetItem(1, 0)  ; -<<<< ERROR HERE
 
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye