Skip to content

Commit

Permalink
prevent crashes by validating currentScene and currentEpisode
Browse files Browse the repository at this point in the history
  • Loading branch information
cewert committed Jul 18, 2024
1 parent 4385d2d commit 872aeb1
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions source/Main.bs
Original file line number Diff line number Diff line change
Expand Up @@ -215,22 +215,28 @@ sub Main (args as dynamic) as void
else if isNodeEvent(msg, "refreshSeasonDetailsData")
startLoadingSpinner()

currentEpisode = m.global.queueManager.callFunc("getCurrentItem")
currentScene = m.global.sceneManager.callFunc("getActiveScene")

' Find the object in the scene's data and update its json data
for i = 0 to currentScene.objects.Items.count() - 1
if LCase(currentScene.objects.Items[i].id) = LCase(currentEpisode.id)
currentScene.objects.Items[i].json = api.users.GetItem(m.global.session.user.id, currentEpisode.id)
m.global.queueManager.callFunc("setTopStartingPoint", currentScene.objects.Items[i].json.UserData.PlaybackPositionTicks)
exit for
if isValid(currentScene) and isValid(currentScene.objects) and isValid(currentScene.seasonData)
currentEpisode = m.global.queueManager.callFunc("getCurrentItem")

if isValid(currentScene.objects.Items) and isValid(currentEpisode) and isValid(currentEpisode.id)
' Find the object in the scene's data and update its json data
for i = 0 to currentScene.objects.Items.count() - 1
if LCase(currentScene.objects.Items[i].id) = LCase(currentEpisode.id)
currentScene.objects.Items[i].json = api.users.GetItem(m.global.session.user.id, currentEpisode.id)
m.global.queueManager.callFunc("setTopStartingPoint", currentScene.objects.Items[i].json.UserData.PlaybackPositionTicks)
exit for
end if
end for
end if
end for

seasonMetaData = ItemMetaData(currentScene.seasonData.id)
currentScene.seasonData = seasonMetaData.json
currentScene.episodeObjects = currentScene.objects
currentScene.callFunc("updateSeason")
seasonMetaData = ItemMetaData(currentScene.seasonData.id)
currentScene.seasonData = seasonMetaData.json
currentScene.episodeObjects = currentScene.objects
currentScene.callFunc("updateSeason")
end if

stopLoadingSpinner()
else if isNodeEvent(msg, "refreshMovieDetailsData")
startLoadingSpinner()
Expand Down

0 comments on commit 872aeb1

Please sign in to comment.