Script Runtime Error/User Crash

Post Reply
jmtpct
Posts: 19
Joined: 08 Dec 15 0:00

Script Runtime Error/User Crash

Post by jmtpct »

I assembled the attached code to use as a custom line in the Custom View field. 90% of the time it runs fine, but occasionally I get a Script Runtime Error that forces me to restart. Not sure what triggers the error, but it only appears after I have been working in PSU for an extended period. Ordinarily this is a manageable nuisance, but now it seems to have caused my user account to crash. This account was the only one using the code, and the only one that no longer works. When I try to login in with it, I get an error stating IDImager has stopped working and will exit. Other credentials work fine.

I'm not an expert coder by any means, but I am confused by the fact that it works fine most of the time, then doesn't. Any thoughts?

Thanks,
JT

Code: Select all

%code
const
	cName = 'RESTRICTED';
	xPA = 'X-PA';
	xHR = 'X-HR';
	xEHS = 'X-EHS';
	fID	= 'FULL ID';
	
var
  AProp: TCatalogItemProp;
  ACatItem: TCatalogItem;
  AVersionColor: String;
  AVersionShape: String;
  ARatingColor: String;
  ARatingStar: String;
  ARatingOnStar: String;
  ARatingOffStar: String;
  i: Integer;
  
begin
  result := '';
  ARatingColor := '#CCCCCCCC';
  ARatingStar := 'M 3.03,4.19883 L 2.996,4.22354 L 3.00909,4.26369 L 2.97501,4.2389 L 2.94086,4.26369 L 2.95394,4.22354 L 2.92,4.19883 L 2.96193,4.19883 L 2.97501,4.1589 L 2.98801,4.19883 L 3.03,4.19883 Z ';
  ARatingOnStar := '<img size="22" path="' + ARatingStar + '" pathfillcolor="' + ARatingColor + '">';
  ARatingOffStar := '<img size="19" path="' + ARatingStar + '" pathfillstyle="none" pathstrokestyle="solid" pathstrokecolor="' + ARatingColor + '">';

  AVersionShape := 'M 1,1 L 2,2 L 1,2 L 1,1 Z';
  
  AProp := TCatalogItemProp.Create(nil);
    if Catalog.FindPropByName(xPA, AProp, '', False) then begin
  		      AVersionColor := '#3FCCCCCC';
    if Catalog.ImageHasProp(ImageItem, AProp, False) then
	      AVersionColor := '#FFFF4040';
		else 
		if Catalog.FindPropByName(xHR, AProp, '', False) then
  		      AVersionColor := '#3FCCCCCC';
		if Catalog.ImageHasProp(ImageItem, AProp, False) then
	      AVersionColor := '#FFFF4040';
			else 
			if Catalog.FindPropByName(xEHS, AProp, '', False) then
  		      AVersionColor := '#3FCCCCCC';
			if Catalog.ImageHasProp(ImageItem, AProp, False) then
				AVersionColor := '#FFFF4040';
		  
//#### Show Marker
    result := result + '<font size="08" color="'+ AVersionColor +'"><ind y="2">';
    result := result + '<img size="18" path="' + AVersionShape + '" pathfillcolor="' + AVersionColor + '">';
    result := result + '</ind></font>';

//#### Show Flags
if Catalog.FindPropByName(xEHS, AProp, '', False) then
      if Catalog.ImageHasProp(ImageItem, AProp, False) then
      result := result + '<FONT size="08" color="#FFFF4040"><ind y="3">EHS  '
	  else
	  result := result + '<FONT size="08" color="#3FCCCCCC"><ind y="3">EHS  ';
  
 if Catalog.FindPropByName(xHR, AProp, '', False) then
      if Catalog.ImageHasProp(ImageItem, AProp, False) then
      result := result + '<FONT size="08" color="#FFFF4040"><ind y="3">HR  '
	  else
	  result := result + '<FONT size="08" color="#3FCCCCCC"><ind y="3">HR  ';
  
 if Catalog.FindPropByName(xPA, AProp, '', False) then
      if Catalog.ImageHasProp(ImageItem, AProp, False) then
      result := result + '<FONT size="08" color="#FFFF4040"><ind y="3">PA  '
	  else
	  result := result + '<FONT size="08" color="#3FCCCCCC"><ind y="3">PA  ';
  
 if Catalog.FindPropByName(fID, AProp, '', False) then
      if Catalog.ImageHasProp(ImageItem, AProp, False) then
      result := result + '<FONT size="08" color="#3BB9FF"><ind y="3">Full ID  '
	  else
	  result := result + '<FONT size="08" color="#3FCCCCCC"><ind y="3">Full ID  '; 
  
if Catalog.ImageIsVersion(ImageItem) then
    result := result + '<FONT size="08" color="#FF40FF40"><ind y="3">Versions'
	else if Catalog.ImageHasVersions(ImageItem) then
    result := result + '<FONT size="08" color="#FF40FF40"><ind y="3">Versions'
	else
	result := result + '<FONT size="08" color="#3FCCCCCC"><ind y="3">Versions';


  end;
  ACatItem.Free;
end;
%/code
jmtpct
Posts: 19
Joined: 08 Dec 15 0:00

Re: Script Runtime Error/User Crash

Post by jmtpct »

I should also add that I use this code as Line 1 in the custom view, but it is pretty straightforward compared to what I have for Line 2.

Code: Select all

%code

begin
  result := '';
   
result := result + '<font size="08" color="#FF8822"><ind y="3">%dd-%mmm{uppercase=y}-%yyyy  T: %hh:%nn:%ss      '

   //#### Show File Size
    result := result + '<FONT size="08" color="#CFFFFF00"><ind y="3">%ImageFileSizeShort';
    result := result + '</ind></font>';

end;
%/code
weidmic
moderator
Posts: 861
Joined: 04 Dec 06 21:21

Re: Script Runtime Error/User Crash

Post by weidmic »

JT,
I think this is a bug somehow...
Unfortunately I have this same issue and it is (to my knowledge) not directly related to the script itself.
It works most of the time and all of a sudden it does'nt anymore. Restart required ;(

I figured, after some heavy load (like importing images or adding lots of labels or metadata) its more likely to get the runtime error.

Michael
PSUServer 2024.x, PostgreSQL 12.x
My homepage http://www.michaelweidner.com
Hert
Posts: 7870
Joined: 13 Sep 03 6:24

Re: Script Runtime Error/User Crash

Post by Hert »

Your script needs the following change: you create a TCatalogItemProp object (AProp) but you don't free it. This means that there's a memory leak. And you script has an unused variable called ACatItem. That's not too serious but what is is that you free ACatItem at the end of the script while it isn't created anywhere earlier in the code.

Replace ACatItem.Free with AProp.Free and you should be good to go
This is a user-to-user forum. If you have suggestions, requests or need support then please send a message
jmtpct
Posts: 19
Joined: 08 Dec 15 0:00

Re: Script Runtime Error/User Crash

Post by jmtpct »

Thanks Hert. I guess that's what I get for making Frankenstein code. I'll make that change and post back if the error pops up again.
Post Reply