Comments (6)
Are you using Threads or Tasks?
from monogame.
I use Tasks to load SFX and Music. I don't think I'm using it anywhere to play anything though.
I wrote some code that hooks into the BufferNeeded event from DynamicSoundEffectInstance in order to have more control over looping and stuff. See my gist below if that provides more context:
https://gist.github.com/ZachIsAGardner/87d34f881dcb60c917e298657e2dfb32
from monogame.
Also, I forked MonoGame and made my own fix(???) to DynamicSoundEffectInstance.OpenAL.cs.
I just wrapped everything in a try/catch and when an error is thrown it calls PlatformStop. I don't know what I'm doing, but I figured it might fix it for now.
private void PlatformUpdateQueue()
{
try
{
// Get the completed buffers
AL.GetError();
int numBuffers;
AL.GetSource(SourceId, ALGetSourcei.BuffersProcessed, out numBuffers);
ALHelper.CheckError("Failed to get processed buffer count.");
// Unqueue them
if (numBuffers > 0)
{
AL.SourceUnqueueBuffers(SourceId, numBuffers);
ALHelper.CheckError("Failed to unqueue buffers.");
for (int i = 0; i < numBuffers; i++)
{
var buffer = _queuedBuffers.Dequeue();
buffer.Dispose();
}
}
// Raise the event for each removed buffer, if needed
for (int i = 0; i < numBuffers; i++)
CheckBufferCount();
}
catch(Exception error)
{
PlatformStop();
}
}
from monogame.
Whenever Thread/Task and events are involved with sounds, it makes things hard to know if it's an actual bug or code sync'ing issues in developers' code.
A quick look at your gist makes me thinking that you're loading all sounds each in their own thread at the same time, which might explain the problem.
On a general note, anything involving sound doesn't like at all if multiple sound operations happen at the same time. It's fine to use threads, but it is up to the developer to make sure that no sound operation happen at the same time, loading included.
Regarding your changes in DynamicSoundEffectInstance
, this will hide the problem but not fix it. It'd be best to figure out the source problem, and MonoGame shouldn't silence errors.
from monogame.
You're correct, I am loading my 200+ sound effects into memory with one Task each at boot. I'm also loading music similarly, the difference being it only loads the required songs for a level when starting it. It sounds like I shouldn't be though? I've never had a problem with this in the past year it has been this way.
So instead of having one Task per sound effect/song, I could maybe have one Task that loads the requested assets one after the other?
My "fix" of course is not suggested, that part of dev is a little out of my depth and I was just trying to ensure my game wouldn't crash randomly eheh...
from monogame.
So instead of having one Task per sound effect/song, I could maybe have one Task that loads the requested assets one after the other?
That's more advisable, yes. Otherwise there's a probable risk of having OpenAL mixing up buffers internally, which may cascade on other things.
I don't know if in this present instance it is what cascades into breaking DynamicSoundEffectInstance
, though.
Your "fix" is likely just postponing an error. I believe that you'll run into other issues later on if you use it. Though fine enough as a local temp patch.
from monogame.
Related Issues (20)
- TestFailure: TestMergePositionsMultipleGeometries - Index was outside the bounds of the array. HOT 1
- MGCB editor fails with a parsing error in latest "develop" HOT 5
- Feature Request: Resolve Missing XML For Public Type Warnings HOT 4
- unmanaged callers only HOT 4
- Project Template Type Table Documentation URLs need to be updated HOT 2
- [PAID BOUNTY] [LOCKED] Switch the console runtime from BRUTE to NativeAOT HOT 4
- [PAID BOUNTY] [LOCKED] Implement the Direct3D 12 / GDK/GDKX backend HOT 1
- NoSuitableGraphicsDeviceException on Virtual Machine HOT 2
- PathHelper.GetRelativePath potential bugs HOT 2
- Issue with GetData/SetData as of 2024 HOT 2
- `DrawableGameComponent.Initialize` Does Not Behave How XNA Documentation Describe It HOT 1
- [PAID BOUNTY] [LOCKED] Package up ffmpeg and ffprobe HOT 10
- [PAID BOUNTY][LOCKED] A shared base for public and console repos
- AL lib throws unclosed device warning on proper game exit HOT 4
- Variable rate shading HOT 2
- [Urgent security issue] FreeImage arbitrary code execution vulnerability HOT 2
- tu-clausthal link does not exists HOT 2
- Getting started page is not working HOT 2
- SpriteBatch With Custom Effects and Per-Sprite Data HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from monogame.