Renamefunction causes "dopus_function" thread to crash

Running an updated version of my Singlerun renamescript causes the "dopus_function" thread to crash. This problem already occured in the orignial script for a longer time so i thought to make its code a little bit cleaner but it didnt help. This script renames images and videos from my camera memory card in a single run. I just tried in the most recent dopus version 12.29.2.

After agreeing to terminate the thread, the progresswindow of the rename function opens up but does nothing (not updating) nor is it closable. I have to exit Dopus completely.
image
I think this should be the corresponding minidump
dopus.20221103.092552.zip (34.8 KB)

When denying the thread termination this window opens up
image
and sometimes after the auto dopus restart it crashes again after opening producing these dumps
dopus.20210225.114813.zip (65.2 KB) and this window.
image
I didnt find any difference of the used file- or storagesystem (sd/cfexpresscard/ramdisk/ssd). I selected jpegs and corresponding raw (nef) files. I was able to make one rename run without crash when logging was disabled but a second run crashed again. I already encountered the behaviour that it sometimes worked and sometimes crashed.

The configuration is


and the code

// v1.0(2021-07-07)

var DefaultDateRegex = /([12]\d{3})-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01]) (?:[01]\d|2[0123])-(?:[012345]\d)-(?:[012345]\d)/;
var DefaultDateFormat = "D#yyyy-MM-dd T#HH-mm-ss";
var Logging = true;

//https://www.gpsoft.com.au/help/opus12/index.html#!Documents/Scripting/OnGetNewName.htm
//https://www.gpsoft.com.au/help/opus12/index.html#!Documents/Scripting/GetNewNameData.htm	
function OnGetNewName(getNewNameData)
{
	try
	{
		Logging = getNewNameData.custom.activatelog;
		var item = getNewNameData.item;		
		if(item.is_dir)
		{
			Log(item + " is directory");
			return true; //dont rename
		}

		if(getNewNameData.custom.userenamepreventionregex && getNewNameData.custom.renamepreventionregex.length > 0) //do check before renaming
		{
			var regex = new RegExp(getNewNameData.custom.renamepreventionregex);
			if(regex.test(item.name)) // if matches my desired name pattern already dont rename
			{
				Log(item + " already matches the desired name pattern, skipping ...");
				return true;//dont rename
			}
		}
		
		var result = DateTakenFromFile(item, getNewNameData.custom.usecreationdateasfallback);
		if(result == null)
		{
			return true; //dont rename
		}

		var format = getNewNameData.custom.format.length > 0 ? getNewNameData.custom.format : DefaultDateFormat;
		var newFileName = result.date.Format(format) + item.ext;
		Log(item + ": Renaming (" + result.metatype + ")\t=> '" + newFileName + "'");
		
		return newFileName; //rename
	}
	catch(e)
	{
		Log(item + " ERROR: " + e, true);
		return true; //dont rename
	}
}

//Extract desired date from metadata based on type
function DateTakenFromFile(file, useFallback)
{
	var currentMeta = file.metadata;
	if(currentMeta == null)	
	{
		if(useFallback)
			return { date : file.create, metatype: "file creation meta" };
		else
		{
			Log(item + ": Cannot find metadata. Skipping...", true);
			return null
		}
	}
	switch(currentMeta)
	{
		case "image":
			return { date : currentMeta.image.datetaken, metatype: "image meta" };
		case "video":
			return { date : currentMeta.video.releasedate, metatype: "video meta" };
		default:
			return { date : file.create, metatype: "file creation meta" };//FallbackDate(file); //two references because meta cann be null or something else than image or video
	}
}

//https://www.gpsoft.com.au/help/opus12/index.html#!Documents/Scripting/GetCustomFieldData.htm
function OnGetCustomFields(getCustomFieldData)
{
	getCustomFieldData.fields.format="D#yyyy-MM-dd T#HH-mm-ss";
 	getCustomFieldData.field_labels('format')='Custom Datetime format';
 	getCustomFieldData.field_tips('format')='Specify the format how the extracted date should be used for the new name of the file.';

	getCustomFieldData.fields.userenamepreventionregex=false;
 	getCustomFieldData.field_labels('userenamepreventionregex')='Use regex check'; //jshint ignore:line
 	getCustomFieldData.field_tips('userenamepreventionregex')='If regex is defined than filename is checked against regex and if matches than no rename will happen'; //jshint ignore:line

	getCustomFieldData.fields.renamepreventionregex="([12]\\d{3})-(0[1-9]|1[0-2])-(0[1-9]|[12]\\d|3[01]) (?:[01]\\d|2[0123])-(?:[012345]\\d)-(?:[012345]\\d)";
 	getCustomFieldData.field_labels('renamepreventionregex')='Regex'; //jshint ignore:line
 	getCustomFieldData.field_tips('renamepreventionregex')='Regex for filename checking before renaming'; //jshint ignore:line

 	getCustomFieldData.fields.usecreationdateasfallback=true;
 	getCustomFieldData.field_labels('usecreationdateasfallback')='Use creationdate as fallback'; //jshint ignore:line
 	getCustomFieldData.field_tips('usecreationdateasfallback')='Use creationdate as fallback date if neither image nor video meta was found'; //jshint ignore:line

	getCustomFieldData.fields.activatelog=true;
 	getCustomFieldData.field_labels('activatelog')='Logging'; //jshint ignore:line
 	getCustomFieldData.field_tips('activatelog')='Log rename script outputs'; //jshint ignore:line
}

function Log(msg, e)
{
	if(Logging)
		DOpus.output(String(msg), e || false);
}

Can you narrow down which part of the script is causing the crash?

I addded logging in nearly every line where it made sense, and it seems that when it comes to a crash, the script already fails after the execution of the OnGetCustomFields method. The crash seems to be correlated to the count of the selected files when running the rename script. A few (up to 40) were no problem and the script renamed the files but 60 were already too much and dopus crashed.

Are there any more DMP files from recent crashes? There's only one in the 2022 archive. It gives part of the picture but if there are more DMPs then they might reveal more.

The 2021 DMPs are a year and a half old and look unrelated to any of this.

I would also try simplifying the script to see which part is the actual trigger and which parts are not important. The one DMP we have suggests it may be something corrupting memory, which could be caused by various things, including video codecs that aren't part of Opus (since it looks like you're querying video metadata in the script). Ruling that kind of thing out (or confirming it as the cause) would be good.

Ah im sorry. Might have copied those from another bug report which were saved in another folder with the same name, tried to split those from after the crash from those from restarting after the crash. Should i upload all DMPs of today? I produced a lot while trying to get more insights into this crash :sweat_smile:

They should compress to a small size. Please email the ones you have to the crashdumps address (found here).

Just sent them to this address.

Thanks for sending those. They're all consistent with the initial DMP, which is both good and bad. Good in that all the crashes are consistent, but bad in that I can't explain how they can happen from looking at the code on its own.


I've not been able to reproduce the crash with the same rename script either. If I can reproduce it then I should be able to work out what's going wrong. I suspect it may depend on the files being examined.


I did notice a couple of things in the script code, although they are both long shots:

  •   var DefaultDateRegex = /([12]\d{3})-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01]) (?:[01]\d|2[0123])-(?:[ 012345]\d)-(?:[012345]\d)/;
    

    The \ characters aren't doubled/escaped on that line, so the regex it defines may have some unexpected characters. I'm not sure if that could cause what you're seeing, though, and the DefaultDateRegex variable isn't actually used after that line.

    The crash is happening when the script is just being started, which is when those global variables would be set up, and not much else should be happening at that point. If it's triggering a bug in the Windows JScript engine's regex code, it could explain things, potentially. Unlikely but not impossible.

    The regex that is there is repeated in the code lower down, and the second copy of it does have correctly escaped \ characters. Worth a quick try removing the one at the top in case it helps.

  • There's also a return null inside DateTakenFromFile which is missing the ; at the end of the line. I've had JScript do unexpected things with missing ; (they're meant to be optional but aren't entirely), although it shouldn't cause a crash.


With any test, it's best to use a new process and avoid testing again in one where a crashed thread has been terminated, as the problem could still exist once it first appears within the process.


If you still see the problem after changing those two lines in the script, I think the best thing to do would be to simplify the script as much as possible while still being able to reproduce the issue, and then focus on which files trigger it.

That will narrow down the amount of things to consider, and may also mean we can reproduce the problem with a copy of the same files.

For example, does the problem still happen if all the script's custom fields are removed and replaced with constants? Does it still happen with just one criteria or metadata field being considered instead of multiple? What about if there are none?

Since I can't reproduce the crash yet, these are unfortunately not things I can try myself.

1 Like

I will have a look on these points at the weekend and let you know about more possible details. Thanks for the points mentioned.

1 Like

Ok, just was too curious to find out to go to bed early :sweat_smile: I was able to reduce the code to the following. It seems to me that OnGetCustomFields() gets called three times in a run where not too many files are selected / a successfull run which then produces a log output like

getcustomfields + 02:11:45.348
05.11.2022 02:11 getcustomfields + 02:11:45.348
05.11.2022 02:11 getcustomfields + 02:11:45.845
05.11.2022 02:11 Item is file
05.11.2022 02:11 .... (Here all files are iterated and renamed, i saw no more calls to OnGetCustomFields)

but if too many files are seleted, this method gets called very often (i counted 329 times, even though nothing else than logging happens inside this method) producing a log like

05.11.2022 02:10 getcustomfields + 02:10:38.336
05.11.2022 02:10 getcustomfields + 02:10:38.353
05.11.2022 02:10 getcustomfields + 02:10:38.362
05.11.2022 02:10 getcustomfields + 02:10:38.379
05.11.2022 02:10 getcustomfields + 02:10:38.387
05.11.2022 02:10 getcustomfields + 02:10:38.393
.....
05.11.2022 02:10 getcustomfields + 02:10:42.295
05.11.2022 02:10 getcustomfields + 02:10:42.308
05.11.2022 02:10 getcustomfields + 02:10:42.316
05.11.2022 02:10 getcustomfields + 02:10:42.331
"CRASH"
There is no log output that OnGetNewName() gets actually called in between before or after.

Here is the most recent dump from a freshly restarted dopus (dopus + rt were killed before). Let me know if i can provide more information or images to test it yourself.
dopus.20221105.022211.zip (33.3 KB)

function OnGetNewName(getNewNameData)
{
	try
	{
		var item = getNewNameData.item;
		if(item.is_dir)
		{
			Log(item + " is directory");
			return true; //dont rename
		}
		Log("Item is file");

		var result = null;
		var currentMeta = item.metadata;
			if(currentMeta == null)	
			{
				result = item.create;
			}
				Log("switch");
			switch(currentMeta)
			{
				case "image":
					result = currentMeta.image.datetaken;
					break;
				case "video":
					result = currentMeta.video.releasedate;
					break;
				default:
					result = item.create;
					break;
			}
		
		if(result == null)
		{
			Log("result is null");
			return true; //dont rename
		}
		Log("result is not null");

		//var format = getNewNameData.custom.format.length > 0 ? getNewNameData.custom.format : DefaultDateFormat;
		var format = "D#yyyy-MM-dd T#HH-mm-ss";
		Log("got format");
		var newFileName = result.Format(format) + item.ext;
		Log("new filename");
		Log(item + ": Renaming \t=> '" + newFileName + "'");
		
		return newFileName; //rename
	}
	catch(e)
	{
		Log(item + " ERROR: " + e, true);
		return true; //dont rename
	}
}


function OnGetCustomFields(getCustomFieldData)
{
var date = DOpus.Create.Date.Format("T#MHH:mm:ss")
	Log("getcustomfields + " +date);
}

function Log(msg, e)
{
var l = true;
	if(l)
		DOpus.output(String(msg), e || false, true);
}

I'm not sure but that may not be unusual.

If you remove the OnGetCustomFields method (and hardcode the values it provides), does the problem still happen?

I removed the function but the crash still happens. Yet i have to mention that it seemed to me that it was a little less likely to crash. I was able to get a few times that at least the preview worked fine. But it got more and more confusing when it crashed in the folder i temporarily created for testing but not with copies of those files placed in a subfolder of this temp folder. The images are jpegs (just for testing, normally also the raws) from a Nikon z6ii which i can provide to you for further testing.

I've just tested this on my windows 11 laptop and it didnt run into any problems/crashes when renaming ~450 files. I do not have installed any additional anti virus software on both pcs (except the builtin windows defender) so i wonder what makes the difference. Could it be a difference between win 10/11?