[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#434457: Fixed it.



tags 434457 +patch
thanks

I fixed this bug. The problem was an uncaught exception when reading in
sm files that contained letters. I don't know what the letters are
supposed to mean, but pydance should convert unrecognized input to a
sane default, ignore, or give an error, rather than crashing. The patch
that I attached will cause pydance to convert unkown characters into
"0"'s, which is the behavior described in the pydance docs.

-Brandon
diff -ur pydance-1.0.3/fileparsers.py pydance-1.0.3-5/fileparsers.py
--- pydance-1.0.3/fileparsers.py	2005-04-04 13:49:22.000000000 -0700
+++ pydance-1.0.3-5/fileparsers.py	2008-01-29 14:49:07.000000000 -0800
@@ -603,13 +603,13 @@
         if gametype in games.COUPLE:
           step1 = [note]
           step2 = [note]
-          step1.extend([SMFile.step[int(s)] for s in sd[0:count/2]])
-          step2.extend([SMFile.step[int(s)] for s in sd[count/2:]])
+          step1.extend([SMFile.step[util.my_int(s)] for s in sd[0:count/2]])
+          step2.extend([SMFile.step[util.my_int(s)] for s in sd[count/2:]])
           stepdata[0].append(step1)
           stepdata[1].append(step2)
         else:
           step = [note]
-          step.extend([SMFile.step[int(s)] for s in sd])
+          step.extend([SMFile.step[util.my_int(s)] for s in sd])
           stepdata.append(step)
 
         beat += note / 4.0
diff -ur pydance-1.0.3/util.py pydance-1.0.3-5/util.py
--- pydance-1.0.3/util.py	2004-05-23 09:00:42.000000000 -0700
+++ pydance-1.0.3-5/util.py	2008-01-29 14:45:33.000000000 -0800
@@ -90,3 +90,11 @@
       parts[i] = parts[i][0].capitalize() + oldparts[1:]
 
   return " ".join(parts)
+
+# This function takes a string, and returns an int. Unlike the builtin int()
+# function, this function returns 0 if the string does not represent a number
+def my_int(x):
+  try:
+    return int(x)
+  except:
+    return 0

Reply to: