Illegal storage access... Problem

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
oscarchan
Posts: 47
Joined: Mon Apr 11, 2022 2:04 am

Illegal storage access... Problem

Post by oscarchan »

Hi guys! I run Freecad on a 【win10】 computer.
When I tried the code below in FC 0.18【python version 3.6.6】, the html page would display successfully.
But in FC 0.19 and FC 0.20【both in python version 3.8.10】 it failed with an unhandled exception dialog showing. Also the report view said " Illegal storage access..."
Is it something wrong with the HTML file or the WebGui???

Code: Select all

import WebGui
import os
from mod.file_tools import get_path

browser = WebGui.openBrowserWindow('start')
html_path = os.path.join(get_path(), "welcome_page.html")
with open(html_path, "r", encoding="utf8") as file:
    html_str = file.read()
    
html_str = html_str.replace("GIFPATH", "file:///" + os.path.join(get_path(), "images\welcome.gif"))
browser.setHtml(html_str)
Here is the html file.

Code: Select all

<!doctype html>
<html>
<head>
    <meta charset="UTF-8" />
    <title>Welcome</title>
    <style>
        .gif{width: 100%;height:100%;}
    </style>

</head>
<body>
    <div>
        <img src="GIFPATH" class="gif">
    </div>
</body>
</html>

After replacing the GIFPATH , html_str would be
'<!doctype html>\n<html>\n<head>\n <meta charset="UTF-8" />\n <title>Welcome</title>\n <style>\n .gif{width: 100%;height:100%;}\n </style>\n\n</head>\n<body>\n <div>\n <img src="file:///F:\\FreeCad 0.20\\Mod\\Design\\mod/../images\\welcome.gif" class="gif">\n </div>\n</body>\n</html>'
Last edited by oscarchan on Mon Sep 19, 2022 9:04 am, edited 1 time in total.
Thank you!
chrisb
Veteran
Posts: 54207
Joined: Tue Mar 17, 2015 9:14 am

Re: Illegal storage access... Problem

Post by chrisb »

Please retry with 0.21.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
Syres
Veteran
Posts: 2900
Joined: Thu Aug 09, 2018 11:14 am

Re: Illegal storage access... Problem

Post by Syres »

I'm fairly certain your code won't work with any recent Python 3.x, I couldn't actually test this fully as I don't have a workbench to mess with but hopefully you'll be able to make progress with it:

Code: Select all

import WebGui
import os

browser = WebGui.openBrowserWindow('start')
html_path = os.path.dirname(__file__) + os.sep + "welcome_page.html"
with open(html_path, "r", encoding="utf8") as file:
    html_str = file.read()
newHtml = "file:///" + os.path.dirname(__file__) + os.sep + "images" + os.sep + "welcome.gif"
html_str = html_str.replace("GIFPATH", newHtml)
browser.setHtml(html_str)
oscarchan
Posts: 47
Joined: Mon Apr 11, 2022 2:04 am

Re: Illegal storage access... Problem

Post by oscarchan »

Thanks for that. But it still doesn't work.
Thank you!
User avatar
onekk
Veteran
Posts: 6208
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Illegal storage access... Problem

Post by onekk »

oscarchan wrote: Mon Sep 19, 2022 1:18 am Thanks for that. But it still doesn't work.
Please add information required in:

https://forum.freecadweb.org/viewtopic.php?f=3&t=2264

As it may depends even on what version of python you are trying to use, and almost surely on what Qt version you are testing the code, and very probably even on what OS are you using.

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
oscarchan
Posts: 47
Joined: Mon Apr 11, 2022 2:04 am

Re: Illegal storage access... Problem

Post by oscarchan »

onekk wrote: Mon Sep 19, 2022 8:23 am
oscarchan wrote: Mon Sep 19, 2022 1:18 am Thanks for that. But it still doesn't work.
Please add information required in:

https://forum.freecadweb.org/viewtopic.php?f=3&t=2264

As it may depends even on what version of python you are trying to use, and almost surely on what Qt version you are testing the code, and very probably even on what OS are you using.

Regards

Carlo D.
Thanks for the reminder.
Thank you!
User avatar
onekk
Veteran
Posts: 6208
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Illegal storage access... Problem

Post by onekk »

oscarchan wrote: Mon Sep 19, 2022 9:05 am ...
Thanks for the reminder.
[/quote]

OK but as your report didn't say nothing about Qt versions it is not very useful for people who are willing to help, as you are using Qt related things.

The procedure is clear and will result in something like:

Code: Select all

OS: Artix Linux (openbox)
Word size of FreeCAD: 64-bit
Version: 0.21.30345 (Git)
Build type: Release
Branch: master
Hash: f42a47aa0fd8c4f34ef63c185d9f29b9b6e84737
Python 3.10.6, Qt 5.15.4, Coin 4.0.0, Vtk 9.1.0, OCC 7.6.3
Locale: Italian/Italy (it_IT)
Installed mods: 
  * Curves.backup1662281788.2751102 0.4.1
  * fcgear.backup1662281841.5151978 1.0.0
  * test_wb
  * fcgear 1.0.0
  * Curves 0.5.8
  * Help.backup1662281850.737508 1.0.3
  * Help 1.0.3

Code: Select all

OS: Artix Linux (openbox)
Word size of FreeCAD: 64-bit
Version: 0.20.1.29410 (Git) AppImage
Build type: Release
Branch: (HEAD detached at 0.20.1)
Hash: f5d13554ecc7a456fb6e970568ae5c74ba727563
Python 3.10.5, Qt 5.15.4, Coin 4.0.0, Vtk 9.1.0, OCC 7.6.2
Locale: Italian/Italy (it_IT)
Installed mods: 
  * Curves 0.5.7
As you could see this is containing all the relevant infos, and some more that could be "relevant" to try to see why it is not working.

For 0.18 you maybe have to add the code tag by hand (sorry but I've not anymore a copy of 0.18 installed, to make tests.)

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
Post Reply