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

[6.0.100-preview.6.21308.9] PixiEditor stopped working when saving, System.ArgumentException: Parameter is not valid #53991

Closed
Junjun-zhao opened this issue Jun 10, 2021 · 6 comments
Assignees
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI untriaged New issue has not been triaged by the area owner

Comments

@Junjun-zhao
Copy link
Member

Junjun-zhao commented Jun 10, 2021

Application Name: PixiEditor
OS: Windows 10 RS5
CPU: X64
.NET Build Number: 6.0.100-preview.6.21308.9

Verify Scenarios:

  1. Windows 10 RS5 X64 + dotnet-sdk-5.0.204-win-x64 PASS
  2. Windows 10 RS5 X64 + dotnet-sdk-6.0.100-preview.5.21266.3 PASS
  3. Windows 10 RS5 X64 + 6.0.100-preview.6.21308.9: Fail

Source Code & App check at : https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1340936

Minimal Repro steps:

This is 5.0 app, but we are running it on 6.0, machine only have 6.0 installed, and DOTNET_ROLL_FORWARD_ON_NO_CANDIDATE_FX=2, so it runs on 6.0

1)Copy App to machine
2) Run PixiEditor.exe
3) Click New
4) We can leave Width-Height as default, click OK
5)click File, Save
6)input file name, click Save

Note : If we make changes in the pixi, error Not Repro.

Expected Result:

App should continue working

Actual Result:

App has stopped working window displayed, app shutdown

Event Viewer Log


CoreCLR Version: 6.0.21.30601
.NET Version: 6.0.0-preview.6.21306.1
Description: The process was terminated due to an unhandled exception.
Exception Info: System.ArgumentException: Parameter is not valid.
   at System.Drawing.Bitmap..ctor(Int32 width, Int32 height, Int32 stride, PixelFormat format, IntPtr scan0) in System.Drawing.Common.dll:token 0x60000d6+0x1b
   at PixiEditor.Parser.SerializableLayer.ToBitmap() in PixiParser.dll:token 0x600002e+0x0
   at PixiEditor.Parser.PixiParser.Serialize(SerializableDocument document) in PixiParser.dll:token 0x6000038+0x5f
   at PixiEditor.Parser.PixiParser.Serialize(SerializableDocument document, Stream stream) in PixiParser.dll:token 0x6000039+0x0
   at PixiEditor.Parser.PixiParser.Serialize(SerializableDocument document, String path) in PixiParser.dll:token 0x600003a+0x9
   at PixiEditor.Models.IO.Exporter.SaveAsEditableFile(Document document, String path) in C:\source code\202104.NETCoreP0UpgradedApps\PixiEditor\PixiEditor\Models\IO\Exporter.cs:line 45
   at PixiEditor.Models.IO.Exporter.SaveAsEditableFileWithDialog(Document document, String& path) in C:\source code\202104.NETCoreP0UpgradedApps\PixiEditor\PixiEditor\Models\IO\Exporter.cs:line 29
   at PixiEditor.Models.DataHolders.Document.SaveWithDialog() in C:\source code\202104.NETCoreP0UpgradedApps\PixiEditor\PixiEditor\Models\DataHolders\Document\Document.IO.cs:line 39
   at PixiEditor.ViewModels.SubViewModels.Main.FileViewModel.SaveDocument(Object parameter) in C:\source code\202104.NETCoreP0UpgradedApps\PixiEditor\PixiEditor\ViewModels\SubViewModels\Main\FileViewModel.cs:line 274
   at PixiEditor.Helpers.RelayCommand.Execute(Object parameter) in C:\source code\202104.NETCoreP0UpgradedApps\PixiEditor\PixiEditor\Helpers\RelayCommand.cs:line 40
   at MS.Internal.Commands.CommandHelpers.CriticalExecuteCommandSource(ICommandSource commandSource, Boolean userInitiated) in PresentationFramework.dll:token 0x60017f6+0x4a
   at System.Windows.Controls.MenuItem.InvokeClickAfterRender(Object arg) in PresentationFramework.dll:token 0x6006f8e+0x18
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) in WindowsBase.dll:token 0x6000eaf+0xca
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler) in WindowsBase.dll:token 0x6000eae+0x3a
   at System.Windows.Threading.DispatcherOperation.InvokeImpl() in WindowsBase.dll:token 0x6000f87+0xa7
   at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj) in WindowsBase.dll:token 0x60002de+0x21
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) in System.Private.CoreLib.dll:token 0x60029f7+0x87
--- End of stack trace from previous location ---
   at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state) in WindowsBase.dll:token 0x60002dd+0x58
   at System.Windows.Threading.DispatcherOperation.Invoke() in WindowsBase.dll:token 0x6000f84+0x9e
   at System.Windows.Threading.Dispatcher.ProcessQueue() in WindowsBase.dll:token 0x6000f1a+0x139
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) in WindowsBase.dll:token 0x6000f21+0xd9
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) in WindowsBase.dll:token 0x60001a3+0x23
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) in WindowsBase.dll:token 0x6000193+0x60
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) in WindowsBase.dll:token 0x6000eaf+0xca
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler) in WindowsBase.dll:token 0x6000eae+0x3a
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs) in WindowsBase.dll:token 0x6000efa+0xf2
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam) in WindowsBase.dll:token 0x6000191+0x3f
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame) in WindowsBase.dll:token 0x6000f1c+0x3c
   at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame) in WindowsBase.dll:token 0x6000ed7+0x5e
   at System.Windows.Threading.Dispatcher.Run() in WindowsBase.dll:token 0x6000ed6+0x5
   at System.Windows.Application.RunDispatcher(Object ignore) in PresentationFramework.dll:token 0x6001fbe+0x1f
   at System.Windows.Application.RunInternal(Window window) in PresentationFramework.dll:token 0x6001f92+0xd9
   at System.Windows.Application.Run() in PresentationFramework.dll:token 0x6001f44+0x7
   at PixiEditor.App.Main() in PixiEditor.dll:token 0x6000016+0xe

Findings :

Error is coming from this package :

For minimal app repro :

This code will work on .net5 but throws exception on .net6

  1. create console app (net5 or net6), but we need to run it on net6
  2. Add this package : <PackageReference Include="PixiEditor.Parser" Version="1.0.1.1" />
  3. Add this code, we can change pixi file path, pixi file should be empty :
    SerializableDocument document = PixiParser.Deserialize("./pixiFile.pixi");
    PixiParser.Serialize(document, "./pixiFile.pixi"); //error here

Exception :

Unhandled exception. System.ArgumentException: Parameter is not valid.
 at System.Drawing.SafeNativeMethods.Gdip.CheckStatus(Int32 status) in System.Drawing.Common.dll:token 0x6000b61+0x3
   at System.Drawing.Bitmap..ctor(Int32 width, Int32 height, Int32 stride, PixelFormat format, IntPtr scan0) in System.Drawing.Common.dll:token 0x60000c2+0x1b
   at PixiEditor.Parser.SerializableLayer.ToBitmap() in PixiParser.dll:token 0x600002e+0x0
   at PixiEditor.Parser.PixiParser.Serialize(SerializableDocument document) in PixiParser.dll:token 0x6000038+0x5f
   at PixiEditor.Parser.PixiParser.Serialize(SerializableDocument document, Stream stream) in PixiParser.dll:token 0x6000039+0x0
   at PixiEditor.Parser.PixiParser.Serialize(SerializableDocument document, String path) in PixiParser.dll:token 0x600003a+0x9
   at ConsoleApp17.Program.Main(String[] args) in C:\Users\v-altunc\source\repos\ConsoleApp17\ConsoleApp17\Program.cs:line 16

When we update PixiEditor.Parser to latest(1.1.2.1), we also get an error on .net6, we think these errors are related, but PixiEditor has dependency 1.0.1.1

Error on latest PixiEditor.Parser(1.1.2.1) :

Unhandled exception. System.ArgumentNullException: Value cannot be null. (Parameter 'arr') 
at System.Runtime.InteropServices.Marshal.UnsafeAddrOfPinnedArrayElement[T](T[] arr, Int32 index) in System.Private.CoreLib.dll:token 0x6004687+0xd
   at PixiEditor.Parser.SerializableLayer.ToBitmap() in PixiParser.dll:token 0x6000035+0x0
   at PixiEditor.Parser.PixiParser.WriteLayers(SerializableDocument document, BinaryWriter writer) in PixiParser.dll:token 0x6000044+0x1f
   at PixiEditor.Parser.PixiParser.Serialize(SerializableDocument document, Stream stream) in PixiParser.dll:token 0x6000041+0x2c
   at PixiEditor.Parser.PixiParser.Serialize(SerializableDocument document, String path) in PixiParser.dll:token 0x6000043+0x9
   at ConsoleApp17.Program.Main(String[] args) in C:\Users\v-altunc\source\repos\ConsoleApp17\ConsoleApp17\Program.cs:line 16

@dotnet-actwx-bot @dotnet/compat

@ghost
Copy link

ghost commented Jun 10, 2021

Tagging subscribers to this area: @safern, @tarekgh
See info in area-owners.md if you want to be subscribed.

Issue Details

Application Name: PixiEditor
OS: Windows 10 RS5
CPU: X64
.NET Build Number: 6.0.100-preview.6.21308.9

Verify Scenarios:

  1. Windows 10 RS5 X64 + dotnet-sdk-5.0.204-win-x64 PASS
  2. Windows 10 RS5 X64 + dotnet-sdk-6.0.100-preview.5.21266.3 PASS
  3. Windows 10 RS5 X64 + 6.0.100-preview.6.21308.9: Fail

Source Code & App check at : https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1340936

Minimal Repro steps:

This is 5.0 app, but we are running it on 6.0, machine only have 6.0 installed, and DOTNET_ROLL_FORWARD_ON_NO_CANDIDATE_FX=2, so it runs on 6.0

1)Copy App to machine
2) Run PixiEditor.exe
3) Click New
4) We can leave Width-Height as default, click OK
5)click File, Save
6)input file name, click Save

Note : If we make changes in the pixi, error Not Repro.

Expected Result:

App should continue working

Actual Result:

App has stopped working window displayed, app shutdown

Event Viewer Log


CoreCLR Version: 6.0.21.30601
.NET Version: 6.0.0-preview.6.21306.1
Description: The process was terminated due to an unhandled exception.
Exception Info: System.ArgumentException: Parameter is not valid.
   at System.Drawing.Bitmap..ctor(Int32 width, Int32 height, Int32 stride, PixelFormat format, IntPtr scan0) in System.Drawing.Common.dll:token 0x60000d6+0x1b
   at PixiEditor.Parser.SerializableLayer.ToBitmap() in PixiParser.dll:token 0x600002e+0x0
   at PixiEditor.Parser.PixiParser.Serialize(SerializableDocument document) in PixiParser.dll:token 0x6000038+0x5f
   at PixiEditor.Parser.PixiParser.Serialize(SerializableDocument document, Stream stream) in PixiParser.dll:token 0x6000039+0x0
   at PixiEditor.Parser.PixiParser.Serialize(SerializableDocument document, String path) in PixiParser.dll:token 0x600003a+0x9
   at PixiEditor.Models.IO.Exporter.SaveAsEditableFile(Document document, String path) in C:\source code\202104.NETCoreP0UpgradedApps\PixiEditor\PixiEditor\Models\IO\Exporter.cs:line 45
   at PixiEditor.Models.IO.Exporter.SaveAsEditableFileWithDialog(Document document, String& path) in C:\source code\202104.NETCoreP0UpgradedApps\PixiEditor\PixiEditor\Models\IO\Exporter.cs:line 29
   at PixiEditor.Models.DataHolders.Document.SaveWithDialog() in C:\source code\202104.NETCoreP0UpgradedApps\PixiEditor\PixiEditor\Models\DataHolders\Document\Document.IO.cs:line 39
   at PixiEditor.ViewModels.SubViewModels.Main.FileViewModel.SaveDocument(Object parameter) in C:\source code\202104.NETCoreP0UpgradedApps\PixiEditor\PixiEditor\ViewModels\SubViewModels\Main\FileViewModel.cs:line 274
   at PixiEditor.Helpers.RelayCommand.Execute(Object parameter) in C:\source code\202104.NETCoreP0UpgradedApps\PixiEditor\PixiEditor\Helpers\RelayCommand.cs:line 40
   at MS.Internal.Commands.CommandHelpers.CriticalExecuteCommandSource(ICommandSource commandSource, Boolean userInitiated) in PresentationFramework.dll:token 0x60017f6+0x4a
   at System.Windows.Controls.MenuItem.InvokeClickAfterRender(Object arg) in PresentationFramework.dll:token 0x6006f8e+0x18
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) in WindowsBase.dll:token 0x6000eaf+0xca
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler) in WindowsBase.dll:token 0x6000eae+0x3a
   at System.Windows.Threading.DispatcherOperation.InvokeImpl() in WindowsBase.dll:token 0x6000f87+0xa7
   at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj) in WindowsBase.dll:token 0x60002de+0x21
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) in System.Private.CoreLib.dll:token 0x60029f7+0x87
--- End of stack trace from previous location ---
   at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state) in WindowsBase.dll:token 0x60002dd+0x58
   at System.Windows.Threading.DispatcherOperation.Invoke() in WindowsBase.dll:token 0x6000f84+0x9e
   at System.Windows.Threading.Dispatcher.ProcessQueue() in WindowsBase.dll:token 0x6000f1a+0x139
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) in WindowsBase.dll:token 0x6000f21+0xd9
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) in WindowsBase.dll:token 0x60001a3+0x23
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) in WindowsBase.dll:token 0x6000193+0x60
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) in WindowsBase.dll:token 0x6000eaf+0xca
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler) in WindowsBase.dll:token 0x6000eae+0x3a
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs) in WindowsBase.dll:token 0x6000efa+0xf2
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam) in WindowsBase.dll:token 0x6000191+0x3f
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame) in WindowsBase.dll:token 0x6000f1c+0x3c
   at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame) in WindowsBase.dll:token 0x6000ed7+0x5e
   at System.Windows.Threading.Dispatcher.Run() in WindowsBase.dll:token 0x6000ed6+0x5
   at System.Windows.Application.RunDispatcher(Object ignore) in PresentationFramework.dll:token 0x6001fbe+0x1f
   at System.Windows.Application.RunInternal(Window window) in PresentationFramework.dll:token 0x6001f92+0xd9
   at System.Windows.Application.Run() in PresentationFramework.dll:token 0x6001f44+0x7
   at PixiEditor.App.Main() in PixiEditor.dll:token 0x6000016+0xe

Findings :

Error is coming from this package :

For minimal app repro :

This code will work on .net5 but throws exception on .net6

  1. create console app (net5 or net6), but we need to run it on net6
  2. Add this package : <PackageReference Include="PixiEditor.Parser" Version="1.0.1.1" />
  3. Add this code, we can change pixi file path, pixi file should be empty :
    SerializableDocument document = PixiParser.Deserialize("./pixiFile.pixi");
    PixiParser.Serialize(document, "./pixiFile.pixi"); //error here

Exception :

Unhandled exception. System.ArgumentException: Parameter is not valid.

  at System.Drawing.Bitmap..ctor(Int32 width, Int32 height, Int32 stride, PixelFormat format, IntPtr scan0) in System.Drawing.Common.dll:token 0x60000c2+0x1b
  at PixiEditor.Parser.SerializableLayer.ToBitmap() in PixiParser.dll:token 0x600002e+0x0
  at PixiEditor.Parser.PixiParser.Serialize(SerializableDocument document) in PixiParser.dll:token 0x6000038+0x5f
  at PixiEditor.Parser.PixiParser.Serialize(SerializableDocument document, Stream stream) in PixiParser.dll:token 0x6000039+0x0
  at PixiEditor.Parser.PixiParser.Serialize(SerializableDocument document, String path) in PixiParser.dll:token 0x600003a+0x9
  at ConsoleApp17.Program.Main(String[] args) in C:\Users\v-altunc\source\repos\ConsoleApp17\ConsoleApp17\Program.cs:line 16

When we update PixiEditor.Parser to latest(1.1.2.1), we also get an error on .net6, we think these errors are related, but PixiEditor has dependency 1.0.1.1

Error on latest PixiEditor.Parser(1.1.2.1) :

Unhandled exception. System.ArgumentNullException: Value cannot be null. (Parameter 'arr')

   at PixiEditor.Parser.SerializableLayer.ToBitmap() in PixiParser.dll:token 0x6000035+0x0
   at PixiEditor.Parser.PixiParser.WriteLayers(SerializableDocument document, BinaryWriter writer) in PixiParser.dll:token 0x6000044+0x1f
   at PixiEditor.Parser.PixiParser.Serialize(SerializableDocument document, Stream stream) in PixiParser.dll:token 0x6000041+0x2c
   at PixiEditor.Parser.PixiParser.Serialize(SerializableDocument document, String path) in PixiParser.dll:token 0x6000043+0x9
   at ConsoleApp17.Program.Main(String[] args) in C:\Users\v-altunc\source\repos\ConsoleApp17\ConsoleApp17\Program.cs:line 16

@dotnet-actwx-bot @dotnet/compat

Author: Junjun-zhao
Assignees: ericstj
Labels:

area-System.Drawing

Milestone: -

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged New issue has not been triaged by the area owner label Jun 10, 2021
@tarekgh tarekgh assigned safern and unassigned ericstj Jun 10, 2021
@safern
Copy link
Member

safern commented Jun 10, 2021

I started looking into this and nothing changed on System.Drawing.Common from Preview5 to what's in main (Preview6).

The interop call to GDI that is failing is:

int status = Gdip.GdipCreateBitmapFromScan0(width, height, stride, unchecked((int)format), scan0, out bitmap);

GDI is returning an invalid parameter because the stride in that case is 0. I think this error is somewhere either on the JIT or the runtime, as after debugging, this line of code should not be hit: https://github.com/PixiEditor/PixiParser/blob/3b21a5c079de60a37d5baff0b488fff002765e45/src/PixiParser/Parser/PixiParser.Serialize.cs#L67 because the only layer on the document, it's height and width is 0, so it should continue here: https://github.com/PixiEditor/PixiParser/blob/3b21a5c079de60a37d5baff0b488fff002765e45/src/PixiParser/Parser/PixiParser.Serialize.cs#L64

image

So since these are 0, and the code is not going inside the if:

if (layer.Width * layer.Height == 0)
{
    writer.Write(0);
    continue;
}

the stride when creating the bitmap (which is calculated with Width * 4) is 0:
https://github.com/PixiEditor/PixiParser/blob/3b21a5c079de60a37d5baff0b488fff002765e45/src/PixiParser/Models/SerializableLayer.cs#L66

So this code should never be called in this case as it is the case in Preview5, that is why in Preview5 this error doesn't happen cause we never get to the layer.ToBitmap call.

@jkotas who can help look at this issue?

@jkotas
Copy link
Member

jkotas commented Jun 11, 2021

This looks like a dup of issue fixed by #53806.

Does it repro on live main?

cc @kunalspathak

@jkotas jkotas added area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI and removed area-System.Drawing labels Jun 11, 2021
@jkotas jkotas assigned kunalspathak and unassigned safern Jun 11, 2021
@safern
Copy link
Member

safern commented Jun 11, 2021

Yeah, with main it doesn't repro. Thanks for pointing it out @jkotas. I will close the issue as I no longer reproed it with main.

@safern safern closed this as completed Jun 11, 2021
@kunalspathak
Copy link
Member

Yes, the C# code seems to be doing multiplication and there was problem with imul that I addressed in #53806.

@Junjun-zhao
Copy link
Member Author

Verified it and fixed on build dotnet-sdk-6.0.100-preview.7.21320.2

@ghost ghost locked as resolved and limited conversation to collaborators Jul 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI untriaged New issue has not been triaged by the area owner
Projects
None yet
Development

No branches or pull requests

5 participants