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

crashes on Linux #57

Closed
martynas-m opened this issue Oct 14, 2020 · 20 comments · Fixed by #60
Closed

crashes on Linux #57

martynas-m opened this issue Oct 14, 2020 · 20 comments · Fixed by #60
Assignees

Comments

@martynas-m
Copy link

while trying to generate qr code following crash occurs:

System.Runtime.InteropServices.ExternalException (0x80004005): A generic error occurred in GDI+.
   at System.Drawing.SafeNativeMethods.Gdip.CheckStatus(Int32 status)
   at System.Drawing.Graphics.FillRectangle(Brush brush, Int32 x, Int32 y, Int32 width, Int32 height)
   at System.Drawing.Graphics.FillRectangle(Brush brush, Rectangle rect)
   at QRCoder.QRCode.GetGraphic(Int32 pixelsPerModule, Color darkColor, Color lightColor, Boolean drawQuietZones)
   at QRCoder.QRCode.GetGraphic(Int32 pixelsPerModule)

not very helpful exception, maybe you need some more details?

@ahwm
Copy link
Collaborator

ahwm commented Oct 14, 2020

More details would certainly be helpful. The problem does seem to be with the QRCoder library instead, though. But maybe it's just a matter of targeting? Which version of .NET are you targeting?

@ahwm
Copy link
Collaborator

ahwm commented Oct 14, 2020

Might be related to codebude/QRCoder#227

@martynas-m
Copy link
Author

I'm targeting .net core 3.1, and stack trace shows that error is at QRCoder namespace (as you noted in your previous post)
Probably you've missed, but all action is on Linux (bug title)

@flytzen
Copy link
Collaborator

flytzen commented Oct 14, 2020

I did a quick test on Ubuntu 18.04 and when libgdiplus is missing I get a type initialisation error. Your stack trace looks like you are getting further.
I suspect you are probably missing one of the other references mentioned by @ahwm. However, when I install only libgdiplus it works, so I am stuck.
What version of linux are you on? If you are on docker, can you give us a repro?

@ahwm
Copy link
Collaborator

ahwm commented Oct 14, 2020

@flytzen I have the 2.1 release drafted. Are we good to publish that and push to nuget?

@flytzen
Copy link
Collaborator

flytzen commented Oct 14, 2020

@ahwm yes, I believe so. I think we need @BrandonPotter to approve it?

@ahwm
Copy link
Collaborator

ahwm commented Oct 14, 2020

Yeah, that happen in Azure. I'll go ahead and publish, then, and then once it's approved in Azure it will go to nuget.

@flytzen
Copy link
Collaborator

flytzen commented Oct 14, 2020

The "publish" happens automatically when we merge to master - it's sat there waiting for @BrandonPotter already :)

@flytzen
Copy link
Collaborator

flytzen commented Oct 14, 2020

ps if you want to comm more directly, find me on @flytzen on twitter

@martynas-m
Copy link
Author

martynas-m commented Oct 15, 2020

I'm using very bare Arch Linux installation.
I was missing libgdiplus too, but after installing it still crashes.
I've checked about using System.Drawing.* on Linux a bit, it seems libgdiplus is the only dependency needed ( this source )

I've also did following test to see if image can be generated on linux, and it works on my machine too:

var bmp = new Bitmap(100, 100);
var graphics = Graphics.FromImage(bmp);
graphics.DrawEllipse(Pens.Blue, new Rectangle(10, 10, 80, 80));

bmp.Save("test.bmp");

So it seems that System.Graphicsis working, but some other dependencies are missing and (most likely) that's the reason why QRCoder library is crashing.

I've also checked other dependencies they've mentioned ( `apt-utils libc6-dev' ), but I could not find them in my distro. But anyway, since my example is working (I can open saved bitmap) the problem might be somewhere else.

@flytzen
Copy link
Collaborator

flytzen commented Oct 15, 2020

Just one thought - what value are you passing for the QRPixelsPerModule parameter?
Does it crash if you pass in, say 2?

@martynas-m
Copy link
Author

@flytzen - not sure if question was to me, but I've tried to use QRCoder library alone and see if it crashes. This is code I've ran:

var qrGenerator = new QRCodeGenerator();
var payloadGenerator = new PayloadGenerator.Url("https://github.com/codebude/QRCoder/");
var qrCodeData = qrGenerator.CreateQrCode(payloadGenerator, QRCodeGenerator.ECCLevel.Q);
			
var pngQrCode = new PngByteQRCode(qrCodeData);
var qrBytes = pngQrCode.GetGraphic(10);
			
File.WriteAllBytes("qr.png", qrBytes);
			
var base64QrCode= new Base64QRCode(qrCodeData);
var qrString = base64QrCode.GetGraphic(10);
File.WriteAllText("qr.html", 
  $"<html><body><img src=\"data:image/png;base64,{qrString}\" alt=\"qr\"/></body></html>");

as you see, I've tried to generate qr code as PNG and as base64 (which, I assume, you're using in your library. But this code works and I can open both png and generated html, and scanning from phone also works.

So my earlier assumption that problem was in QRCoder seems to be wrong.

@flytzen
Copy link
Collaborator

flytzen commented Oct 15, 2020

@martynas-m Sorry, yes, the question was indeed to you :)
Thank you for looking into this deeper.
When you call GenerateSetupCode, what values do you pass in? Most importantly, what value do you pass in for QRPixelsPerModule?

@martynas-m
Copy link
Author

Hi,
I think that's was the problem- I was using value 500 (I've looked in description on description site and since it showed values passed 300, 300 (which, i guess was width and height) I somehow assumed that this parameter should also be width of qr code. Apparently it was not :)

So when I've chose to use some reasonable value like 10, it stopped crashing and works fine.

Maybe you could make error handling a bit better or just update documentation :)

Thanks for your help, and sorry for false alarm.

@flytzen flytzen reopened this Oct 15, 2020
@flytzen
Copy link
Collaborator

flytzen commented Oct 15, 2020

Thank you @martynas-m. This is the second time we have seen this so we definitely need to improve this with both docs and error handling. Thank you for raising it.

@flytzen flytzen self-assigned this Oct 15, 2020
@flytzen
Copy link
Collaborator

flytzen commented Oct 15, 2020

Need to:

  1. Update the readme
  2. Make the intellisense much clearer about the importance of this param
  3. Possible provide a default value to serve as a hint
  4. If possible, catch the exception and provide a meaningful error

@ahwm
Copy link
Collaborator

ahwm commented Oct 15, 2020

That documentation @martynas-m linked to is a mirror of an old blog post for how to use the 1.x version that used the Google Charts API. Unfortunately, we don't have direct access. But the link was provided in #21 so it may be possible to reach out and get that updated. I think it would be better to indicate in the readme that it's for 1.x and doesn't apply to 2.x.

@flytzen
Copy link
Collaborator

flytzen commented Oct 15, 2020

@ahwm I agree. I think we need to copy the documentation from that blog post to the readme. I have opened issue #59 to handle that.

@ahwm
Copy link
Collaborator

ahwm commented Oct 15, 2020

In another branch I just specified that it was for 1.x: 2880416

And working on the intellisense update.

@ahwm
Copy link
Collaborator

ahwm commented Oct 15, 2020

@BrandonPotter any chance of approving at least the latest nuget package?

@ahwm ahwm pinned this issue Dec 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants