Jump to content
  • Advertisement
Sign in to follow this  
caelk

DirectMusic problem (loading from file)

This topic is 4812 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Alright... this is gonna sound stupid, but here goes. I thought I'd play around with DirectMusic a bit, so I wrote some simple code that'd get a midi file and play it. Sounds simple enough, but whenever I hit a particular line of code, my debugger proceeds to freeze. When this happens, I usually can't even tell the debugger to stop debugging, forcing me to Ctrl-Alt-Del and forcibly terminate the program. The few times that the debugger actually stops successfully, I get something like, "First-chance exception at <hexadecimal number>, illegal access at <hexadecimal number>." (Not verbatim.) Usually there's a whole bunch of these... but, other than the first message, the numbers are 0xC0000005 and 0x00000000 respectively (I may not have remembered those numbers correctly, though). The easy question to ask is... is there anything about IDirectMusicLoader8::LoadObjectFromFile that would cause this behavior? For the record, I've tried two or three seperate midi files and they've all done the same thing. Other than that, well... the code follows; it fails on the call to IDirectMusicLoader8::LoadObjectFromFile. I'm programming with MS Visual Studio .NET 2003.
#include <windows.h>
#include <dsound.h>
#include <dmusici.h>

#define TESTFILE L"pinball.mid"

IDirectMusicPerformance8 *g_pDMPerformance;
IDirectMusicLoader8 *g_pDMLoader;
IDirectMusicSegment8 *g_pDMSegment;

...

    CoInitialize(NULL);
    CoCreateInstance(CLSID_DirectMusicPerformance, NULL, CLSCTX_INPROC, 
                     IID_IDirectMusicPerformance8, (LPVOID *) &g_pDMPerformance);
    g_pDMPerformance->InitAudio(NULL, NULL, g_hWnd, DMUS_APATH_SHARED_STEREOPLUSREVERB,
                                64, DMUS_AUDIOF_ALL, NULL);
    CHAR mbsPath[MAX_PATH];
    WCHAR wcsPath[MAX_PATH];
    GetCurrentDirectory(MAX_PATH, mbsPath);
    mbstowcs(wcsPath, mbsPath, MAX_PATH);
    CoCreateInstance(CLSID_DirectMusicLoader, NULL, CLSCTX_INPROC,
	                 IID_IDirectMusicLoader8, (LPVOID *) &g_pDMLoader);
    g_pDMLoader->SetSearchDirectory(GUID_DirectMusicAllTypes, wcsPath, FALSE);
    
    CoCreateInstance(CLSID_DirectMusicSegment, NULL, CLSCTX_INPROC,
                     IID_IDirectMusicSegment8, (LPVOID *) &g_pDMSegment);
    g_pDMLoader->LoadObjectFromFile(CLSID_DirectMusicSegment, IID_IDirectMusicSegment8,
                                    TESTFILE, (void **) &g_pDMSegment);
    g_pDMSegment->Download(g_pDMPerformance);

...

Share this post


Link to post
Share on other sites
Advertisement
You don't need to call CoCreateInstance() for IDirectMusicSegment. The segment is automatically created by IDirectMusicLoader::LoadObjectFromFile().

Try to reduce the performance channel down to 32 or 16, and check if wcsPath actually contains a valid string. Loading an empty file can cause this problem too.

Share this post


Link to post
Share on other sites
Just a follow-up in case anyone cares, or (more importantly), has the same problem. Sorry if it seems like I'm beating a dead horse, but I like things to come to conclusion. ^_^;

I did what alnite suggested, but the program still wouldn't work. I checked my local variables and they appeared to both (a) have a valid string, and (b) represent a directory and file that existed on my system. I did end up chucking the CoCreateInstance for the music segment, though.

Anyways, I did some more scrounging around, and came up with the following thread. (Unfortunately, forum search has been and is currently down at this time, so I got it off Google instead.)
http://www.gamedev.net/community/forums/topic.asp?topic_id=149440&whichpage=1󎑲

So... upon seeing that this thread was two years old, I spent the next 12+ hours downloading the latest version of the DirectX SDK (since mine was old and I'm on crappy dialup with America OnLag). Lo and behold, it works.

Lessons reiterated:
1) Critical, fatal, and obvious bugs still might make it past QA and into release.
2) All systems you will ever use will hardly be perfect. (Corollary to number 1.)
3) Always stay up to date.
4) Stupid Little Things(TM) will always bite you in the arse if you let 'em.

Time wasted figuring this out: 2 days, plus 1 day for updating the DirectX SDK. Grr. (Direct3D kept me entertained during my download, though.)

But all that aside, thank you both for your help! (^_^)v

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!