Python material pipeline EXCEPTION_ACCESS_VIOLATION error

Hi guys
I’m having an issue with the python script that creates and sets up materials for my project. I used it many times more or less 1 month ago, but now it crashes the editor with an EXCEPTION_ACCESS_VIOLATION, i also verified that i didn’t change something unintentionally with vsc timeline.
I have to verify the files of my engine version to be able to reopen a project.
I also tested it on another project in 5.3 and 5.2, for both worked previously, and has the same behaviour.

This is the script. Basically checks for the assets in a folder and create a material instance for the materials, assigning textures and deleting old materials.
Some of it is taken from this forum, credit to OP.

import unreal
import os
def fileSetup():

    Import = False #Import or only assign mats
    
    # Directory path to search for files if importing
    directory_path = ''
    # Game folder to look into -  textures and fbx should be in the same folder
    importPath = '/Game/Aquafluttua/Jail'
    if Import:
        fileList(directory_path, importPath)
    else: 
        buildSelectedAssets(importPath)

def fileList(directory_path, importPath):
    # List of file extensions to include
    file_extensions = ['.fbx', '.tga','.png']

    # Initialize an empty list to store the file paths
    file_paths = []

    # Traverse the directory and find matching files
    for root, dirs, files in os.walk(directory_path):
        for file in files:
            # Check if the file has one of the specified extensions
            if any(file.endswith(ext) for ext in file_extensions):
                # Create the full file path by joining the directory and file name
                full_file_path = os.path.join(root, file)
                # Append the file path to the list
                file_paths.append(full_file_path)

    # Print the list of file paths
    for file_path in file_paths:
        print(f"'{file_path}',")

    importAssets(file_paths,importPath)

#Import Function
def importAssets(fileNames, folderPath):
    #Import Directory
    # create asset tools object
    assetTools = unreal.AssetToolsHelpers.get_asset_tools()
    # create asset import data object        
    assetImportData = unreal.AutomatedAssetImportData()
    # set assetImportData attributes
    
    assetImportData.destination_path = folderPath
    assetImportData.filenames = fileNames
    assetImportData.replace_existing = True
    assetTools.import_assets_automated(assetImportData)
#
    buildSelectedAssets(folderPath)
    #time.sleep(60)
#Material Instance creation, deleting the old one and assign texture
def buildSelectedAssets(folderPath):
    """
    Sets up static mesh, material instances, and textures.  Args passed in by import script.
    """
    # lists to hold new assets
    textures = []
    geo = []
    materialInstances = []
    # create asset tools instance
    assetTools = unreal.AssetToolsHelpers.get_asset_tools()
    EAL = unreal.EditorAssetLibrary()
    # hard coded path to parent material
    materialParent = EAL.load_asset('/Game/Aquafluttua/Master/M_parent')
    # get all assets in folder path
    for assetPath in EAL.list_assets(folderPath):
        # clean up asset path
        assetPath = assetPath.split('.')[0]
        # identify newly import assets
        # load assets, located file import path, and compare to file import paths passed in from import script.
        asset = EAL.load_asset(assetPath)
        try:
            assetImportData = asset.get_editor_property('asset_import_data')
            importfilePath = assetImportData.get_first_filename()
            #if importfilePath in fileNames:
            if isinstance(asset, unreal.StaticMesh):
                geo.append(asset)
            if isinstance(asset, unreal.Texture):
                textures.append(asset)
        except AttributeError: # not all assets have asset import data
            pass
    #print("Textures: ",textures,"geo: ", geo)
    for staticMesh in geo:
        #print("!!StaticMesh", staticMesh)
        # iterate over all static materials associated with mesh
        for staticMaterial in staticMesh.static_materials:
            if staticMaterial.material_interface != None:
                print("MatIn", staticMaterial)
                # get the index of the current static material for later
                index = staticMesh.static_materials.index(staticMaterial)
                # locate and delete the default material created on import
                matPath = staticMaterial.material_interface.get_path_name()
                unreal.EditorAssetLibrary.delete_asset(matPath)
                # create new material instance
                materialInstance = assetTools.create_asset(
                    staticMaterial.material_slot_name,
                    folderPath,
                    unreal.MaterialInstanceConstant,
                    unreal.MaterialInstanceConstantFactoryNew(),
                )
                materialInstances.append(materialInstance)
                # set parent material
                materialInstance.set_editor_property('parent', materialParent)
                # assign new material instance to correct material slot
                staticMesh.set_material(index, materialInstance)
                # get asset name from static mesh to find textures later
                assetName = str(staticMaterial.material_slot_name)
                # iterate over textures
                for texture in textures:
                    # identify textures associated with asset by naming convention
                    if assetName in texture.get_name():
                        # get parameter name from texture name - i.e. T_Airconditioner_BC -> BC
                        parameterName = texture.get_name().split('_')[-1]
                        # set up material instance parameter
                        unreal.MaterialEditingLibrary.set_material_instance_texture_parameter_value(
                            materialInstance,
                            parameterName,
                            texture
                    )
    # save all new assets
    newAssets = [geo,textures,materialInstances]
    for list in newAssets:
        for asset in list:
            unreal.EditorAssetLibrary.save_asset(asset.get_path_name())
    
    
fileSetup()
print ("done")

And this is the exit error.

LoginId:
EpicAccountId:

Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0x00000000000003f8

UnrealEditor_Engine!UMaterialInstance::GetCachedExpressionData() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\Materials\MaterialInstance.cpp:958]
UnrealEditor_Engine!UMaterialInterface::GetAssetRegistryTags() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\Materials\MaterialInterface.cpp:773]
UnrealEditor_CoreUObject!UObject::GetAssetRegistryTags() [D:\build\++UE5\Sync\Engine\Source\Runtime\CoreUObject\Private\UObject\Obj.cpp:2234]
UnrealEditor_CoreUObject!FAssetData::FAssetData() [D:\build\++UE5\Sync\Engine\Source\Runtime\CoreUObject\Private\AssetRegistry\AssetData.cpp:368]
UnrealEditor_AssetRegistry!UAssetRegistryImpl::AssetCreated() [D:\build\++UE5\Sync\Engine\Source\Runtime\AssetRegistry\Private\AssetRegistry.cpp:3633]
UnrealEditor_AssetTools!UAssetToolsImpl::CreateAsset() [D:\build\++UE5\Sync\Engine\Source\Developer\AssetTools\Private\AssetTools.cpp:1675]
UnrealEditor_AssetTools!IAssetTools::execCreateAsset() [D:\build\++UE5\Sync\Engine\Intermediate\Build\Win64\UnrealEditor\Inc\AssetTools\UHT\IAssetTools.gen.cpp:815]
UnrealEditor_CoreUObject!UFunction::Invoke() [D:\build\++UE5\Sync\Engine\Source\Runtime\CoreUObject\Private\UObject\Class.cpp:6665]
UnrealEditor_CoreUObject!UObject::ProcessEvent() [D:\build\++UE5\Sync\Engine\Source\Runtime\CoreUObject\Private\UObject\ScriptCore.cpp:2145]
UnrealEditor_PythonScriptPlugin!PyUtil::InvokeFunctionCall() [D:\build\++UE5\Sync\Engine\Plugins\Experimental\PythonScriptPlugin\Source\PythonScriptPlugin\Private\PyUtil.cpp:533]
UnrealEditor_PythonScriptPlugin!FPyWrapperObject::CallFunction_Impl() [D:\build\++UE5\Sync\Engine\Plugins\Experimental\PythonScriptPlugin\Source\PythonScriptPlugin\Private\PyWrapperObject.cpp:303]
UnrealEditor_PythonScriptPlugin!FPyWrapperObject::CallFunction() [D:\build\++UE5\Sync\Engine\Plugins\Experimental\PythonScriptPlugin\Source\PythonScriptPlugin\Private\PyWrapperObject.cpp:227]
UnrealEditor_PythonScriptPlugin!FPyWrapperObject::CallMethodWithArgs_Impl() [D:\build\++UE5\Sync\Engine\Plugins\Experimental\PythonScriptPlugin\Source\PythonScriptPlugin\Private\PyWrapperObject.cpp:335]
UnrealEditor_PythonScriptPlugin!FPyMethodWithClosureDef::Call() [D:\build\++UE5\Sync\Engine\Plugins\Experimental\PythonScriptPlugin\Source\PythonScriptPlugin\Private\PyMethodWithClosure.cpp:152]
python39
python39
python39
python39
python39
python39
python39
UnrealEditor_PythonScriptPlugin!FPythonScriptPlugin::EvalString() [D:\build\++UE5\Sync\Engine\Plugins\Experimental\PythonScriptPlugin\Source\PythonScriptPlugin\Private\PythonScriptPlugin.cpp:1279]
UnrealEditor_PythonScriptPlugin!FPythonScriptPlugin::RunFile() [D:\build\++UE5\Sync\Engine\Plugins\Experimental\PythonScriptPlugin\Source\PythonScriptPlugin\Private\PythonScriptPlugin.cpp:1403]
UnrealEditor_PythonScriptPlugin!FPythonScriptPlugin::ExecPythonCommandEx() [D:\build\++UE5\Sync\Engine\Plugins\Experimental\PythonScriptPlugin\Source\PythonScriptPlugin\Private\PythonScriptPlugin.cpp:596]
UnrealEditor_PythonScriptPlugin!FPythonScriptPlugin::ExecPythonCommand() [D:\build\++UE5\Sync\Engine\Plugins\Experimental\PythonScriptPlugin\Source\PythonScriptPlugin\Private\PythonScriptPlugin.cpp:500]
UnrealEditor_PythonScriptPlugin!FPythonScriptPlugin::Exec_Runtime() [D:\build\++UE5\Sync\Engine\Plugins\Experimental\PythonScriptPlugin\Source\PythonScriptPlugin\Private\PythonScriptPlugin.cpp:714]
UnrealEditor_Core!FExec::Exec() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Private\Misc\Exec.cpp:25]
UnrealEditor_Core!FSelfRegisteringExec::StaticExec() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Private\Misc\CoreMisc.cpp:80]
UnrealEditor_CoreUObject!StaticExec() [D:\build\++UE5\Sync\Engine\Source\Runtime\CoreUObject\Private\UObject\Obj.cpp:4943]
UnrealEditor_Engine!UEngine::Exec() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\UnrealEngine.cpp:4692]
UnrealEditor_UnrealEd!UUnrealEdEngine::Exec() [D:\build\++UE5\Sync\Engine\Source\Editor\UnrealEd\Private\UnrealEdSrv.cpp:662]
UnrealEditor_PythonScriptPlugin!FPythonCommandMenuImpl::Menu_ExecutePython() [D:\build\++UE5\Sync\Engine\Plugins\Experimental\PythonScriptPlugin\Source\PythonScriptPlugin\Private\PythonScriptPlugin.cpp:463]
UnrealEditor_PythonScriptPlugin!TBaseRawMethodDelegateInstance<0,FPythonCommandMenuImpl,void __cdecl(void),FDefaultDelegateUserPolicy>::ExecuteIfSafe() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Public\Delegates\DelegateInstancesImpl.h:534]
UnrealEditor_Slate!TDelegate<void __cdecl(void),FDefaultDelegateUserPolicy>::ExecuteIfBound<void,0>() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Public\Delegates\DelegateSignatureImpl.inl:570]
UnrealEditor_Slate!SMenuEntryBlock::OnClicked() [D:\build\++UE5\Sync\Engine\Source\Runtime\Slate\Private\Framework\MultiBox\SMenuEntryBlock.cpp:1167]
UnrealEditor_Slate!SMenuEntryBlock::OnMenuItemButtonClicked() [D:\build\++UE5\Sync\Engine\Source\Runtime\Slate\Private\Framework\MultiBox\SMenuEntryBlock.cpp:1118]
UnrealEditor_Slate!TBaseSPMethodDelegateInstance<0,SMenuEntryBlock,1,FReply __cdecl(void),FDefaultDelegateUserPolicy>::Execute() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Public\Delegates\DelegateInstancesImpl.h:281]
UnrealEditor_Slate!TDelegate<FReply __cdecl(void),FDefaultDelegateUserPolicy>::Execute() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Public\Delegates\DelegateSignatureImpl.inl:549]
UnrealEditor_Slate!SButton::ExecuteOnClick() [D:\build\++UE5\Sync\Engine\Source\Runtime\Slate\Private\Widgets\Input\SButton.cpp:465]
UnrealEditor_Slate!SButton::OnMouseButtonUp() [D:\build\++UE5\Sync\Engine\Source\Runtime\Slate\Private\Widgets\Input\SButton.cpp:390]
UnrealEditor_Slate!SMenuEntryButton::OnMouseButtonUp() [D:\build\++UE5\Sync\Engine\Source\Runtime\Slate\Private\Framework\MultiBox\SMenuEntryBlock.cpp:434]
UnrealEditor_Slate!FEventRouter::Route<FReply,FEventRouter::FToLeafmostPolicy,FPointerEvent,`FSlateApplication::RoutePointerUpEvent'::`8'::<lambda_3> >() [D:\build\++UE5\Sync\Engine\Source\Runtime\Slate\Private\Framework\Application\SlateApplication.cpp:442]
UnrealEditor_Slate!FSlateApplication::RoutePointerUpEvent() [D:\build\++UE5\Sync\Engine\Source\Runtime\Slate\Private\Framework\Application\SlateApplication.cpp:5206]
UnrealEditor_Slate!FSlateApplication::ProcessMouseButtonUpEvent() [D:\build\++UE5\Sync\Engine\Source\Runtime\Slate\Private\Framework\Application\SlateApplication.cpp:5775]
UnrealEditor_Slate!FSlateApplication::OnMouseUp() [D:\build\++UE5\Sync\Engine\Source\Runtime\Slate\Private\Framework\Application\SlateApplication.cpp:5740]
UnrealEditor_ApplicationCore!FWindowsApplication::ProcessDeferredMessage() [D:\build\++UE5\Sync\Engine\Source\Runtime\ApplicationCore\Private\Windows\WindowsApplication.cpp:2231]
UnrealEditor_ApplicationCore!FWindowsApplication::DeferMessage() [D:\build\++UE5\Sync\Engine\Source\Runtime\ApplicationCore\Private\Windows\WindowsApplication.cpp:2738]
UnrealEditor_ApplicationCore!FWindowsApplication::ProcessMessage() [D:\build\++UE5\Sync\Engine\Source\Runtime\ApplicationCore\Private\Windows\WindowsApplication.cpp:1099]
UnrealEditor_ApplicationCore!FWindowsApplication::AppWndProc() [D:\build\++UE5\Sync\Engine\Source\Runtime\ApplicationCore\Private\Windows\WindowsApplication.cpp:937]
user32
user32
UnrealEditor_ApplicationCore!FWindowsPlatformApplicationMisc::PumpMessages() [D:\build\++UE5\Sync\Engine\Source\Runtime\ApplicationCore\Private\Windows\WindowsPlatformApplicationMisc.cpp:148]
UnrealEditor!FEngineLoop::Tick() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\LaunchEngineLoop.cpp:5749]
UnrealEditor!GuardedMain() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\Launch.cpp:188]
UnrealEditor!GuardedMainWrapper() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:118]
UnrealEditor!LaunchWindowsStartup() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:258]
UnrealEditor!WinMain() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:298]
UnrealEditor!__scrt_common_main_seh() [D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288]
kernel32
ntdll

Idk if this is something related to some updates of the engine/python api or something else I changed.