-1

The error occurs when resizing an array only on one specific array and when the program is run outside of the VS idea. When i hit compile and run, no errors of any description occurs.

Here is the detail of the 'exeption'

See the end of this message for details on invoking 
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.NullReferenceException: Object reference not set to an instance of an object.
   at BWING.MAINW.ResizeArray(Array arr, Int32[] newSizes) in c:\Users\FFA\Documents\BWING\ENG\BWING\BWING\MAINW.cs:line 583
   at BWING.MAINW.MAINW_Load(Object sender, EventArgs e) in c:\Users\FFA\Documents\BWING\ENG\BWING\BWING\MAINW.cs:line 145
   at System.Windows.Forms.Form.OnLoad(EventArgs e)
   at System.Windows.Forms.Form.OnCreateControl()
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl()
   at System.Windows.Forms.Control.WmShowWindow(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.ContainerControl.WndProc(Message& m)
   at System.Windows.Forms.Form.WmShowWindow(Message& m)
   at System.Windows.Forms.Form.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17929 built by: FX45RTMREL
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------
BWING
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/Users/FFA/Documents/BWING/ENG/BWING/BWING/bin/Debug/BWING.exe
----------------------------------------
System.Windows.Forms
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17929 built by: FX45RTMREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17929 built by: FX45RTMREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17929 built by: FX45RTMREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
    <system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.

Here is the code intended to resize the array :

ResizeArray(zbuffer, new int[] {xdisplay});

And here is the method i fetched from the internet to resize the array :

private static Array ResizeArray(Array arr, int[] newSizes)
{
    if (newSizes.Length != arr.Rank)
        throw new ArgumentException("arr must have the same number of dimensions " +
                                    "as there are elements in newSizes", "newSizes");

    var temp = Array.CreateInstance(arr.GetType().GetElementType(), newSizes);
    int length = arr.Length <= temp.Length ? arr.Length : temp.Length;
    Array.ConstrainedCopy(arr, 0, temp, 0, length);
    return temp;
}

This never happened to me and i didn't think it was possible.

D Stanley
  • 149,601
  • 11
  • 178
  • 240
FFA702
  • 29
  • 3
  • what is zbuffer set to? If you just have Array zbuffer; that may be your issue. – Robert Nov 06 '14 at 18:52
  • 1
    `arr` must be null - look at the code in `MAINW_Load` before calling this function and see how it could be null. – D Stanley Nov 06 '14 at 18:53
  • possible duplicate of [What is a NullReferenceException and how do I fix it?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – mason Nov 06 '14 at 18:56
  • From the stack trace, I can see that the exception is being thrown on line 583 of `MAINW.cs`. Can you point out which line that is in your `ResizeArray` method? I'm guessing that either `arr` or `newSizes` is `null`. You need to make sure it gets initialized to something other than null before you call `ResizeArray()`. – jwnace Nov 06 '14 at 19:03
  • Change to AnyCPU and see if it still doesnt happen in VS; sounds/looks like the "silent exception" bug (exception not caught in form ctor or form load causes problems elsewhere). Show your Form_Load code maybe. – Ňɏssa Pøngjǣrdenlarp Nov 06 '14 at 19:05
  • Yep array was null silly me – FFA702 Nov 06 '14 at 21:37

1 Answers1

0

Try to add the following lines:

private static Array ResizeArray(Array arr, int[] newSizes)
{
    // Add next four lines
    if (newSizes == null)
        throw new ArgumentNullException("newSizes is null!"); 
    if (arr == null)
        throw new ArgumentNullException("arr is null!"); 
    if (newSizes.Length != arr.Rank)
        throw new ArgumentException("arr must have the same number of dimensions " +
                                    "as there are elements in newSizes", "newSizes");

    var temp = Array.CreateInstance(arr.GetType().GetElementType(), newSizes);
    int length = arr.Length <= temp.Length ? arr.Length : temp.Length;
    Array.ConstrainedCopy(arr, 0, temp, 0, length);
    return temp;
}
Sjips
  • 1,248
  • 2
  • 11
  • 22