This project is read-only.

Reload scene

May 28, 2013 at 2:49 PM
Is it possible to get a answer to my question regarding :

How to reload/reset a active scene.
How to switch between 2 scenes

both using the button input of the neoforce UI

Thank you very much and regards

Emile
May 28, 2013 at 4:11 PM
You can remove the active scene from the screenmanager and add the new one (new instance of the same scene) to it.

Thiago Dias Pastor


May 29, 2013 at 5:15 PM
The issue is that it needs to be done in the active scene. It causes an error in the update function call afterwards with this error "Object reference not set to an instance of an object.".
May 29, 2013 at 9:23 PM
strange,

i think i did not understand what you want.

if you want to reload the scene, just remove it from the scene manager and add a NEW instance of it to the scene manager.

if you still getting errors, send me an email ([email removed]) with the relevant code then i will be able to simulate the problem.

Att,
Thiago Dias

Thiago Dias Pastor


May 30, 2013 at 12:46 PM
Edited May 30, 2013 at 4:40 PM
Greetings,

i'm the fellow coder of EmileS that's encountering the issue. I shall try my best to explain the problem.

We have 2 scenes (main menu and game). Because of a recquirement everything has to be controlled by using a xbox360 controller, so we use the supplied neoforce GUI

The engine loads the main menu as starting screen, and when pressing the button play we fire this line
    {

        if (this.ScreenState == PloobsEngine.SceneControl.ScreenState.Active)
        {
            this.ScreenState = ScreenState.Inactive; 
        }
        IScreen temp = new TemplateDeferredScreen();
        ScreenManager.AddScreen(temp);
        ScreenManager.RemoveScreen(this);
    }
This is an event that fires when pressing the play button.

This results in the following error

"Object reference not set to an instance of an object."

in the update of the main menu on base.Update(gameTime);


Kind Regards,
May 30, 2013 at 12:49 PM
Edited May 30, 2013 at 1:38 PM
nothing
May 30, 2013 at 10:25 PM
try this and tell me what happens :
{
        IScene temp = new TemplateDeferredScreen();

              ScreenManager.RemoveScreen(this);
        ScreenManager.AddScreen(temp);

    }

I cant look at the engine code right now, i will try your code asap.


Att,
Thiago Dias


Thiago Dias Pastor


May 30, 2013 at 10:33 PM
Thanks for the reply.

I've updated the code and still get the same error.

"Object reference not set to an instance of an object."

on base.Update(gameTime) in the scene I called ScreenManager.RemoveScreen(this) on
May 31, 2013 at 12:26 AM
hi

i tried this :

{
SimpleConcreteKeyboardInputPlayable sc = new SimpleConcreteKeyboardInputPlayable(StateKey.PRESS, Keys.Space);
sc.KeyStateChange += new KeyStateChange(sc_KeyStateChange);
this.BindInput(sc);
}

...

void sc_KeyStateChange(InputPlayableKeyBoard ipk)
{
{

if (this.ScreenState == PloobsEngine.SceneControl.ScreenState.Active)
{
this.ScreenState = ScreenState.Inactive;
}

ScreenManager.RemoveScreen(this);

IScene temp = new Physx28TriggerScreen2();
ScreenManager.AddScreen(temp);
}
}

and everything worked just fine.

can you please provide me a small sample showing the problem. ([email removed])

Att,
Thiago Dias


Thiago Dias Pastor


May 31, 2013 at 12:09 PM
Edited May 31, 2013 at 12:17 PM
Hello and thanks for the reply,

Think the issue is part of us being unable to use the keyboard input, as the requirements are xbox360 controller instead of mouse/keyboard.

I'm trying to replicate the issue on a small scale now.

I will upload a link to the 2 scenes their source file and the EngineSetup.cs file. If this is not sufficient, i can also give a public link to the project (though it's about 200-300 MB)

//engine setup(feel stupid to explain this)
https://dl.dropboxusercontent.com/u/2388469/PloobsSample/EngineSetup.cs

//contains the Menu screen
https://dl.dropboxusercontent.com/u/2388469/PloobsSample/MenuScreen.cs

//contains the testscreen we switch to and triggers the error
https://dl.dropboxusercontent.com/u/2388469/PloobsSample/TestScreen.cs
May 31, 2013 at 2:56 PM
ok, iam waiting

Thiago Dias Pastor


May 31, 2013 at 3:39 PM
Hello,

I'm uploading a stripped version of the entire project that just demonstrates the issue.

(it's a dropbox public link)

https://dl.dropboxusercontent.com/u/2388469/StrippedVersionProject.rar

Hope this makes thing clearer. And thanks for spending time on this issue

Kind Regards,
May 31, 2013 at 7:11 PM
hi,

this problem happens because you are removing a screen inside of an update event (the neoforce generates the event inside the scene update).
I will fix this problem in the next version of the engine.

By now,
YOu can fix this using:

void click_StartGame(object sender, TomShane.Neoforce.Controls.EventArgs e)
{
//m_MainMenu.Close();

PloobsDispatcher.Dispatch(
new Action(() =>
{
if (this.ScreenState == PloobsEngine.SceneControl.ScreenState.Active)
{
this.ScreenState = ScreenState.Inactive;
}
IScene temp = new TestScreen();
ScreenManager.RemoveScreen(this);
ScreenManager.AddScreen(temp);
})
);
}

The PloobsDispatcher just executes the action inside of it when it is safe (outside of scene updates and in a single thread).

Att,
THiago DIas


Thiago Dias Pastor


May 31, 2013 at 8:30 PM
Edited May 31, 2013 at 9:49 PM
Hi,

Thanks alot for the swift reply.
It indeed solved that error, but at the same time it made us encounter a new one.

"Failed to compare two elements in the array." on the draw of the newly created scene.

This issue only happens in a scene where models have been added.

Kind Regards,


EDIT:

Found the error. It was due to the way my fellow coder implemented the loading of the models that we had a concurrency issue.

Again thanks alot for the help with the error. Really enjoying working with ploobs, though it's a crash course for coding in C# with only 4 months to learn the language/engine and create a game in it. Very pleased with what is possible and build in
May 31, 2013 at 10:37 PM
again, same problem ... (sorry)

i added the same a model to the sample you send to me (TestScreen) and i got no error even after loading a model inside the screen.

please, send me a demo (dont need to put all the assets, bin , obj folder, just the code =P)

Thanks

Thiago Dias Pastor


Jun 1, 2013 at 1:49 AM
Hello,

thanks for the reply again.

At the moment we use a temporary fix, by skipping the first tick of the scene (quick and dirty).

This contains the cleaned up version of the project, only the code still in it.

https://dl.dropboxusercontent.com/u/2388469/StrippedVersion.rar

Kind Regards,
Jun 1, 2013 at 6:36 PM
i found the problem.
your camera is returning Not a number in the position in the first frame.

in the templatedeferredscreen

check this:

protected override void Draw(GameTime gameTime, RenderHelper render)
{
render.Clear(Color.Black);
{

Vector3 pos = World.CameraManager.ActiveCamera.Position ;
Matrix m = World.CameraManager.ActiveCamera.View;
Matrix k = World.CameraManager.ActiveCamera.Projection;
....

}

pos, m and k will have "Not a number" inside of it.
This is causing your problem.

probably in the first update call to your camera, you are generating "not a number" (http://www.blackwasp.co.uk/CSharpNaN.aspx) values


Thiago Dias Pastor


Jun 1, 2013 at 10:20 PM
Hello,

I see. Will need to redo that piece of code then

Thanks alot for taking your time with this. Much appreciated