-
Aug 7th, 2014, 12:45 PM
#1
Thread Starter
Addicted Member
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.
-
Aug 7th, 2014, 01:18 PM
#2
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.
-
Aug 7th, 2014, 01:24 PM
#3
Thread Starter
Addicted Member
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.
-
Aug 7th, 2014, 01:32 PM
#4
Thread Starter
Addicted Member
Re: Debug Works Release Fails
Here is the code for Form1_Load:
vb Code:
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load Try 1: Try Dim MyFont As System.Drawing.Text.PrivateFontCollection = New System.Drawing.Text.PrivateFontCollection MyFont.AddFontFile("gamefont.ttf") StartLabel.Font = New Font(MyFont.Families(0), 12) ScoreLabel.Font = New Font(MyFont.Families(0), 12) InfoLabel.Font = New Font(MyFont.Families(0), 12) HiScoreLabel1.Font = New Font(MyFont.Families(0), 12) HiScoreLabel2.Font = New Font(MyFont.Families(0), 12) HiScoreLabel3.Font = New Font(MyFont.Families(0), 12) HiScoreLabel4.Font = New Font(MyFont.Families(0), 12) HiScoreLabel5.Font = New Font(MyFont.Families(0), 12) Catch ex As Exception Try Dim b As Byte() = My.Resources.gamefont My.Computer.FileSystem.WriteAllBytes("gamefont.ttf", b, False) GoTo 1 Catch exc As Exception MessageBox.Show("Could not load font.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Try Me.Text = ProductName & " - v" & ProductVersion Me.KeyPreview = True PanelBack.Parent = Me PanelBack.Visible = True PanelBack.Dock = DockStyle.Fill PanelBack.BackColor = Color.Black AddHandler HiScoreLabel1.Click, AddressOf Me.Color1_Click AddHandler HiScoreLabel2.Click, AddressOf Me.Color2_Click AddHandler HiScoreLabel3.Click, AddressOf Me.Color3_Click AddHandler HiScoreLabel4.Click, AddressOf Me.Color4_Click AddHandler HiScoreLabel5.Click, AddressOf Me.Color5_Click AddHandler TimerMove.Tick, AddressOf Me.TimerMove_Tick ReloadGame() 2: If PanelBack.Width > 200 Then Me.Width -= 1 GoTo 2 ElseIf PanelBack.Width < 200 Then Me.Width += 1 GoTo 2 End If 3: If PanelBack.Height > 200 Then Me.Height -= 1 GoTo 3 ElseIf PanelBack.Height < 200 Then Me.Height += 1 GoTo 3 End If Catch ex As Exception MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub
-
Aug 7th, 2014, 01:47 PM
#5
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.
-
Aug 7th, 2014, 01:58 PM
#6
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)?
-
Aug 7th, 2014, 02:13 PM
#7
Thread Starter
Addicted Member
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.
-
Aug 7th, 2014, 02:33 PM
#8
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
-
Aug 7th, 2014, 02:35 PM
#9
Thread Starter
Addicted Member
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:
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:
Private Sub Form1_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing Try My.Computer.FileSystem.DeleteFile("C:\VB Program Files\Mini Game 2\gamefont.ttf") Catch ex As Exception MessageBox.Show("Could not delete font." & vbNewLine & ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load 1: Try Dim b As Byte() = My.Resources.gamefont My.Computer.FileSystem.WriteAllBytes("C:\VB Program Files\Mini Game 2\gamefont.ttf", b, False) Dim MyFont As System.Drawing.Text.PrivateFontCollection = New System.Drawing.Text.PrivateFontCollection MyFont.AddFontFile("C:\VB Program Files\Mini Game 2\gamefont.ttf") StartLabel.Font = New Font(MyFont.Families(0), 12) ScoreLabel.Font = New Font(MyFont.Families(0), 12) InfoLabel.Font = New Font(MyFont.Families(0), 12) HiScoreLabel1.Font = New Font(MyFont.Families(0), 12) HiScoreLabel2.Font = New Font(MyFont.Families(0), 12) HiScoreLabel3.Font = New Font(MyFont.Families(0), 12) HiScoreLabel4.Font = New Font(MyFont.Families(0), 12) HiScoreLabel5.Font = New Font(MyFont.Families(0), 12) MyFont.Dispose() Catch ex As Exception MessageBox.Show("Could not load font." & vbNewLine & ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try
Last edited by NinjaNic; Aug 7th, 2014 at 02:42 PM.
-
Aug 7th, 2014, 02:46 PM
#10
Re: Debug Works Release Fails
Originally Posted by Grimfort
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)?
!!!!
-
Aug 7th, 2014, 10:27 PM
#11
Re: Debug Works Release Fails
Originally Posted by NinjaNic
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|