473,320 Members | 1,933 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

SndPlaySound causing crashes

Nak
Hi there,

*fingers crossed that the newsserver works long enough for me to see any
replies to this!!*

I'm having crashes when using SndPlaySound with SND_ASYNC and SND_MEMORY
in VB.NET. The sounds are being loaded from embedded resources and stored
into byte arrays, which are then being stored in a hashtable for easy
retrieval second time around. Occasionally a get a funny "beep" sound and
the application crashes, the report tells me that it comes from "winmm.dll".
The only reference I could find to this crash was

http://ftp.tuniv.szczecin.pl/pub/win...P/w32s125a.txt

But that is in reference to "MICROSOFT WIN32S UPGRADE". Any ideas on
this one? I've just made my first ever game and the sounds keep making it
crash :-(

Nick.

--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
"No matter. Whatever the outcome, you are changed."

Fergus - September 5th 2003
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Nov 20 '05 #1
19 2082
"Nak" <a@a.com> scripsit:
I'm having crashes when using SndPlaySound with SND_ASYNC and SND_MEMORY
in VB.NET. The sounds are being loaded from embedded resources and stored
into byte arrays, which are then being stored in a hashtable for easy
retrieval second time around. Occasionally a get a funny "beep" sound and
the application crashes, the report tells me that it comes from "winmm.dll".
The only reference I could find to this crash was


Does this sample work for you?

<http://www.google.de/groups?selm=exQuKMjfDHA.1712%40TK2MSFTNGP11.phx.gb l>

Notice that 'sndPlaySound' should not be used any more, it's only
available for compatibility with old applications.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #2

It sounds like this could be caused by the GC moving the byte array in
memory, and thereby invalidating the pointer you've passed to
sndPlaySound. But I can't say for sure without seeing your code.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Nov 20 '05 #3
Nak
Hi Herfried,
Does this sample work for you?
Excellent, thank you, it works a treat, even with my caching method. The
one I was using previously wasn't passing a pointer, but a whole byte array,
maybe that is why it was failing so easily?
Notice that 'sndPlaySound' should not be used any more, it's only
available for compatibility with old applications.


What would you recommend using? I didn't want to use DirectX for a reason,
even though I have already developed similar classes with increased
functionality, my game is "bog standard", so I have done it the "bog
standard" way :-)

Nick.

--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
"No matter. Whatever the outcome, you are changed."

Fergus - September 5th 2003
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Nov 20 '05 #4
Hi Nick,
What would you recommend using?


I believe that Herfried was refering to PlaySound. Please read the
following in MSDN documentation:

"This function (sndPlaySound) offers a subset of the functionality of the
PlaySound function; sndPlaySound is being maintained for backward
compatibility."

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 20 '05 #5
"Flying Frank" <fi****@post.com> scripsit:
ps. Here's a picture of me in my Harry Enfield jacket. What do you think - do
I look like some Dork?


ROFL

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #6
Nak
> "This function (sndPlaySound) offers a subset of the functionality of the
PlaySound function; sndPlaySound is being maintained for backward
compatibility."


Aaah, thanks :-)

Nick.

--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
"No matter. Whatever the outcome, you are changed."

Fergus - September 5th 2003
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Nov 20 '05 #7
Nak
Hi there,
Just a guess, but SndPlaySound is a WinApi call and the source of the
sound is a .NET HashTable. If you're giving a pointer to .NET memory to an
asynchronous Win32 function, it's highly possible that your HashTable contents have been shuffled around, perhaps by a garbage collection, and all of a
sudden SndPlaySound is grabbing at thin air. If so, I guess you could do a
GlobalAlloc and copy the sound wave into it for the duration of the playing.

The data for the sound *was/is* being stored in a Hashtable, retrieved into
a byte array and they byte array was being passed to the function. Surely
the garbage collector shouldn't change the address of something that is in
use? It's quite strange, the CLR seems to randomly choose what objects it
reclaims when they fall out of scope, I had a http downloading class
(Microsoft have a very similar example) which has objects that fall out of
scope but never get collected, that was the downside to it because you never
had a solid reference to the object.
ps. Here's a picture of me in my Harry Enfield jacket. What do you think - do I look like some Dork?


Not really, that happens to be one of my best friends!

Nick.

--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
"No matter. Whatever the outcome, you are changed."

Fergus - September 5th 2003
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Nov 20 '05 #8
Nak
Hi Fergus,
Just a guess, but SndPlaySound is a WinApi call and the source of the
sound is a .NET HashTable. If you're giving a pointer to .NET memory to an
asynchronous Win32 function, it's highly possible that your HashTable contents have been shuffled around, perhaps by a garbage collection, and all of a
sudden SndPlaySound is grabbing at thin air. If so, I guess you could do a
GlobalAlloc and copy the sound wave into it for the duration of the

playing.

A man of many many guises!

Nick.

--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
"No matter. Whatever the outcome, you are changed."

Fergus - September 5th 2003
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Nov 20 '05 #9
Hi Nick,

LOL - you saw through it. ;-)) What gave the game away, I wonder.

|| that happens to be one of my best friends!

Lol, again. And he's achieved fame and notoriety as the man with the funny
jaw, the wobbly head and the belch!! No, he's not a dork, but he does remind
me of Harry Enfield (only in the less close-up pictures).

A good bit of fun is FFC. I had a liitle play with it. (And it's why I
knew you'd be able to answer that sprite question - shame that guy never came
back),

ps. I've missed you, you've only been dropping in for seconds at a time.
But I'm glad that it's because you're getting into your Game Prog. More power
to your elbow. :-)

Regards,
Fergus
Nov 20 '05 #10
Surely
the garbage collector shouldn't change the address of something that is in
use?
It sure can do that, when "compacting" the memory after having cleaned
up other objects.

And there's no way for the runtime to know that the byte array is "in
use" by the unmanaged API function. The runtime can only track uses in
managed code.

It's quite strange, the CLR seems to randomly choose what objects it
reclaims when they fall out of scope, I had a http downloading class
(Microsoft have a very similar example) which has objects that fall out of
scope but never get collected, that was the downside to it because you never
had a solid reference to the object.


How do you know they weren't collected?

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Nov 20 '05 #11
Nak
Hi Fergus,
LOL - you saw through it. ;-)) What gave the game away, I wonder.
;-) Where there is a will, there is a way!
Lol, again. And he's achieved fame and notoriety as the man with the funny jaw, the wobbly head and the belch!! No, he's not a dork, but he does remind me of Harry Enfield (only in the less close-up pictures).
Yeah I know you were only joking, but I thought you *may* have been someone
else, so I was proceeding with caution, if you know what I mean :-)
A good bit of fun is FFC. I had a liitle play with it. (And it's why I
knew you'd be able to answer that sprite question - shame that guy never came back),
Yeah, my next one's going to be a damn site better, hopefully anyway. Glad
you like it :-)
ps. I've missed you, you've only been dropping in for seconds at a time. But I'm glad that it's because you're getting into your Game Prog. More power to your elbow. :-)


Yeah, I don't seem to be able to use the newsgroups very well lately, OE it
seems to refuse to pick up headers and the most inconvenient parts of the
day. I've just started doing a bit of game programming just for the
experience, I read an article somewhere that said start with a Tetris clone,
damn, I didn't think it would be that hard! but it works now anyway, I'm
gonna stick it on my web sit soon providing I don't get sued!

Nick.

--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
"No matter. Whatever the outcome, you are changed."

Fergus - September 5th 2003
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Nov 20 '05 #12
Nak
Hi there,
It sure can do that, when "compacting" the memory after having cleaned
up other objects. And there's no way for the runtime to know that the byte array is "in
use" by the unmanaged API function. The runtime can only track uses in
managed code.
Aah, that makes sence, but if I still have a solid reference to the data
that is being garbage collected, that should be detected as being in use.
Data being stored in a hash table is surely a solid reference, why would
their addresses change?
How do you know they weren't collected?


Because the application still functions and a callback occurs. Also when
terminating the class it becomes a nightmare because you have no references
to dispose of, they just seem to float around. I replaced it in the end for
a class that simply runs synchronously in another thread to prevent the main
thread from becoming blocked, far more reliable than the previous method.

Nick.

--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
"No matter. Whatever the outcome, you are changed."

Fergus - September 5th 2003
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Nov 20 '05 #13
Hi Nick,

The whole point about managed memory is that the GC knows where everything
is, who talks to who and how's your father. Thus, when the GC stops the music,
every object freezes and waits for the music to start again. During that
period, the GC can shift objects about devil-may-care. And because the GC <is>
that devil, and takes that care, it always fixes up the objects' pointers
accordingly. So when the GC says "off you go then children", some will have
moved but they'll never know it.

Not the case for uny one in unmanged territory - their pointers into te
managed memory space can go invalid at a moment's notice.

There is a way round all this. In C# you can have memory that is 'pinned'
in place - such that the GC is not allowed to touch it. In C# the keyword is
'fixed' but I don't think it's possible to do pinning in VB. You could have a
C# Project in your solution which can deal with the sounds. (Good excuse to
get your toes wet in C#, too).

Regards,
Fergus
Nov 20 '05 #14
Hi Nick,

|| I thought you *may* have been someone else, so I was
|| proceeding with caution, if you know what I mean :-)

In a way it would have been good if it had been him - so that he could
read what you said about him - if he's the one I think you're talking about!!

|| Tetris

I like Tetris - I'll alpha/beta test if you like.

Regards,
Fergus

Nov 20 '05 #15
Nak
Hi Fergus,

WOW, OE working 2 attempts in a row!!! Is this too good to be true?
I like Tetris - I'll alpha/beta test if you like.


I'm gonna start referring it to as a "falling blocks game" just so there
is no affiliation with Tetris ;-)

Nick.

--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
"No matter. Whatever the outcome, you are changed."

Fergus - September 5th 2003
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Nov 20 '05 #16
Hi Nick,

|| WOW, OE working 2 attempts in a row!!!

Yo!!

|| Is this too good to be true?

I only got one copy of the virus-spam email in the last 24 hours, and
OE/msnews has regained it's two-minute response time!! I was going to mention
it myself but I bottled out in case the Gods were watching. Well done - you've
averted the curse for me.

|| I'm gonna start referring it to as a "falling blocks game"
|| just so there is no affiliation with Tetris ;-)

The first version I ever played was a gorgeous 3-D wire-frame version.
Excellent fun. It was called 'Block'!!

Whatever you call it, I look forward to it. ;-)

Regards,
Fergus

Tetris - I never liked that name. Apparently it's derived from 'tetra' because
of the four squares that make up each piece. You could call your game
FourPlay!!

But then again, there are seven possible shapes so you could call it Septis.

But then again - Nah!!
Nov 20 '05 #17
"Fergus Cooney" <fi******@tesco.net> scripsit:
In C# you can have memory that is 'pinned'
in place - such that the GC is not allowed to touch it. In C# the keyword is
'fixed' but I don't think it's possible to do pinning in VB. You could have a
C# Project in your solution which can deal with the sounds. (Good excuse to
get your toes wet in C#, too).


Have a look at the 'GCHandle' class.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #18
Nak
Hi Fergus,
Tetris - I never liked that name. Apparently it's derived from 'tetra' because of the four squares that make up each piece. You could call your game
FourPlay!!


LOL! I was thinking if "Bastard blocks", but I decided to call it
"nikblox". I have incorporated a "Bastard blocks" feature though, which is
pretty ammusing, if your lines equal a multiple of 10 you get dished out 1
bastard block, which is a really awkwardly shaped block made out of 5 rather
than 4 blocks, I love the cat sound that it plays, MMMMMMEEEEAAWWW, someone
kick that cat!!!

Nick.

--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
"No matter. Whatever the outcome, you are changed."

Fergus - September 5th 2003
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Nov 20 '05 #19
Hi Nick,

Bastard blocks sounds like a good innovation.

If it were a dog you could have Nikblox as its day-to-day doggie
name and Nick-a-Block-a-Glory as its fancy show-time pedigree name.

Regards,
Fergus

ps. I hope the keyboard setup is editable - I like my numeric keypad, I do,
with Spacebar to drop.
Nov 20 '05 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Jamma | last post by:
Hello, I have an Access 2000 file working on XP machines and a NT network. The files are split and 95% of the time all is well and stable. The main issue arises when the app prints,a novell...
3
by: Brad | last post by:
I have an aspx web page which initially displays fine. When I postback the resulting response back to the client output is causing InternetExplorer 6 to crash. I've disabled the server side code...
9
by: Andy | last post by:
Hi, I have an application that has several forms. Each form acts as a monitor of a gateway system. If the gateway appears to be dead, the application should play a .wav file (not resource)...
23
by: Dave G | last post by:
Since upgrading one of my clients from A97/W2000 to A2003/XP they have suffered no end of data corruption problems, mainly involving one of the main tables. The corruption can result in one...
0
by: bsruth | last post by:
I am writing a .NET wrapper for an unmanaged C++ library using managed C++. I am having an issue with an ofstream object used inside of the unmanaged code. Here is the code that is giving me the...
2
by: Ansh | last post by:
i want to play a .wav file using sndPlaySound and PlaySound function but both function doesn't works in the expected way... i just hear a click sound after execution of these functions.... not the...
2
by: =?Utf-8?B?TWFuYXNoIFNhaG9v?= | last post by:
Anyone experience this? I am doing a "__doPostBack('','');" in javascript. The postback does occur on the server side as I have verified this in debug mode. However, when the response is sent...
4
by: Alistair George | last post by:
Every time I want to move a menu item (from one menu dropdown to to same menu adjacent dropdown) by Cut in Microsoft Visual Studio 2005 it immediately crashes on cut with error dialog 'an error...
2
by: Dave Johansen | last post by:
I just converted a solution from Visual Studio 2003 to Visual Studio 2005 and the Debug mode seems to be running just fine, but the Release mode crashes on the following code: std::ifstream...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.