Skip to content

Commit

Permalink
Merge pull request #387 from seansd/fix-longdesc-crash-2
Browse files Browse the repository at this point in the history
Fix long desc / episode name crash
  • Loading branch information
Narflex committed Oct 10, 2018
2 parents 213e01c + 986c0d8 commit 285ed82
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 67 deletions.
74 changes: 9 additions & 65 deletions java/sage/Show.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,43 +163,11 @@ public String getTitle()

public String getEpisodeName()
{
if (episodeNameBytes != null)
{
// Doing it this way should be thread safe, we may create the String twice but we'd always
// do it from a valid byte array
byte[] testBytes = episodeNameBytes;
if (testBytes != null)
{
try {
episodeNameStr = new String(testBytes, Sage.I18N_CHARSET);
episodeNameBytes = null;
}
catch (UnsupportedEncodingException uee) {
if (Sage.DBG) System.out.println("Unicode ERROR creating String of:" + uee);
}
}
}
return episodeNameStr;
return episodeNameStr;
}

public String getDesc()
{
if (descBytes != null)
{
// Doing it this way should be thread safe, we may create the String twice but we'd always
// do it from a valid byte array
byte[] testBytes = descBytes;
if (testBytes != null)
{
try {
descStr = new String(testBytes, Sage.I18N_CHARSET);
descBytes = null;
}
catch (UnsupportedEncodingException uee) {
if (Sage.DBG) System.out.println("Unicode ERROR creating String of:" + uee);
}
}
}
return descStr;
}

Expand Down Expand Up @@ -355,10 +323,8 @@ void update(DBObject x)
lastWatched = fromMe.lastWatched;
dontLike = fromMe.dontLike;
title = fromMe.title;
episodeNameBytes = fromMe.episodeNameBytes;
episodeNameStr = fromMe.episodeNameStr;
externalID = fromMe.externalID;
descBytes = fromMe.descBytes;
descStr = fromMe.descStr;
categories = fromMe.categories;
people = fromMe.people;
Expand Down Expand Up @@ -461,20 +427,10 @@ public boolean isIdentical(Show other)
title = wiz.getTitleForID(readID(in, idMap));

// We lazily create these String to speed up loading time and reduce memory overhead
int size = in.readShort();
if (size == 0)
episodeNameStr = "";
else {
episodeNameBytes = new byte[size];
in.readFully(episodeNameBytes);
}
size = in.readShort();
if (size == 0)
descStr = "";
else {
descBytes = new byte[size];
in.readFully(descBytes);
}
int size = 0;

episodeNameStr = in.readUTF();
descStr = in.readUTF();

Stringer category = wiz.getCategoryForID(readID(in, idMap));
Stringer subCategory = wiz.getSubCategoryForID(readID(in, idMap));
Expand Down Expand Up @@ -649,20 +605,10 @@ void write(DataOutput out, int flags) throws IOException
boolean useLookupIdx = (flags & Wizard.WRITE_OPT_USE_ARRAY_INDICES) != 0;
out.writeLong(duration);
out.writeInt((title == null) ? 0 : (useLookupIdx ? title.lookupIdx : title.id));
byte[] barr = episodeNameBytes;
if (barr != null) {
out.writeShort(barr.length);
out.write(barr);
}
else
out.writeUTF(episodeNameStr);
barr = descBytes;
if (barr != null) {
out.writeShort(barr.length);
out.write(barr);
}
else
out.writeUTF(descStr);

out.writeUTF(episodeNameStr);
out.writeUTF(descStr);

out.writeInt((categories.length == 0) ? 0 : (useLookupIdx ? categories[0].lookupIdx : categories[0].id));
out.writeInt((categories.length < 2) ? 0 : (useLookupIdx ? categories[1].lookupIdx : categories[1].id));

Expand Down Expand Up @@ -1536,9 +1482,7 @@ public static String getImageIdUrl(int packedImageId, int rootId, int altFilmId,
long duration;
Stringer title;
volatile String episodeNameStr;
byte[] episodeNameBytes;
volatile String descStr;
byte[] descBytes;
Stringer[] categories;
Person[] people;
byte[] roles;
Expand Down
2 changes: 0 additions & 2 deletions java/sage/Wizard.java
Original file line number Diff line number Diff line change
Expand Up @@ -4541,9 +4541,7 @@ private Show addShow(String title, String episodeName, String desc, long duratio
s.duration = duration;
s.title = getTitleForName(title, mediaMask);
s.episodeNameStr = (episodeName == null) ? "" : new String(episodeName);
s.episodeNameBytes = null;
s.descStr = (desc == null) ? "" : new String(desc);
s.descBytes = null;
if (!fromAPlugin && extID.startsWith("MV") && (categories == null || categories.length == 0 || !Sage.rez("Movie").equals(categories[0])))
{
if (categories == null)
Expand Down

0 comments on commit 285ed82

Please sign in to comment.