Error: cannot access member ... of deleted QObject. Need help, please!

MCphylyss_2MCphylyss_2 Posts: 48

Hi,

First of all, I'm not familiar with js and QT neither.

I'm trying to create a simple script that displays a GUI on which I could choose any owned product I want, to batch export them. Nothing difficult, but I have that error message that randomly appears very often : "cannot access member 'title' of deleted Qobject" ("title', or any other attribute I try to get)

I tried to minimize my code to locate the cause, but nothing to do : error is too random so it's really hard to locate.

For example : if I run my script for the first time since I launched Daz, Error probability is 100%! then I re-run the script: success probability is 100% !!! then I take a break, come back 5 minutes later (script's still running, but doing nothing), It doesn't work anymore because most of QObjects have been deleted by their own will!

So my question is : did I miss something? is that a common mistake that requires doing something specific to be fixed?

I can join my script if needed, thanks a lot for any help!

Post edited by MCphylyss_2 on

Comments

  • I just simplified my code, hope this will help you to help me^^

    // Function taken from https://direct.daz3d.com/forums/discussion/185431/get-assets-of-certain-type-from-content-library// Iterates over each asset of each installed product. For each asset, executes record_asset(oAsset);function findAssets()  {	var aAssets; assets = [];	var oProductsTop = App.getAssetMgr().getProducts();	var oIntermediate, oProduct, nProducts;	var nIntermediates = oProductsTop.getNumChildContainers();	startProgress( "", nIntermediates, true, true );	// while debugging, I add "i<3" condition to earn time...	for( var i=0; i<3 && i<nIntermediates; i++)  {		var oIntermediate = oProductsTop.getChildContainer(i);		for( var j=0; j<oIntermediate.getNumChildContainers(); j++)  {			oProduct = oIntermediate.getChildContainer(j);			if(!oProduct.isInstalled){continue;}			aAssets = oProduct.getAssets();				for (var k=0; k<aAssets.length;k++) record_asset(aAssets[k])			App.statusLine("Found: "+oProduct.title, false );}		stepProgress(1);}	finishProgress();}// Store the asset in var "assets", a dict that will look like {"actor/character" : [aiko6_asset, giselle6_asset, ...], ...}	function record_asset(oAsset){	var contentType = oAsset.contentType.toString();	// Applying some filters, otherwise there will be a HUGE amount of datas	if (!contentType.match('/material') && !contentType.match('/light') && !contentType.match('/pose') && !contentType.match('/lost and found')){		if(!(contentType in assets)) assets[contentType]=[];		assets[contentType].push(oAsset);}}// sending all assets name to the listbox.function display_assets()  {	assets_corres = []; wList.clear();	for (var contentType in assets) {		for(var j=0;j<assets[contentType].length;j++){			wList.insertItem(assets[contentType][j].assetName);			assets_corres.push(assets[contentType][j]);	// We have to keep a trace of what we're putting in the list, in order to display the asset when clicking on it.}}}			function display_asset(){	oLogListBox.clear();	for (var i in {'productName':1, 'assetName':1, 'displayName':1, 'contentType':1, 'categories':1, 'originalFilename':1, 'originalPath':1, 'description':1}){		oLogListBox.insertItem(assets_corres[arguments[0]][i].toString());}}var assets; var assets_corres;var wDlg = new DzDialog(); wDlg.caption = "Export to Qpyd"; wDlg.width = 800; wDlg.height = 600;// LEFT COLUMNvar wLyt1 = new DzHBoxLayout(wDlg); wLyt1.autoAdd = true; wLyt1.margin = 8; wLyt1.spacing = 8; wLyt1.columns = 2;var wList = new DzListBox(wDlg);// RIGHT COLUMNvar wLyt2 = new DzVGroupBox(wDlg); wLyt2.autoAdd = true; wLyt2.margin = 8; wLyt2.spacing = 8; wLyt2.rows = 2;var oLogListBox = new DzListBox(wLyt2); oLogListBox.selectionMode = oLogListBox.NoSelection;var button_run = DzPushButton(wLyt2); button_run.text = "Search datas";connect(button_run, "clicked()", function()  {findAssets();display_assets(); })connect(wList, "clicked(int)", display_asset);wDlg.exec();

     

    My problem is :

    - I launch Daz.

    - I execute the script and click on the button. It displays the assets liist on the left listbox. But when I click on an asset, nothing happens. I close the script.

    - I relaunch the script, without any changes : It works (for about 5 minutes. Then Qobjects get deleted...).

     

    I hope that I'm understandable... Could someone explain me what I'm doing wrong? thanks!

  • jag11jag11 Posts: 885

    I checked the code and found some problems, I understand your not familiar with JS or Qt, but the will is more important than knowledge. First, some healthy code recommendations:

    • It is a good idea to move all var declarations to the beginning of the file.
    • Initialize every declared var.
    • Validate every parameter passed to a function.
    • Validate every value you get from the API, for instance: oProduct = oIntermediate.getChildContainer(j), you can't assume oProduct is valid it might be null.

    On line: 

    var contentType = oAsset.contentType.toString();

    You are relying on getting a contentType value, but it is not always the case, a quick test I made returned some empty values, so, you must test against empty strings.

    As it is a lengthy operation(many nested for loops) you must yield control to DS to do house keeping tasks by calling processEvents() function.

    On some lines you are instancing with wDlg as parent, in other lines you are instancing with wLyt2 as parent.

    I applied some validations here and there and the error disappeared.

    HTH

  • Thanks a lot for the answer!

    I will apply your recommendations. I did ckeck values before to use them, but removed that part of the code to simplify it... but you're right, on line "var contentType = ...toString()", I didn't check the value, because I supposed that even if value is undefined, toString method will work...

    I didn't really understand the second part of your message as I'm not native english speaker, but I think that's exactly what I was looking for, so I'll work on it.

    Thanks again!

  • I did what you told me and continued my script, and didn't have any other error of that kind for now two days. I think that was essentially the bad layout instancing that was fatal...

    Once again, thank you !

  • jag11jag11 Posts: 885

    You're welcome, I'm glad I could help.

Sign In or Register to comment.