Release build crashes Buzz but Debug build doesn't.

User avatar
IXix
Posts: 1113
Joined: Wed Nov 23, 2011 3:24 pm

Release build crashes Buzz but Debug build doesn't.

Post by IXix »

I don't understand what's happening here. If you select 'About' from the machine context menu, the release build causes Buzz to crash but the debug build doesn't.

BTDSys PeerADSR (debug)
BTDSys PeerADSR (release)

There's nothing to go wrong in the machine's code...

Code: Select all

	case 3 : //About
		{
			MessageBox(NULL,
				"BTDSys PeerADSR v1.1\n"
				"©2002-2011 Ed Powley (BTDSys)\n\n"
				"http://sourceforge.net/projects/btdsys/"
				"\n\nThis machine is DONATIONWARE, so if you like it, and want to "
				"send me something nice (eg hardware, CDs, money etc etc), drop "
				"me an email.\n\n"
				"Please read the help file for usage instructions",
				"BTDSys PeerADSR", 
				MB_OK|MB_SYSTEMMODAL|MB_ICONINFORMATION);
		}
		break;
What's happening? I thought maybe it was a BuzzGUI problem but when I try to debug it from that side, Buzz just exits. I looks like it pops up a few exception windows but it doesn't give me time to see what they are.
oskari
Site Admin
Posts: 296
Joined: Mon Nov 21, 2011 2:04 pm

Re: Release build crashes Buzz but Debug build doesn't.

Post by oskari »

It's probably related to MFC and AFX_MANAGE_STATE. I think I had the same problem with pxp when I switched to VS2010 but I don't remember exactly what it was or how I fixed it.
User avatar
IXix
Posts: 1113
Joined: Wed Nov 23, 2011 3:24 pm

Re: Release build crashes Buzz but Debug build doesn't.

Post by IXix »

oskari wrote:It's probably related to MFC and AFX_MANAGE_STATE. I think I had the same problem with pxp when I switched to VS2010 but I don't remember exactly what it was or how I fixed it.
Thanks. At least it gives me an idea of where to start looking.
User avatar
IXix
Posts: 1113
Joined: Wed Nov 23, 2011 3:24 pm

Re: Release build crashes Buzz but Debug build doesn't.

Post by IXix »

Well, commenting out this...

Code: Select all

AFX_MANAGE_STATE(AfxGetStaticModuleState());
...in mi::Command() solves the about box crash but the same trick doesn't work for the machine assign dialog :(.

Code: Select all

void mi::DoAssignPar(int TrackNum)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());

	CAssignDlg assdlg;

	assdlg.g_mi = this;
	assdlg.g_track = &Tracks[TrackNum];
	assdlg.g_tracknum = TrackNum;

	assdlg.DoModal();
}
If I comment out the AFX_MANAGE_STATE line here, I get an error message saying "Attempted an unsupported operation" with the release build. The debug build triggers this assertion in AfxGetResourceHandle()...

Code: Select all

ASSERT(afxCurrentResourceHandle != NULL);
...so it looks like I need to set the resource handle to be that of my dll but I don't know the MFC way to do it.

Any help would be appreciated as I know zero MFC.
User avatar
thOke
Posts: 343
Joined: Thu Nov 24, 2011 7:14 am

Re: Release build crashes Buzz but Debug build doesn't.

Post by thOke »

recently switched to win7 64-bit. any news about this ? i didn't have that problem with PeerADSR on winxp sp3

now the debug build does not run at all and the assignment and about screens of the release version are crashing buzz (bld 1481).
the assignment screens of PeerLFO or PeerENV are working correctly ... where is the difference to these machines ?
User avatar
IXix
Posts: 1113
Joined: Wed Nov 23, 2011 3:24 pm

Re: Release build crashes Buzz but Debug build doesn't.

Post by IXix »

thOke wrote:recently switched to win7 64-bit. any news about this ? i didn't have that problem with PeerADSR on winxp sp3

now the debug build does not run at all and the assignment and about screens of the release version are crashing buzz (bld 1481).
Sorry about that. I can't test on 64bit so I don't know if I'll be able to fix it. Funny you should mention this now as just last night I learned how to go about debugging a release build (I thought it wasn't possible) so I'll have another look as soon as possible. In the meantime, I'd try reverting to the last build that BTD made (http://sourceforge.net/projects/btdsys/ ... p/download) to see if that works.
the assignment screens of PeerLFO or PeerENV are working correctly ... where is the difference to these machines ?
BTD made them and he understood what he was doing .:lol:
User avatar
thOke
Posts: 343
Joined: Thu Nov 24, 2011 7:14 am

Re: Release build crashes Buzz but Debug build doesn't.

Post by thOke »

IXix wrote: Sorry about that. I can't test on 64bit so I don't know if I'll be able to fix it. Funny you should mention this now as just last night I learned how to go about debugging a release build (I thought it wasn't possible) so I'll have another look as soon as possible. In the meantime, I'd try reverting to the last build that BTD made (http://sourceforge.net/projects/btdsys/ ... p/download) to see if that works.
Aye, yes ... this version runs fine, i think. I thought the 'release version' was the latest from BTD. :oops:
IXix wrote:
the assignment screens of PeerLFO or PeerENV are working correctly ... where is the difference to these machines ?
BTD made them and he understood what he was doing .:lol:
:lol: , but your on the right track :!: I also have your versions of PeerLFO and PeerScale and those
assignment screens do not crash ! Thanks for reminding me of the old versions though. ;)
User avatar
IXix
Posts: 1113
Joined: Wed Nov 23, 2011 3:24 pm

Re: Release build crashes Buzz but Debug build doesn't.

Post by IXix »

Still can't figure out why this is crashing. It fails in a Microsoft dll and doesn't give me any clue as to why. I'll keep trying but I'm not very optimistic.

It would probably be quicker and easier to just scrap all the MFC code and rewrite the dialogs, either in a Win32 framework that I can understand or in C# and WPF. The only thing stopping me is I don't know how to integrate envelope.ocx into a dialog or how to make an envelope editing control in WPF and the main thing stopping me from figuring that out is lack of time.
oskari
Site Admin
Posts: 296
Joined: Mon Nov 21, 2011 2:04 pm

Re: Release build crashes Buzz but Debug build doesn't.

Post by oskari »

IXix wrote:Still can't figure out why this is crashing. It fails in a Microsoft dll and doesn't give me any clue as to why. I'll keep trying but I'm not very optimistic.

It would probably be quicker and easier to just scrap all the MFC code and rewrite the dialogs, either in a Win32 framework that I can understand or in C# and WPF. The only thing stopping me is I don't know how to integrate envelope.ocx into a dialog or how to make an envelope editing control in WPF and the main thing stopping me from figuring that out is lack of time.
http://svn.jeskola.net/buzzgui/BuzzGUI.EnvelopeControl/
User avatar
IXix
Posts: 1113
Joined: Wed Nov 23, 2011 3:24 pm

Re: Release build crashes Buzz but Debug build doesn't.

Post by IXix »

How would I add that to a machine GUI? Can I just define an element in my GUI xaml as being a "BuzzGUI.EnvelopeControl"?

When I try to look at EnvelopeControl.xaml the design view says "'EnvelopeControl' TargetType does not match type of element 'UserControl'." and marks this code as bad...

Code: Select all

  <UserControl.Style>
    <Style TargetType="{x:Type l:EnvelopeControl}">
      <Style.Triggers>
        <Trigger Property="IsEnabled" Value="False">
          <Setter Property="Opacity" Value="0.25"/>
        </Trigger>
        <Trigger Property="Envelope" Value="{x:Null}">
          <Setter Property="IsEnabled" Value="False"/>
        </Trigger>
        <DataTrigger Binding="{Binding Envelope.IsEnabled}" Value="False">
          <Setter Property="IsEnabled" Value="False"/>
        </DataTrigger>
      </Style.Triggers>
    </Style>
  </UserControl.Style>
Is that normal? You've probably guessed by now that my C#/WPF skills haven't much improved yet. :)
oskari
Site Admin
Posts: 296
Joined: Mon Nov 21, 2011 2:04 pm

Re: Release build crashes Buzz but Debug build doesn't.

Post by oskari »

IXix wrote:
How would I add that to a machine GUI? Can I just define an element in my GUI xaml as being a "BuzzGUI.EnvelopeControl"?
You don't even have to build it yourself, just add a reference to the dll.

Then implement http://svn.jeskola.net/buzzgui/BuzzGUI. ... nvelope.cs and set the Envelope property of the control to an instance of it.
oskari
Site Admin
Posts: 296
Joined: Mon Nov 21, 2011 2:04 pm

Re: Release build crashes Buzz but Debug build doesn't.

Post by oskari »

Here's an example:

Code: Select all

	public partial class MainWindow : Window
	{
		class Envelope : IEnvelope
		{
			List<Tuple<int, int>> points = new List<Tuple<int, int>>();

			public Envelope()
			{
				IsEnabled = true;
				SustainPoint = -1;

				points.Add(Tuple.Create(0, 0));
				points.Add(Tuple.Create(65536, 65536));
			}

			public bool IsEnabled { get; set; }
			public int PlayPosition	{ get { return -1; } }
			public ReadOnlyCollection<Tuple<int, int>> Points {	get { return points.AsReadOnly(); }	}
			public int SustainPoint { get; private set; }

			public void Update(IEnumerable<Tuple<int, int>> points, int sustainpoint)
			{
				this.points = points.ToList();
				SustainPoint = sustainpoint;
			}

			public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
		}


		public MainWindow()
		{
			InitializeComponent();

			envControl.Envelope = new Envelope();
		}
	}

Code: Select all

<Window x:Class="EnvExample.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
				xmlns:env="clr-namespace:BuzzGUI.EnvelopeControl;assembly=BuzzGUI.EnvelopeControl"
        Title="MainWindow" Height="350" Width="525">
	<Grid>
		<env:EnvelopeControl Name="envControl"/>		      
	</Grid>
</Window>
User avatar
IXix
Posts: 1113
Joined: Wed Nov 23, 2011 3:24 pm

Re: Release build crashes Buzz but Debug build doesn't.

Post by IXix »

Thanks! I'm still getting my head round this stuff so simple examples are much appreciated.

I still wish I could find out why this stupid dialog crashes though! :x
User avatar
IXix
Posts: 1113
Joined: Wed Nov 23, 2011 3:24 pm

Re: Release build crashes Buzz but Debug build doesn't.

Post by IXix »

I'm still trying to get the PeerADSR dialogs to behave properly as I (and others no doubt) need this machine to work for existing tracks.

I've discovered that the problem is not specific to this machine as I made a skeleton machine that does nothing except open a simple MFC dialog (with just the default OK and Cancel buttons) and it has the same problem. Interestingly, if I set the project to use unicode character set, the dialog works just fine. The same is true of the PeerADSR dialogs (I have to define out lots of code that won't compile as unicode but the dialogs open okay). I suppose it may be possible to fix the machine so it will work with unicode but I'd rather get to the bottom of the problem if possible.

My PeerADSR build used to work fine, so I'm wondering could it be possible that something that was changed in Buzz could be contributing to the problem.

Any help would be much appreciated. I'm really struggling here. :(
User avatar
IXix
Posts: 1113
Joined: Wed Nov 23, 2011 3:24 pm

Re: Release build crashes Buzz but Debug build doesn't.

Post by IXix »

FWIW here's my MFC test machine (generator), built as unicode and non-unicode versions. Right-click the machine and select "Test" to open the dialog. The non-unicode version kills Buzz instantly.
Attachments
MFC Test Machine.zip
Test generator hosting MFC dialog box
(16.43 KiB) Downloaded 309 times
oskari
Site Admin
Posts: 296
Joined: Mon Nov 21, 2011 2:04 pm

Re: Release build crashes Buzz but Debug build doesn't.

Post by oskari »

Upload the source code too so I can try to make it work.
User avatar
IXix
Posts: 1113
Joined: Wed Nov 23, 2011 3:24 pm

Re: Release build crashes Buzz but Debug build doesn't.

Post by IXix »

oskari wrote:Upload the source code too so I can try to make it work.
Thanks for looking! I made two release configurations, one unicode, one not. All you need to do is switch config and the dll name and unicode settings will be set appropriately.

I hope you can figure out what's going wrong.
Attachments
MFC Test.zip
VS2010 Solution
(33.24 KiB) Downloaded 298 times
oskari
Site Admin
Posts: 296
Joined: Mon Nov 21, 2011 2:04 pm

Re: Release build crashes Buzz but Debug build doesn't.

Post by oskari »

It works if you switch to static linking (I think this is how I fixed it too):

General->Use MFC in a Static Library
Code Generation->Multi-threaded (/MT)
User avatar
IXix
Posts: 1113
Joined: Wed Nov 23, 2011 3:24 pm

Re: Release build crashes Buzz but Debug build doesn't.

Post by IXix »

oskari wrote:It works if you switch to static linking (I think this is how I fixed it too):

General->Use MFC in a Static Library
Code Generation->Multi-threaded (/MT)
Great, that fixes PeerADSR! Thanks Oskari! It adds around 1.5MB to the size of the dll but I guess that's okay if means it works.

One thing I don't understand, why "Multi-threaded" instead of "Multi-threaded DLL"?
oskari
Site Admin
Posts: 296
Joined: Mon Nov 21, 2011 2:04 pm

Re: Release build crashes Buzz but Debug build doesn't.

Post by oskari »

Multi-threaded is the statically linked (.lib) CRT library.
Post Reply