cfilipov / MuscleBook

[ABANDONED] Muscle Book is an iOS workout tracker for strength training and body building.
GNU General Public License v3.0
42 stars 18 forks source link

[Bug] App crashes when trying to add new set #44

Closed JonathanGuberman closed 8 years ago

JonathanGuberman commented 8 years ago

This morning when I went to use the app I pressed the "+" button in the upper-right corner of the main screen to add a set, and the app crashed. I tried this multiple times with no luck.

When I got back to my computer I plugged it in to get the console output from Xcode and got the following (only the last few lines are shown):

Database: /var/mobile/Containers/Data/Application/AF9389E2-DDC8-414E-99C9-1E2368104104/Documents/musclebook.db
SELECT count(*) FROM "sqlite_master" WHERE (("type" = 'table') AND ("name" = 'schema_migrations'))
SELECT count(*) FROM "sqlite_master" WHERE (("type" = 'table') AND ("name" = 'schema_migrations'))
SELECT count(*) FROM "sqlite_master" WHERE (("type" = 'table') AND ("name" = 'schema_migrations'))
SELECT "version" FROM "schema_migrations" ORDER BY "version"
SELECT "start_time", max("activation") FROM "workout" GROUP BY date("start_time", 'localtime') ORDER BY date("start_time", 'localtime')
SELECT "start_time", count("workout_id") FROM "workout" GROUP BY date("start_time", 'localtime')
SELECT "muscle_id", "muscle_movement_class_id", "workset"."exercise_id", "workset"."exercise_name", max("activation_id"), sum("volume"), max("weight") FROM "workset" INNER JOIN "muscle_movement" ON ("workset"."exercise_id" = "muscle_movement"."exercise_id") WHERE ((((date("start_time", 'localtime') = date('2016-07-04T14:13:07.125Z', 'localtime')) AND ("workset"."exercise_id" IS NOT NULL)) AND ("muscle_movement_class_id" = 1)) AND ("muscle_id" IS NOT NULL)) GROUP BY "muscle_id"
SELECT max("start_time") FROM "workout"
SELECT min("start_time") FROM "workout"
SELECT count("workout_id") FROM "workout" WHERE (date("start_time", 'localtime') = date('2016-07-04T14:13:07.705Z', 'localtime'))
SELECT "exercise_id", "exercise_name" FROM "workset" WHERE (date("start_time", 'localtime') = date('2016-07-04T14:13:07.125Z', 'localtime')) GROUP BY "exercise_id"
SELECT "start_time", count("workout_id") FROM "workout" GROUP BY date("start_time", 'localtime')
SELECT "muscle_id", "muscle_movement_class_id", "workset"."exercise_id", "workset"."exercise_name", max("activation_id"), sum("volume"), max("weight") FROM "workset" INNER JOIN "muscle_movement" ON ("workset"."exercise_id" = "muscle_movement"."exercise_id") WHERE ((((date("start_time", 'localtime') = date('2016-07-04T14:13:07.125Z', 'localtime')) AND ("workset"."exercise_id" IS NOT NULL)) AND ("muscle_movement_class_id" = 1)) AND ("muscle_id" IS NOT NULL)) GROUP BY "muscle_id"
SELECT "start_time", count("workout_id") FROM "workout" GROUP BY date("start_time", 'localtime')
SELECT "muscle_id", "muscle_movement_class_id", "workset"."exercise_id", "workset"."exercise_name", max("activation_id"), sum("volume"), max("weight") FROM "workset" INNER JOIN "muscle_movement" ON ("workset"."exercise_id" = "muscle_movement"."exercise_id") WHERE ((((date("start_time", 'localtime') = date('2016-07-04T04:00:00Z', 'localtime')) AND ("workset"."exercise_id" IS NOT NULL)) AND ("muscle_movement_class_id" = 1)) AND ("muscle_id" IS NOT NULL)) GROUP BY "muscle_id"
SELECT max("start_time") FROM "workout"
SELECT min("start_time") FROM "workout"
SELECT count("workout_id") FROM "workout" WHERE (date("start_time", 'localtime') = date('2016-07-04T14:13:07.787Z', 'localtime'))
SELECT "exercise_id", "exercise_name" FROM "workset" WHERE (date("start_time", 'localtime') = date('2016-07-04T04:00:00Z', 'localtime')) GROUP BY "exercise_id"
SELECT max("start_time") FROM "workout"
SELECT min("start_time") FROM "workout"
SELECT count("workout_id") FROM "workout" WHERE (date("start_time", 'localtime') = date('2016-07-04T14:13:07.823Z', 'localtime'))
SELECT "exercise_id", "exercise_name" FROM "workset" WHERE (date("start_time", 'localtime') = date('2016-07-04T04:00:00Z', 'localtime')) GROUP BY "exercise_id"
SELECT "start_time", count("workout_id") FROM "workout" GROUP BY date("start_time", 'localtime')
SELECT "muscle_id", "muscle_movement_class_id", "workset"."exercise_id", "workset"."exercise_name", max("activation_id"), sum("volume"), max("weight") FROM "workset" INNER JOIN "muscle_movement" ON ("workset"."exercise_id" = "muscle_movement"."exercise_id") WHERE ((((date("start_time", 'localtime') = date('2016-07-04T04:00:00Z', 'localtime')) AND ("workset"."exercise_id" IS NOT NULL)) AND ("muscle_movement_class_id" = 1)) AND ("muscle_id" IS NOT NULL)) GROUP BY "muscle_id"
SELECT max("start_time") FROM "workout"
SELECT min("start_time") FROM "workout"
SELECT count("workout_id") FROM "workout" WHERE (date("start_time", 'localtime') = date('2016-07-04T14:13:07.873Z', 'localtime'))
SELECT "exercise_id", "exercise_name" FROM "workset" WHERE (date("start_time", 'localtime') = date('2016-07-04T04:00:00Z', 'localtime')) GROUP BY "exercise_id"
SELECT * FROM "workset" ORDER BY "start_time" DESC LIMIT 1
SELECT * FROM "workset" WHERE (((date("start_time", 'localtime') < date('2016-07-04T14:13:11.604Z', 'localtime')) AND ("exercise_id" = 426)) AND ("exercise_id" IS NOT NULL)) ORDER BY "weight" DESC LIMIT 1
SELECT * FROM "workset" WHERE ((((date("start_time", 'localtime') < date('2016-07-04T14:13:11.604Z', 'localtime')) AND ("exercise_id" = 426)) AND ("exercise_id" IS NOT NULL)) AND ("reps" = 1)) ORDER BY "weight" DESC LIMIT 1
SELECT * FROM "workset" WHERE (((date("start_time", 'localtime') < date('2016-07-04T14:13:11.604Z', 'localtime')) AND ("exercise_id" = 426)) AND ("exercise_id" IS NOT NULL)) ORDER BY "e1rm" DESC LIMIT 1
SELECT * FROM "workset" WHERE (((date("start_time", 'localtime') < date('2016-07-04T14:13:11.604Z', 'localtime')) AND ("exercise_id" = 426)) AND ("exercise_id" IS NOT NULL)) ORDER BY "volume" DESC LIMIT 1
SELECT * FROM "exercise" WHERE ("exercise_id" = 426) LIMIT 1
SELECT * FROM "workset" WHERE (((date("start_time", 'localtime') < date('2016-07-04T14:13:11.604Z', 'localtime')) AND ("exercise_id" = 426)) AND ("exercise_id" IS NOT NULL)) ORDER BY "weight" DESC LIMIT 1
SELECT * FROM "workset" WHERE ((((date("start_time", 'localtime') < date('2016-07-04T14:13:11.604Z', 'localtime')) AND ("exercise_id" = 426)) AND ("exercise_id" IS NOT NULL)) AND ("reps" = 1)) ORDER BY "weight" DESC LIMIT 1
SELECT * FROM "workset" WHERE (((date("start_time", 'localtime') < date('2016-07-04T14:13:11.604Z', 'localtime')) AND ("exercise_id" = 426)) AND ("exercise_id" IS NOT NULL)) ORDER BY "e1rm" DESC LIMIT 1
SELECT * FROM "workset" WHERE (((date("start_time", 'localtime') < date('2016-07-04T14:13:11.604Z', 'localtime')) AND ("exercise_id" = 426)) AND ("exercise_id" IS NOT NULL)) ORDER BY "volume" DESC LIMIT 1
SELECT * FROM "exercise" WHERE ("exercise_id" = 426) LIMIT 1
Date: Optional(2016-07-04 14:13:11 +0000)
Time: Optional(2016-07-04 14:13:11 +0000)
SELECT * FROM "workset" WHERE (((date("start_time", 'localtime') < date('2016-07-04T14:13:11.604Z', 'localtime')) AND ("exercise_id" = 426)) AND ("exercise_id" IS NOT NULL)) ORDER BY "weight" DESC LIMIT 1
fatal error: unexpectedly found nil while unwrapping an Optional value
(lldb) 

Deleting the app, reinstalling, and uploading my backed-up DB caused the exact same behaviour. Deleting, reinstalling with a fresh DB fixed that issue, although it crashed on startup during the initial run and as a result the exercise DB wasn't fully populated (I'll post a separate issue for that).

JonathanGuberman commented 8 years ago

Another data point: I tried uploading an older backup of the DB, and that worked fine. The difference between the new backup and the old backup was just one day's worth of workouts, and the extra day was the one where I encountered issue #43. Not sure if they're related or not, though.

cfilipov commented 8 years ago

This happened because your last set was a pull up. When you hit "+" MB will query a bunch of stats about your last set to display on screen. In this case it tried to force-unwrap a nil weight value that didn't exist for a bodyweight exercise (there is a separate bodyweight field).

The query has been updated to check for nil in that column so this should now be handled safely.

Fixed in v0.1.1