Page 1 of 1

WebGadget-Invalid Memory Access

Posted: Fri Jun 14, 2024 5:41 pm
by WilliamL
I've just discovered the webgadget and have a problem. I have a window based on the example 'The Worlds Smallest Browser' (can't find the link right now), in my large program, and it works fine if I resize or close the window but if I click anywhere in the web window then hit the close button (red dot) I get a Invalid Memory Access in the main event loop. If the program is compiled it just crashes.

I've re-created the error but maybe only on this link?

Code: Select all

EnableExplicit

Define event

#window1=1
#window2=2
#webgadget1=1

If OpenWindow(#window1, 0, 0,865,535, "WebGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget) 
    ;WebGadget(#webgadget1, 0, 0,WindowWidth(#window1),WindowHeight(#window1), "file://MacBkPro_SSD/Users/vering2/Apps_stuff/PB_examples/WebCamAddict.jpg")
    WebGadget(#webgadget1, 0, 0,WindowWidth(#window1),WindowHeight(#window1), "https://finance.yahoo.com/quote/%5EIXIC/")
    ; Note: if you want to use a local file, change last parameter to "file://" + path + filename 
EndIf 

If OpenWindow(#window2, 10, 10,20,20, "blank window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget) 
EndIf 

Repeat
     Event = WaitWindowEvent()
     
     Select Event
         Case #PB_Event_CloseWindow
            CloseWindow(#window1) : Debug"Close window"
        Case #PB_Event_SizeWindow
            If EventGadget()=#webgadget1
                ResizeGadget(#webgadget1,#PB_Ignore,#PB_Ignore,WindowWidth(#window1),WindowHeight(#window1))
            EndIf     
    EndSelect
ForEver
Worlds Smallest Web Browser (Mini Browser)
https://www.purebasic.com/documentation ... er.pb.html

Re: WebGadget-Invalid Memory Access

Posted: Tue Jun 18, 2024 6:21 am
by fsw
I think the crash you are experiencing is not the WebGadget's fault.
In your code you close the Window, but never exit the event loop.
Your app never ends...

This works:

Code: Select all

EnableExplicit

Define event

#window1=1
#window2=2
#webgadget1=1

If OpenWindow(#window1, 0, 0,865,535, "WebGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget) 
    ;WebGadget(#webgadget1, 0, 0,WindowWidth(#window1),WindowHeight(#window1), "file://MacBkPro_SSD/Users/vering2/Apps_stuff/PB_examples/WebCamAddict.jpg")
    WebGadget(#webgadget1, 0, 0,WindowWidth(#window1),WindowHeight(#window1), "https://finance.yahoo.com/quote/%5EIXIC/")
    ; Note: if you want to use a local file, change last parameter to "file://" + path + filename 
EndIf 

If OpenWindow(#window2, 10, 10,20,20, "blank window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget) 
EndIf 

Repeat
     Event = WaitWindowEvent()
     
     Select Event
        ;Case #PB_Event_CloseWindow
        ;    CloseWindow(#window1) : Debug"Close window"
        Case #PB_Event_SizeWindow
            If EventGadget()=#webgadget1
                ResizeGadget(#webgadget1,#PB_Ignore,#PB_Ignore,WindowWidth(#window1),WindowHeight(#window1))
            EndIf     
    EndSelect
;ForEver
Until Event = #PB_Event_CloseWindow
Debug"Window closed"
In this case, the event loop ends when the window is closed.
Therefore, the app ends as well.

Re: WebGadget-Invalid Memory Access

Posted: Tue Jun 18, 2024 5:03 pm
by WilliamL
Thanks for the comment fsw,

I've modified my code so it will end but it still crashes if I select any text in the web window.

Code: Select all

EnableExplicit

Define event

#window1=1
#window2=2
#webgadget1=1

If OpenWindow(#window1, 0, 0,865,535, "WebGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget) 
    ;WebGadget(#webgadget1, 0, 0,WindowWidth(#window1),WindowHeight(#window1), "file://MacBkPro_SSD/Users/vering2/Apps_stuff/PB_examples/WebCamAddict.jpg")
    WebGadget(#webgadget1, 0, 0,WindowWidth(#window1),WindowHeight(#window1), "https://finance.yahoo.com/quote/%5EIXIC/")
    ; Note: if you want to use a local file, change last parameter to "file://" + path + filename 
EndIf 

If OpenWindow(#window2, 10, 10,80,80, "blank window", #PB_Window_SystemMenu | #PB_Window_SizeGadget) 
EndIf 

Repeat
     Event = WaitWindowEvent()
     
     Select Event
     Case #PB_Event_CloseWindow
         If EventWindow()=#window2 : End
             Else
                 CloseWindow(#window1) : Debug"Close window"
             EndIf   
    EndSelect
ForEver

Re: WebGadget-Invalid Memory Access

Posted: Tue Jun 18, 2024 8:17 pm
by fsw
Tried your code, but I cannot make it crash.
I can click on any text (link) and the next website is opened.

Testing this on PB-6.11-LTS on macOS Sonoma 14.5 on MacBook Pro M1-MAX.
Xcode & Command Line Tools are current.

Re: WebGadget-Invalid Memory Access

Posted: Fri Aug 09, 2024 5:47 pm
by Fred
I can't reproduce it here, can anybody else try it ?

Re: WebGadget-Invalid Memory Access

Posted: Sun Aug 11, 2024 10:55 pm
by WilliamL
Well, if I select any text in the window of my example, say the closing price then hit the close button I get the error.

But if I'm the only one then I would remove my bug report and assume I'm doing something wrong with my code.

Re: WebGadget-Invalid Memory Access

Posted: Mon Aug 12, 2024 9:33 am
by mk-soft
I can confirm your example with your link.
But it doesn't happen with every website.

This error does not occur with PB v6.11.

Re: WebGadget-Invalid Memory Access

Posted: Tue Aug 13, 2024 6:01 pm
by WilliamL
Yes, I agree that it appears to be this website. Other websites work fine (like the PB document). I'm wondering if this site being interactive (you can move the graph etc) is the problem. Maybe it has it's own event loop that is activated when you click in the window.