Skip to content

Commit

Permalink
Fix a crash when encountering 0 byte .vqa placeholders.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mailaender authored and abcdefg30 committed Jul 12, 2022
1 parent 0a36d6f commit cff9ac5
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 10 deletions.
5 changes: 4 additions & 1 deletion OpenRA.Mods.Cnc/VideoLoaders/VqaLoader.cs
Expand Up @@ -21,14 +21,17 @@ public bool TryParseVideo(Stream s, bool useFramePadding, out IVideo video)
{
video = null;

if (s.Length == 0)
return false;

if (!IsWestwoodVqa(s))
return false;

video = new VqaVideo(s, useFramePadding);
return true;
}

bool IsWestwoodVqa(Stream s)
static bool IsWestwoodVqa(Stream s)
{
var start = s.Position;

Expand Down
5 changes: 4 additions & 1 deletion OpenRA.Mods.Cnc/VideoLoaders/WsaLoader.cs
Expand Up @@ -22,14 +22,17 @@ public bool TryParseVideo(Stream s, bool useFramePadding, out IVideo video)
{
video = null;

if (s.Length == 0)
return false;

if (!IsWsa(s))
return false;

video = new WsaVideo(s, useFramePadding);
return true;
}

bool IsWsa(Stream s)
static bool IsWsa(Stream s)
{
var start = s.Position;

Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/Scripting/Global/MediaGlobal.cs
Expand Up @@ -170,7 +170,7 @@ public bool PlayMovieInRadar(string movie, LuaFunction playComplete = null)
}
catch (FileNotFoundException e)
{
Log.Write("lua", "Couldn't play movie {0}! File doesn't exist.", e.FileName);
Log.Write("lua", $"Couldn't play movie {e.FileName}! File doesn't exist.");
onCompleteRadar();
return false;
}
Expand Down
25 changes: 19 additions & 6 deletions OpenRA.Mods.Common/Widgets/Logic/MissionBrowserLogic.cs
Expand Up @@ -343,15 +343,28 @@ void PlayVideo(VideoPlayerWidget player, string video, PlayingVideo pv, Action o
playingVideo = pv;
player.Load(video);

// video playback runs asynchronously
player.PlayThen(() =>
if (player.Video == null)
{
StopVideo(player);
onComplete?.Invoke();
});

// Mute other distracting sounds
MuteSounds();
ConfirmationDialogs.ButtonPrompt(
title: "Unable to play video",
text: "Something went wrong during video playback.",
cancelText: "Back",
onCancel: () => { });
}
else
{
// video playback runs asynchronously
player.PlayThen(() =>
{
StopVideo(player);
onComplete?.Invoke();
});

// Mute other distracting sounds
MuteSounds();
}
}
}

Expand Down
6 changes: 5 additions & 1 deletion OpenRA.Mods.Common/Widgets/VideoPlayerWidget.cs
Expand Up @@ -46,7 +46,8 @@ public void Load(string filename)
if (filename == cachedVideoFileName)
return;

var video = VideoLoader.GetVideo(Game.ModData.DefaultFileSystem.Open(filename), true, Game.ModData.VideoLoaders);
var stream = Game.ModData.DefaultFileSystem.Open(filename);
var video = VideoLoader.GetVideo(stream, true, Game.ModData.VideoLoaders);
Open(video);

cachedVideoFileName = filename;
Expand All @@ -56,6 +57,9 @@ public void Open(IVideo video)
{
this.video = video;

if (video == null)
return;

stopped = true;
paused = true;
Game.Sound.StopVideo();
Expand Down

0 comments on commit cff9ac5

Please sign in to comment.