Wintermute Engine Forum

Wintermute Engine => Technical forum => Topic started by: Spellbreaker on June 23, 2011, 10:45:17 AM

Title: Plugin question
Post by: Spellbreaker on June 23, 2011, 10:45:17 AM
Hey there.

I am having a strange behavior with a plugin I created. The plugin uses serialization to store some information. When i now load a saved game, the serialize function gets called, the values gets loaded, everything fine. But after that, the plugin destructor is called. But then, the plugins methods still get called. I wonder why that happens, since in the destructor i delete some stuff the plugin needs to work properly.

Are there maybe two objects alive at the same time? I am creating the plugin object in the game.script file as a global.

Sincerly,

Spellbreaker
Title: Re: Plugin question
Post by: Mnemonic on June 23, 2011, 11:57:30 AM
Well I think it can actually happen that during load a new object is created before the old one is destroyed, that's "by design".
Title: Re: Plugin question
Post by: Spellbreaker on June 23, 2011, 03:31:57 PM
That means it's not possible to serialize Data with a Plugin? Because the object is destroyed after the data has been loaded from the savegame, which is quite senseless :) Or could the problem be, that WME destroys the new object instead of the old one? It should be possible to use the serialization from within a plugin...

cheers
Title: Re: Plugin question
Post by: Mnemonic on June 23, 2011, 03:44:48 PM
Quote
That means it's not possible to serialize Data with a Plugin? Because the object is destroyed after the data has been loaded from the savegame, which is quite senseless
Err, what? Remember that's a completely different object.
Title: Re: Plugin question
Post by: Spellbreaker on June 23, 2011, 03:52:18 PM
Okay again :)

I run my plugin using the vc debugger step by step, the following happens when loading a game :

- Constructor is called ( calling bass_init(); just for info )
- Serialize is called ( loading filenames and other stuff from the savegame, and starting playing the music fiiles, which actually works until .... )
- Destructor is called ( calling bass_free(); now the plugin does not work anymore ( because of the BASS_Free() I guess ).


greets

Title: Re: Plugin question
Post by: Mnemonic on June 23, 2011, 04:20:02 PM
Yes, but construction and deserialization is one object (the one that's being recreated from the saved game), destruction is other object (the one that existed before you decided to load a saved game).
Normally this is not a problem, but in your case you need to manage external resource (-> BASS), so for you this misorder is a problem (because the new instance creates BASS, which is immediately destroyed together with the old instance). What if you don't destroy BASS at all, and only destroy the streams? Is it legal to call BASS initialization multiple times?
Title: Re: Plugin question
Post by: Spellbreaker on June 23, 2011, 07:45:10 PM
I can call the BASS Initialization multiple times, thats not a problem (it would simply spit out an error code saying that it's already initialized, but everything would work as expected). But since I cannot call BASS_Free() when the game quits, what happens? Can it be a serious problem?
Title: Re: Plugin question
Post by: Spellbreaker on June 23, 2011, 07:55:38 PM
Ahhh couldn't I simply write a shutdown method as class member and put it into the on "QuitGame" Event in the game.script? Shouldn't that do the trick?
Title: Re: Plugin question
Post by: Mnemonic on June 23, 2011, 08:11:27 PM
Yeah, good idea. That will work.
Title: Re: Plugin question
Post by: Spellbreaker on June 23, 2011, 09:49:20 PM
Just for the records - works perfectly :)

Thanks for all the help again ;)