ms_singleton error

kinggori

11-03-2007 22:25:40

Hi guys

I've been trying to attach sounds to objects fpr days now. I didn't want to be a pain in the ass as usual so I didn't post asking for help but I just tried everything and can't seem to get rid of runtime errors.

The game runs perfectly fine and background music is running perfectly. But when I add the three lines:



OgreAL::SoundManager *soundManager;
soundManager = new OgreAL::SoundManager();
mSceneNode->attachObject(soundManager->getListener());


in




namespace CAXCore {

// OgreAL::SoundManager *soundManager;

// initialise the static value
int CAXWorldObject::sNumObjects = 0;

CAXWorldObject::CAXWorldObject ( string meshName,
SceneManager* scnMgr,
const Vector3& initPos,
const float scale,
const float rotate)
{



// entities are automatically named
char bufstr[64];
sprintf ( bufstr, "cax_object_ent_%d", sNumObjects );
mEntity = scnMgr->createEntity ( bufstr, meshName.c_str() );
mEntity->setCastShadows(true);
mSceneManager = scnMgr;
// scene nodes are automatically named
sprintf ( bufstr, "cax_object_node_%d", sNumObjects++ );
mSceneNode = scnMgr->getRootSceneNode()->createChildSceneNode(bufstr, initPos);
mSceneNode->scale ( scale, scale, scale );
mSceneNode->yaw( (Ogre::Radian)rotate);

// To get things right
mSceneNode->attachObject(mEntity);


OgreAL::SoundManager *soundManager;
soundManager = new OgreAL::SoundManager();
mSceneNode->attachObject(soundManager->getListener());


}

void CAXWorldObject::setMesh( string meshName )
{
string name = mEntity->getName();
mSceneNode->detachObject( mEntity );
mSceneManager->destroyEntity( mEntity );

mEntity = mSceneManager->createEntity ( name.c_str(), meshName.c_str() );
mEntity->setCastShadows(true);
mSceneNode->attachObject(mEntity);
}



.................




I get the error:

Assertion failed!

Program c:\mydev\LIAV\bin\Release\LIAV_864.exe
File c:\mydev\ogrenew\include\OgreSingleton.h
Line: 59

Expression: !ms_Singleton

For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts

daedar

11-03-2007 22:34:04

Just a stupid question but... is your SoundManager initialized elsewhere? If so you should try SoundManager::getSingleton() instead.
Then, do you use the SVN-Head version? I had the same problem with the non-SVN version but now it seems to run quite well.
Finally, isn't it a problem of debug/release mode? Are you sure you're using the dll coresponding to the right configuration?

kinggori

11-03-2007 22:46:12

Just a stupid question but... is your SoundManager initialized elsewhere? If so you should try SoundManager::getSingleton() instead.
Then, do you use the SVN-Head version? I had the same problem with the non-SVN version but now it seems to run quite well.
Finally, isn't it a problem of debug/release mode? Are you sure you're using the dll coresponding to the right configuration?


thanks for your fast reply daedar :D :D

i was stupid enough to have SoundManager initialized elsewhere

but now when I change

OgreAL::SoundManager *soundManager;
soundManager = new OgreAL::SoundManager();
mSceneNode->attachObject(soundManager->getListener());


to

OgreAL::SoundManager::getSingleton();
soundManager = new OgreAL::SoundManager();
mSceneNode->attachObject(soundManager->getListener());


i get the error

Error 1 error C2065: 'soundManager' : undeclared identifier c:\mydev\LIAV\src\CAXWorldObject.cpp 48


any idea what i need to do here?

kinggori

11-03-2007 22:55:28

i figured out how:

OgreAL::SoundManager *soundManager;
soundManager = OgreAL::SoundManager::getSingletonPtr();
mSceneNode->attachObject(soundManager->getListener());



now I'm getting a new error... but atleast I'm 1 step closer to getting this baby running :D

CaseyB

12-03-2007 00:01:05

What's the new error? You are creating the SoundManager elsewhere, so getting the singleton is valid, right? If you are not creating the SoundManager elsewhere, getSingletonPtr() will not throw the ms_singleton assertion, it will just return a null pointer.

kinggori

12-03-2007 00:28:56

now I'm not getting anymore errors but...

I attached sound to my villager but I can hear the sound everywhere even if I move away from the villager :roll:

I'm pretty sure the sound is attached to the villager only. Here are the code parts that might be relevant (I will not paste full code, but only parts that are relevant):




CAXWorldObject.cpp
Responsible for creating any new object. As you can see i check if the mesh is that of the villager and if it is I attach the sound


...................

CAXWorldObject::CAXWorldObject (
string meshName,
SceneManager* scnMgr,
const Vector3& initPos,
const float scale,
const float rotate)
{

// entities are automatically named
char bufstr[64];
sprintf ( bufstr, "cax_object_ent_%d", sNumObjects );
mEntity = scnMgr->createEntity ( bufstr, meshName.c_str() );
mEntity->setCastShadows(true);
mSceneManager = scnMgr;

// scene nodes are automatically named
sprintf ( bufstr, "cax_object_node_%d", sNumObjects++ );
mSceneNode = scnMgr->getRootSceneNode()->createChildSceneNode(bufstr, initPos);
mSceneNode->scale ( scale, scale, scale );
mSceneNode->yaw( (Ogre::Radian)rotate);

// To get things right
mSceneNode->attachObject(mEntity);

if( soundCountt==0)
{
if( meshName == "femvillager.mesh")
{
OgreAL::SoundManager *soundManager;
soundManager = OgreAL::SoundManager::getSingletonPtr();
OgreAL::Sound *sound = soundManager->createSound("BusS", "motor_b8.wav", true);
mSceneNode->attachObject(sound);
sound->play();
soundCountt = 1;
}
}

..............

CaseyB

12-03-2007 02:21:33

Yup, the sound is attached to the same node as the entity, but where is the listener? If you don't attach the listener to something it will just sit at 0,0,0 and if this happens to be where your villager is then the sound will never get farther away. The best thing would be to attach the listener to the same node that the camera is attached to.

kinggori

12-03-2007 03:48:13

got it working thanks :D :D :D :D
I actually attached it to the character the player controls :idea:

- Now I have background music and object sounds; is there a way of controlling their volumes or the range of the sound?


- I also have another important question... we recorded voices for the different villagers. Each villager has about 10 wav files dedicated to them andi want the villager to say one wav file after the other and then restart... is there a way of doing that?

CaseyB

12-03-2007 04:50:58

is there a way of controlling their volumes or the range of the sound?Yup, use Sound::setGain() to adjust the volume of the sounds, or Listener::setGain() to adjust the overall volume.


i want the villager to say one wav file after the other and then restart... is there a way of doing that?You can test to see if the first sound has finished by seeing if it isStopped() and then when that returns true play the second one.