Results 1 to 11 of 11

Thread: Debug Works Release Fails

  1. #1

    Thread Starter
    Addicted Member NinjaNic's Avatar
    Join Date
    Dec 2013
    Location
    Earth
    Posts
    230

    Debug Works Release Fails

    Hello! In my program I had created a lot of controls programatically. This is the first time that the release version does not work. I get a very long error message when I try to run it. The debug run fine, just the way I had created it.

    Is there a simple way to fix this, or do I have to post all 320 lines of code, or when whole error message?
    Thanks.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: Debug Works Release Fails

    Think about what you've just asked us. Do you really think that there's just one specific reason that this would happen such that we could tell you what the issue was with no more information other than the fact that the Debug build runs without issue while the Release build fails? Any time you encounter an error, just provide the error message without even thinking about. It's given to you as an aid to diagnosing the issue. If you want us to diagnose the issue then logic dictates that you give it to us. You certainly don't have to provide all the code but posting the RELEVANT code can be a very good idea, including pointing out where in that code the error occurs.

  3. #3

    Thread Starter
    Addicted Member NinjaNic's Avatar
    Join Date
    Dec 2013
    Location
    Earth
    Posts
    230

    Re: Debug Works Release Fails

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

    ************** Exception Text **************
    System.ArgumentException: Parameter is not valid.
    at System.Drawing.FontFamily.GetName(Int32 language)
    at System.Drawing.FontFamily.get_Name()
    at System.Windows.Forms.Internal.WindowsFont.FromFont(Font font, WindowsFontQuality fontQuality)
    at System.Windows.Forms.Internal.WindowsGraphicsCacheManager.GetWindowsFont(Font font, WindowsFontQuality fontQuality)
    at System.Windows.Forms.TextRenderer.MeasureText(String text, Font font, Size proposedSize, TextFormatFlags flags)
    at System.Windows.Forms.Layout.LayoutUtils.MeasureTextCache.GetUnconstrainedSize(String text, Font font, TextFormatFlags flags)
    at System.Windows.Forms.Layout.LayoutUtils.MeasureTextCache.TextRequiresWordBreak(String text, Font font, Size size, TextFormatFlags flags)
    at System.Windows.Forms.Label.CreateTextFormatFlags(Size constrainingSize)
    at System.Windows.Forms.Label.CreateTextFormatFlags()
    at System.Windows.Forms.Label.OnPaint(PaintEventArgs e)
    at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)
    at System.Windows.Forms.Control.WmPaint(Message& m)
    at System.Windows.Forms.Control.WndProc(Message& m)
    at System.Windows.Forms.Label.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.18444 built by: FX451RTMGDR
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
    ----------------------------------------
    Mini Game 2
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/Users/Nicolas/Desktop/Mini%20Game%202.exe
    ----------------------------------------
    Microsoft.VisualBasic
    Assembly Version: 10.0.0.0
    Win32 Version: 11.0.50938.18408 built by: FX451RTMGREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Microsoft.VisualBasic/v4.0_10.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
    ----------------------------------------
    System
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
    ----------------------------------------
    System.Core
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
    ----------------------------------------
    System.Windows.Forms
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL
    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.18408 built by: FX451RTMGREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
    ----------------------------------------
    System.Runtime.Remoting
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.34108 built by: FX45W81RTMGDR
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Runtime.Remoting/v4.0_4.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll
    ----------------------------------------
    System.Configuration
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
    ----------------------------------------
    System.Xml
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.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.

  4. #4

    Thread Starter
    Addicted Member NinjaNic's Avatar
    Join Date
    Dec 2013
    Location
    Earth
    Posts
    230

    Re: Debug Works Release Fails

    Here is the code for Form1_Load:
    vb Code:
    1. Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    2.         Try
    3. 1:
    4.             Try
    5.                 Dim MyFont As System.Drawing.Text.PrivateFontCollection = New System.Drawing.Text.PrivateFontCollection
    6.                 MyFont.AddFontFile("gamefont.ttf")
    7.                 StartLabel.Font = New Font(MyFont.Families(0), 12)
    8.                 ScoreLabel.Font = New Font(MyFont.Families(0), 12)
    9.                 InfoLabel.Font = New Font(MyFont.Families(0), 12)
    10.                 HiScoreLabel1.Font = New Font(MyFont.Families(0), 12)
    11.                 HiScoreLabel2.Font = New Font(MyFont.Families(0), 12)
    12.                 HiScoreLabel3.Font = New Font(MyFont.Families(0), 12)
    13.                 HiScoreLabel4.Font = New Font(MyFont.Families(0), 12)
    14.                 HiScoreLabel5.Font = New Font(MyFont.Families(0), 12)
    15.             Catch ex As Exception
    16.                 Try
    17.                     Dim b As Byte() = My.Resources.gamefont
    18.                     My.Computer.FileSystem.WriteAllBytes("gamefont.ttf", b, False)
    19.                     GoTo 1
    20.                 Catch exc As Exception
    21.                     MessageBox.Show("Could not load font.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
    22.                 End Try
    23.             End Try
    24.  
    25.             Me.Text = ProductName & " - v" & ProductVersion
    26.             Me.KeyPreview = True
    27.             PanelBack.Parent = Me
    28.             PanelBack.Visible = True
    29.             PanelBack.Dock = DockStyle.Fill
    30.             PanelBack.BackColor = Color.Black
    31.             AddHandler HiScoreLabel1.Click, AddressOf Me.Color1_Click
    32.             AddHandler HiScoreLabel2.Click, AddressOf Me.Color2_Click
    33.             AddHandler HiScoreLabel3.Click, AddressOf Me.Color3_Click
    34.             AddHandler HiScoreLabel4.Click, AddressOf Me.Color4_Click
    35.             AddHandler HiScoreLabel5.Click, AddressOf Me.Color5_Click
    36.             AddHandler TimerMove.Tick, AddressOf Me.TimerMove_Tick
    37.             ReloadGame()
    38. 2:
    39.             If PanelBack.Width > 200 Then
    40.                 Me.Width -= 1
    41.                 GoTo 2
    42.             ElseIf PanelBack.Width < 200 Then
    43.                 Me.Width += 1
    44.                 GoTo 2
    45.             End If
    46. 3:
    47.             If PanelBack.Height > 200 Then
    48.                 Me.Height -= 1
    49.                 GoTo 3
    50.             ElseIf PanelBack.Height < 200 Then
    51.                 Me.Height += 1
    52.                 GoTo 3
    53.             End If
    54.         Catch ex As Exception
    55.             MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
    56.         End Try
    57.     End Sub

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: Debug Works Release Fails

    You have a GoTo in your code so it is pretty clearly bad code. You should start by restructuring it to get rid of that GoTo.

    There's clearly an issue with that font based on the exception's stack trace. My first guess would be that your Release build doesn't have permission to write to the location you're trying to use. Try using a location that you know will work, e.g. the current user's Documents folder, and see if that makes a difference.

  6. #6
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: Debug Works Release Fails

    I have never used Fonts like this, but I can point out some obvious issues in your code. You try and load a font, which when you think fails (you trap EVERY failure type), try to extract from the resource. However you never actually retry loading the fontfile after extracting. It looks like you would have to run your app twice for it to work.
    -Edit, O NOES!! You are using GOTO statements to retry it. What happens if that fails over and over and over, infinite loop!?

    You are not using paths for anything, just the filename itself. I have not looked to see where the AddFontFile would read from by default (application path?) or where WriteAllBytes would write to (Mydocuments?). Either way, it is dodgy, you are better off extracting it to a temp file, and loading that on every run, or at least writing it to a known place.

    My guess is that you are not telling us the whole story. When you say release, how are you testing this. Are you simply changing your project to run in Release mode then starting it on the dev machine, or are you really copying this to another machine and trying it? What about if you compile in Debug mode and copy to this other machine (assuming I am right)?

  7. #7

    Thread Starter
    Addicted Member NinjaNic's Avatar
    Join Date
    Dec 2013
    Location
    Earth
    Posts
    230

    Re: Debug Works Release Fails

    Well, the Release Program does work fine if I remove all of the code relating to the font.
    But the "gamefont.ttf" should be created in the same folder location with the program itself, if it doesn't have a path. (And it is.)
    Also, your idea of a temporary file is a good one, is there something specific I should do with it, or just delete the file when the program is closed?
    Last edited by NinjaNic; Aug 7th, 2014 at 02:16 PM.

  8. #8
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,531

    Re: Debug Works Release Fails

    But the "gamefont.ttf" should be created in the same folder location with the program itself,
    Did you add it to the project? What is its "Copy to output directory" option set to?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  9. #9

    Thread Starter
    Addicted Member NinjaNic's Avatar
    Join Date
    Dec 2013
    Location
    Earth
    Posts
    230

    Re: Debug Works Release Fails

    I'm not sure, but this has worked fine on other programs. But anyway now I can see "gamefont.ttf" being created and deleted, and I think there is a problem with this line of code:
    vb Code:
    1. MyFont.AddFontFile("C:\Mini Game 2\gamefont.ttf")
    Because when I remove it, the release works fine, except without the font.

    By the way, this is my new code:
    vb Code:
    1. Private Sub Form1_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    2.         Try
    3.             My.Computer.FileSystem.DeleteFile("C:\VB Program Files\Mini Game 2\gamefont.ttf")
    4.         Catch ex As Exception
    5.             MessageBox.Show("Could not delete font." & vbNewLine & ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
    6.         End Try
    7.     End Sub
    8.  
    9.     Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    10. 1:
    11.         Try
    12.             Dim b As Byte() = My.Resources.gamefont
    13.             My.Computer.FileSystem.WriteAllBytes("C:\VB Program Files\Mini Game 2\gamefont.ttf", b, False)
    14.             Dim MyFont As System.Drawing.Text.PrivateFontCollection = New System.Drawing.Text.PrivateFontCollection
    15.             MyFont.AddFontFile("C:\VB Program Files\Mini Game 2\gamefont.ttf")
    16.             StartLabel.Font = New Font(MyFont.Families(0), 12)
    17.             ScoreLabel.Font = New Font(MyFont.Families(0), 12)
    18.             InfoLabel.Font = New Font(MyFont.Families(0), 12)
    19.             HiScoreLabel1.Font = New Font(MyFont.Families(0), 12)
    20.             HiScoreLabel2.Font = New Font(MyFont.Families(0), 12)
    21.             HiScoreLabel3.Font = New Font(MyFont.Families(0), 12)
    22.             HiScoreLabel4.Font = New Font(MyFont.Families(0), 12)
    23.             HiScoreLabel5.Font = New Font(MyFont.Families(0), 12)
    24.             MyFont.Dispose()
    25.         Catch ex As Exception
    26.             MessageBox.Show("Could not load font." & vbNewLine & ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
    27.         End Try
    Last edited by NinjaNic; Aug 7th, 2014 at 02:42 PM.

  10. #10
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: Debug Works Release Fails

    Quote Originally Posted by Grimfort View Post
    My guess is that you are not telling us the whole story. When you say release, how are you testing this. Are you simply changing your project to run in Release mode then starting it on the dev machine, or are you really copying this to another machine and trying it? What about if you compile in Debug mode and copy to this other machine (assuming I am right)?
    !!!!

  11. #11
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: Debug Works Release Fails

    Quote Originally Posted by NinjaNic View Post
    But the "gamefont.ttf" should be created in the same folder location with the program itself
    That's a bad idea. You can't know for sure that your app will have appropriate permission to write to that folder. The user's own app data folder is a better option. Look at the My.Computer.FileSystem.SpecialDirectories object and the Environment.GetFolderPath method as options for getting standard folder paths. I'd also suggest checking whether the file exists first and creating it if required, then using it.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width