Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes screen grab crash #366

Merged
merged 1 commit into from
Apr 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions Console/Common/BaseCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
using LibDmd.Output.PinDmd1;
using LibDmd.Output.PinDmd2;
using LibDmd.Output.PinDmd3;
using LibDmd.Output.ZeDMD;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import resort

using LibDmd.Output.Pixelcade;
using LibDmd.Output.Virtual.AlphaNumeric;
using LibDmd.Output.ZeDMD;
using NLog;
using static System.Windows.Threading.Dispatcher;
using static DmdExt.Common.BaseOptions.DestinationType;
Expand All @@ -38,7 +38,7 @@ public RenderGraphCollection GetRenderGraphs(HashSet<string> reportingTags)
return _graphs;
}

protected List<IDestination> GetRenderers(IConfiguration config, HashSet<string> reportingTags, int[] position = null)
protected List<IDestination> GetRenderers(IConfiguration config, HashSet<string> reportingTags)
{
var renderers = new List<IDestination>();
if (config.PinDmd1.Enabled) {
Expand Down Expand Up @@ -146,7 +146,7 @@ protected List<IDestination> GetRenderers(IConfiguration config, HashSet<string>
}

if (config.VirtualDmd.Enabled) {
renderers.Add(ShowVirtualDmd(config, position));
renderers.Add(ShowVirtualDmd(config));
Logger.Info("Added virtual DMD renderer.");
reportingTags.Add("Out:VirtualDmd");
}
Expand Down Expand Up @@ -180,13 +180,14 @@ protected List<IDestination> GetRenderers(IConfiguration config, HashSet<string>
return renderers;
}

private static IDestination ShowVirtualDmd(IConfiguration config, int[] position)
private static IDestination ShowVirtualDmd(IConfiguration config)
{
var dmd = new VirtualDmd {
Left = config.VirtualDmd.Left,
Top = config.VirtualDmd.Top,
Width = config.VirtualDmd.Width,
Height = config.VirtualDmd.Height
Height = config.VirtualDmd.Height,
IgnoreAspectRatio = config.VirtualDmd.IgnoreAr
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Height was getting ignored, since the AR was locked.

};
dmd.Setup(config as Configuration, config is Configuration iniConfig ? iniConfig.GameName : null);
var thread = new Thread(() => {
Expand All @@ -196,8 +197,6 @@ private static IDestination ShowVirtualDmd(IConfiguration config, int[] position

dmd.Dispatcher.Invoke(() => {
dmd.Dmd.Init();
if(position != null)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The position it was passing here was the screen grab position, not the virtual dmd position. Not sure why, but it didn't seem correct to me.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're absolutely right, grabbing position has no business when creating the virtual DMD.

dmd.Dmd.SetDimensions(position[2]- position[0], position[3]-position[1]);
dmd.Show();
});

Expand Down
2 changes: 1 addition & 1 deletion Console/Mirror/MirrorCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected override void CreateRenderGraphs(RenderGraphCollection graphs, HashSet
{
// create graph with renderers
_graph = new RenderGraph {
Destinations = GetRenderers(_config, reportingTags, _options.Position),
Destinations = GetRenderers(_config, reportingTags),
Resize = _config.Global.Resize,
FlipHorizontally = _config.Global.FlipHorizontally,
FlipVertically = _config.Global.FlipVertically,
Expand Down
2 changes: 1 addition & 1 deletion LibDmd/Output/Virtual/Dmd/VirtualDmdControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ private void ogl_OpenGLDraw(object sender, OpenGLRoutedEventArgs args)
if (createTexture)
gl.TexImage2D(OpenGL.GL_TEXTURE_2D, 0, OpenGL.GL_RGB, _bitmapToRender.Width, _bitmapToRender.Height, 0, OpenGL.GL_BGR, OpenGL.GL_UNSIGNED_BYTE, data.Scan0);
else
glTexSubImage2D(OpenGL.GL_TEXTURE_2D, 0, 0, 0, DmdWidth, DmdHeight, OpenGL.GL_BGR, OpenGL.GL_UNSIGNED_BYTE, data.Scan0);
glTexSubImage2D(OpenGL.GL_TEXTURE_2D, 0, 0, 0, _bitmapToRender.Width, _bitmapToRender.Height, OpenGL.GL_BGR, OpenGL.GL_UNSIGNED_BYTE, data.Scan0);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cause of the crash. The size needs to match the buffer size. Likely just a copy/paste error.

_bitmapToRender.UnlockBits(data);
break;
}
Expand Down