JacquesLucke / blender_vscode

Visual Studio Code extension for Blender development.
MIT License
580 stars 75 forks source link

Blender crashes immediately after launching my addon through blender_vscode #206

Open enenra opened 1 month ago

enenra commented 1 month ago
ADDONS_TO_LOAD [{'load_dir': 'd:\\Modding\\Space Engineers\\tools\\Blender\\Add-ons\\space-engineers-utilities\\space-engineers-utilities', 'module_name': 'space-engineers-utilities'}, {'load_dir': 'c:\\Program Files\\Blender Foundation\\Blender 4.2\\4.2\\scripts\\templates_toml', 'module_name': 'templates_toml'}]
DEBUG: new extensions repository "vscode_development" created
Traceback (most recent call last):
  File "c:\Users\enenra\.vscode\extensions\jacqueslucke.blender-development-0.0.24\pythonFiles\launch.py", line 26, in <module>
    blender_vscode.startup(
  File "c:\Users\enenra\.vscode\extensions\jacqueslucke.blender-development-0.0.24\pythonFiles\include\blender_vscode\__init__.py", line 26, in startup
    path_mappings = load_addons.setup_addon_links(addons_to_load)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\enenra\.vscode\extensions\jacqueslucke.blender-development-0.0.24\pythonFiles\include\blender_vscode\load_addons.py", line 38, in setup_addon_links
    load_path = _link_addon_or_extension(addon_info)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\enenra\.vscode\extensions\jacqueslucke.blender-development-0.0.24\pythonFiles\include\blender_vscode\load_addons.py", line 64, in _link_addon_or_extension
    if addon_has_bl_info(addon_info.load_dir) and is_in_any_addon_directory(addon_info.load_dir):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\enenra\.vscode\extensions\jacqueslucke.blender-development-0.0.24\pythonFiles\include\blender_vscode\utils.py", line 19, in addon_has_bl_info
    with open(addon_dir / "__init__.py") as init_addon_file:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: 'c:\\Program Files\\Blender Foundation\\Blender 4.2\\4.2\\scripts\\templates_toml\\__init__.py'
 *  Terminal will be reused by tasks, press any key to close it. 

Win10, VSC in normal mode (but admin has the same issue)

My addon: https://github.com/enenra/space-engineers-utilities

Note that this issue appears only on my desktop PC, it's fine on my laptop. It only appears with Blender 4.2 - older versions of Blender are fine, though Add-on not loaded: "templates_toml", cause: appears - nothing after the colon.

My addon is not in a templates_toml-folder. It's where it's supposed to be - in its own folder. image

Mateusz-Grzelinski commented 1 month ago

uhh, in this logic I forgot to respect setting called blender.addon.moduleName and I thought the error (file that not exesits) will be catch by uper function in call stack. addon_has_bl_info needs to be improved.

Are you using the setting blender.addon.moduleName in you current config? i am asking just to be sure

Mateusz-Grzelinski commented 1 month ago

when you open the VS code directly inside folder space-engineers-utilities it should work.

enenra commented 1 month ago

uhh, in this logic I forgot to respect setting called blender.addon.moduleName and I thought the error (file that not exesits) will be catch by uper function in call stack. addon_has_bl_info needs to be improved.

Are you using the setting blender.addon.moduleName in you current config? i am asking just to be sure

I'm not using blender.addon.moduleName, no. Unsure where / how I would use that?

And how would I do this with the directory inside the addon folder? My workspace file is in there so it should always be that directory I think.

Mateusz-Grzelinski commented 1 month ago

I am basically asking you to paste all blender related VS code settings that you use.

enenra commented 1 month ago
{
    "python.languageServer": "Pylance",
    "blender.executables": [
        {
            "path": "c:\\Program Files\\Blender Foundation\\Blender 4.1\\blender.exe",
            "name": "",
            "isDebug": false
        },
        {
            "path": "c:\\Program Files\\Blender Foundation\\Blender 4.2\\blender.exe",
            "name": "",
            "isDebug": false
        }
    ],
}

This is my entire settings.json - admin edited to relevant parts. I don't think I have any specific blender settings aside from the path itself.

Mateusz-Grzelinski commented 1 month ago

this is the part when I say:

  1. how on did you got that log...
  2. it works for me... obraz
enenra commented 1 month ago

Yes, as I stated in the initial post it only happens on my desktop PC. It works fine on my laptop.

I get the error when hitting Ctrl+Shift+P > Start Blender > 4.2 . Then Blender briefly comes up and then closes again and I get the output from above.

I have tried reinstalling the plugin, as well as Blender itself.

Mateusz-Grzelinski commented 1 month ago

I hope you sent me the config from the problematic PC? xD

sry, missed that, I am tired today.

enenra commented 1 month ago

Of course.

enenra commented 1 month ago

One other thing I should note, I forgot to mention it, is that initially I got a different error. Initially I got a straight up Blender crash with a Blender crash log. An access violation:

blender.crash.txt

I was trying to get it to work for a couple hours and what finally made a difference was to edit the Blender code and comment out the bit where it calls the function that causes the crash:

  File "c:\Program Files\Blender Foundation\Blender 4.2\4.2\scripts\addons_core\bl_pkg\bl_extension_ui.py", line 453 in addons_panel_draw_items

Blender still then crashed on startup but differently, and that is where the above stuff started. Sorry, should've started with that.

Mateusz-Grzelinski commented 1 month ago
  1. try deleting the links in blender config - let vs code recreate them.
  2. try running the vs code with
    "blender.environmentVariables": {
    "BLENDER_USER_RESOURCES": "./blender_vscode_development" // changes folder for addons, extensions, modules, config
    },

    see readme

I want to make sure that blender config is ok - those are various ways of cleanup

Mateusz-Grzelinski commented 1 month ago

One other thing I should note, I forgot to mention it, is that initially I got a different error. Initially I got a straight up Blender crash with a Blender crash log. An access violation:

blender.crash.txt

I was trying to get it to work for a couple hours and what finally made a difference was to edit the Blender code and comment out the bit where it calls the function that causes the crash:

  File "c:\Program Files\Blender Foundation\Blender 4.2\4.2\scripts\addons_core\bl_pkg\bl_extension_ui.py", line 453 in addons_panel_draw_items

Blender still then crashed on startup but differently, and that is where the above stuff started. Sorry, should've started with that.

this might be #192 - I am noticing that downgrading wergzeug to 3.0.3 still causes the issues to appear, or my current fix is ineffective... the proper fix is coming in #201

Sorry about your hours of debugging, I know how annoying this is, but it is not obvious to fix without creating new problems. A review is needed, the implementattion is there.

enenra commented 1 month ago

Yes it definitely sounds like #191 though I get it on startup, not just when opening preferences.

Mateusz-Grzelinski commented 1 month ago

if you dig ver very deep into developers formu you will find that the issue is import multiprocessing - so if you import it in any dependencies you blender will hard crash.

Mateusz-Grzelinski commented 1 month ago

btw if you use - in your path names your addon will not work nice with extensions

enenra commented 1 month ago

if you dig ver very deep into developers formu you will find that the issue is import multiprocessing - so if you import it in any dependencies you blender will hard crash.

I've removed that since I wasn't using it anyway. But the crash with addon_utils is still there. I guess I somehow now have to get back to the access violation crash?

And regarding the - yeah, idk if that's easy to change at this point though. Unsure if I will change it to an extension anyway atm.

Mateusz-Grzelinski commented 1 month ago

My head is not working today, need to sleep. Jus make sure that wrrgzeug dependency does not contain string multiprocessing (v3.0.4)

enenra commented 1 month ago

Okay, I think I've done that since I only import it in a single file and it was unused there.

What I'm unsure about is what I should be doing now? Is this something you can fix on your end in a VSC plugin update? Or should I try to get back to the access violation error?

And please don't stay up on my behalf. An answer can wait till tomorrow. 👍

Mateusz-Grzelinski commented 1 month ago

The multiprocessing is issue with blender itself. You will find tracking link in 191.

On my side I tried to lock werkzeug dependency to version 3.0.3 but I am not sure if it is effective.

enenra commented 1 month ago

Okay, but the error I have right now is the template_toml one - is this something you can fix or can I try something else on my end?

Mateusz-Grzelinski commented 1 month ago

Try running the blender with clean config. See the env vars above. Of the problem persists I will investigate

enenra commented 1 month ago

Clean config as in the stuff that you load from a previous version the first time you start a new version? Sorry, unsure which config you're referring to...

Mateusz-Grzelinski commented 1 month ago
  1. try deleting the links in blender config - let vs code recreate them.

    1. try running the vs code with
"blender.environmentVariables": {
    "BLENDER_USER_RESOURCES": "./blender_vscode_development" // changes folder for addons, extensions, modules, config
},

see readme

I want to make sure that blender config is ok - those are various ways of cleanup

If you use env var you can force blender to start with no config. I want to check if your config is ok

enenra commented 1 month ago

Ah, I see. Sorry, I missed that post originally. I did both things, but still get the exact same error with templates_toml.

*  Executing task in folder space-engineers-utilities: C:\Program Files\Blender Foundation\Blender 4.2\blender.exe --python c:\Users\enenra\.vscode\extensions\jacqueslucke.blender-development-0.0.24\pythonFiles\launch.py 

ADDONS_TO_LOAD [{'load_dir': 'd:\\Modding\\Space Engineers\\tools\\Blender\\Add-ons\\space-engineers-utilities\\space-engineers-utilities', 'module_name': 'space-engineers-utilities'}, {'load_dir': 'c:\\Program Files\\Blender Foundation\\Blender 4.2\\4.2\\scripts\\templates_toml', 'module_name': 'templates_toml'}]
DEBUG: new extensions repository "vscode_development" created
INFO: Removing old link: blender_vscode_development\scripts\addons\space-engineers-utilities
Traceback (most recent call last):
  File "c:\Users\enenra\.vscode\extensions\jacqueslucke.blender-development-0.0.24\pythonFiles\launch.py", line 26, in <module>
    blender_vscode.startup(
  File "c:\Users\enenra\.vscode\extensions\jacqueslucke.blender-development-0.0.24\pythonFiles\include\blender_vscode\__init__.py", line 26, in startup
    path_mappings = load_addons.setup_addon_links(addons_to_load)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\enenra\.vscode\extensions\jacqueslucke.blender-development-0.0.24\pythonFiles\include\blender_vscode\load_addons.py", line 38, in setup_addon_links
    load_path = _link_addon_or_extension(addon_info)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\enenra\.vscode\extensions\jacqueslucke.blender-development-0.0.24\pythonFiles\include\blender_vscode\load_addons.py", line 64, in _link_addon_or_extension
    if addon_has_bl_info(addon_info.load_dir) and is_in_any_addon_directory(addon_info.load_dir):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\enenra\.vscode\extensions\jacqueslucke.blender-development-0.0.24\pythonFiles\include\blender_vscode\utils.py", line 19, in addon_has_bl_info
    with open(addon_dir / "__init__.py") as init_addon_file:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: 'c:\\Program Files\\Blender Foundation\\Blender 4.2\\4.2\\scripts\\templates_toml\\__init__.py'
 *  Terminal will be reused by tasks, press any key to close it. 

Note how the load_dir in the header there is wrong, and this causes the error I guess.

Weird thing though: Now, when I start Blender 4.1 through VSCode, it doesn't load my startup file, and doesn't offer me to load it either. If I start Blender 4.1 normally through its own shortcut, it loads fine...

Mateusz-Grzelinski commented 1 month ago

The env var that you set affects also startup file. Remove the env var to get back to normal.

The loaddir looks bad, I will look into it and I will try to read into this logic. If I don't come up with anything we can do a debug session together

enenra commented 1 month ago

Gotcha. Yeah, I should be available evenings EU time or on the weekend.

enenra commented 1 month ago

Hi, did you have time to look into this yet? Sorry for being pushy - my addon breaks with 4.2 and I can't really fix it properly until I can run my dev environment through VSC.

Mateusz-Grzelinski commented 1 month ago

I did some progress in the pr, but it is still in review. Sorry, I had other things to attend to.

enenra commented 1 month ago

No worries. Good to hear it's coming along! Happy to do testing.

enenra commented 1 month ago

I got pointed to the Blender Portable release to try whether that works by a friend. Unfortunately that has exactly the same issue.

DEBUG: new extensions repository "vscode_development" created
Traceback (most recent call last):
  File "c:\Users\enenra\.vscode\extensions\jacqueslucke.blender-development-0.0.24\pythonFiles\launch.py", line 26, in <module>
    blender_vscode.startup(
  File "c:\Users\enenra\.vscode\extensions\jacqueslucke.blender-development-0.0.24\pythonFiles\include\blender_vscode\__init__.py", line 26, in startup
    path_mappings = load_addons.setup_addon_links(addons_to_load)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\enenra\.vscode\extensions\jacqueslucke.blender-development-0.0.24\pythonFiles\include\blender_vscode\load_addons.py", line 38, in setup_addon_links
    load_path = _link_addon_or_extension(addon_info)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\enenra\.vscode\extensions\jacqueslucke.blender-development-0.0.24\pythonFiles\include\blender_vscode\load_addons.py", line 64, in _link_addon_or_extension
    if addon_has_bl_info(addon_info.load_dir) and is_in_any_addon_directory(addon_info.load_dir):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\enenra\.vscode\extensions\jacqueslucke.blender-development-0.0.24\pythonFiles\include\blender_vscode\utils.py", line 19, in addon_has_bl_info
    with open(addon_dir / "__init__.py") as init_addon_file:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: 'c:\\Program Files\\Blender Foundation\\Blender 4.2\\4.2\\scripts\\templates_toml\\__init__.py'
 *  Terminal will be reused by tasks, press any key to close it. 
enenra commented 1 month ago

Ahhh I solved it.

So.

The first clue is that the templates_toml path is to the Blender install directory, not the directory where addons are normally installed to. templates_toml is an example that is distributed with Blender itself. And for some reason, the VSC plugin is trying to load it as an addon (there's a manifest file in that folder, maybe that's why?) but because there's no init file in that folder it fails.

Deleting that folder in the Blender install dir allows the VSC plugin to start up Blender as normal, and my addon loads fine.