Page 1 of 1

[Not a bug] CloseWindow/Canvas - Invalid Memory Access PB573

Posted: Fri Mar 26, 2021 7:53 pm
by Saki
PB573 Big Sur - CloseWindow/Canvas Crash

Hi,
Maybe you can clarify it.
In the new rolling clock code, if I close the windows and don't remove the canvas with FreeGadget first there is a crash.
"Invalid memory access".
It is a small code and the lines are marked, there are only two of which one is relevant to trigger the crash.

Re: CloseWindow/Canvas - Invalid Memory Access PB573

Posted: Fri Mar 26, 2021 8:18 pm
by mk-soft
Your information is very helpful.

Which code? I assume the game counter?
Where is what marked?

Re: CloseWindow/Canvas - Invalid Memory Access PB573

Posted: Fri Mar 26, 2021 9:57 pm
by Saki
Hi
Get the module, this is the first code

Add the clock code, this is the second code

Search in the clock code this both lines : FreeGadget(canvas_ID) ; Mac need this or it crash PB573

Start the clock - Use close window - So you get the clock without menu - klick the clock - bang

The behavior is then the same as if the menu is not closed before closing the window

viewtopic.php?f=12&t=76880

Re: CloseWindow/Canvas - Invalid Memory Access PB573

Posted: Sat Mar 27, 2021 7:20 am
by TI-994A
Saki wrote:...if I close the windows and don't remove the canvas with FreeGadget first there is a crash.
This should not be necessary because all gadgets and resources associated with the window are automatically freed when the window is closed. There must be some reference to some resource of the closed window that's causing the IMA error.

Re: CloseWindow/Canvas - Invalid Memory Access PB573

Posted: Sat Mar 27, 2021 9:28 am
by Saki
Hi, that's exactly it.
It works under Linux, but the drop down menus are also not released under Linux either, which also leads to an gtk error message.
Under gtk2 and qt it is OK, under gtk3 it is not.
On Windows all is OK.

So there are several construction sites to report at once...

If you want to report it would be good, otherwise I'll do it when I have some more time (And feel like it).

Re: CloseWindow/Canvas - Invalid Memory Access PB573

Posted: Sat Mar 27, 2021 12:00 pm
by TI-994A
Saki wrote:...the drop down menus are also not released under Linux either, which also leads to an gtk error...
Here's a reduced version of the code, and it appears to work on all three platforms without the need of freeing up the menu or canvas gadget:

Code: Select all

Global window_ID, canvas_ID, menu

Procedure CreateWindow(wFlags)
  wFlags | #PB_Window_ScreenCentered
  window_ID = OpenWindow(#PB_Any, 0, 0, 300, 150, "Canvas Test", wFlags)
  canvas_ID = CanvasGadget(#PB_Any, 0, 0, 300, 150)
  If wFlags & #PB_Window_SystemMenu
    menu = CreateMenu(#PB_Any, WindowID(window_ID))
    MenuTitle("Menu")
    MenuItem(1, "Quit")
  EndIf  
EndProcedure

wFlags = #PB_Window_SystemMenu
CreateWindow(wFlags)

Repeat
  
  Delay(10)
  
  Select WindowEvent()
      
    Case #PB_Event_CloseWindow 
      PostEvent(#PB_Event_Gadget, window_ID, canvas_ID, #PB_EventType_LeftButtonDown)
      
    Case #PB_Event_Menu
      If EventMenu() = 1
        appQuit = #True
      EndIf
      
    Case #PB_Event_Gadget
      Select EventGadget()
          
        Case canvas_ID 
          If EventType() = #PB_EventType_LeftButtonDown
            
            CloseWindow(window_ID)
            
            If wFlags = #PB_Window_BorderLess
              wFlags = #PB_Window_SystemMenu
            Else
              wFlags = #PB_Window_BorderLess
            EndIf
            
            CreateWindow(wFlags)
            
          EndIf
          
      EndSelect
      
  EndSelect
  
Until appQuit

Re: CloseWindow/Canvas - Invalid Memory Access PB573

Posted: Sat Mar 27, 2021 12:37 pm
by Saki
Nice.
Please report it.
Together we simply achieve more than alone, thank you.

Re: CloseWindow/Canvas - Invalid Memory Access PB573

Posted: Sat Mar 27, 2021 1:11 pm
by TI-994A
TI-994A wrote:...it appears to work on all three platforms without the need of freeing up the menu or canvas gadget.
Saki wrote:Please report it.
:?:

Re: CloseWindow/Canvas - Invalid Memory Access PB573

Posted: Sat Mar 27, 2021 1:34 pm
by Saki
Hi,
sorry, I misunderstood.
Then the matter is clear, it is due to my VMwarePlayer.
That's why I always inquire about these things first, if a misconduct can be confirmed.

Since most use Linux VM, it is still very relevant to consider this.