Here is a simplified version of my code.
This code is written to show a splash screen (press escape to leave splash), then jump to login screen (pass “admin” and “pass” as login information)
The problem is; program throws an unhandled exception when it comes to framework.do_frame() of the second screen.
The order changes nothing, it happens on 2nd screen.( splash > login or login > splash)
But if you alter code to show only one screen (i.e. splash > splash or login > login) no exception happens.
Any suggestions?
Here is the code…
#include "pandaFramework.h"
#include "pandaSystem.h"
#include "PGButton.h"
#include "MouseButton.h"
#include "PGEntry.h"
int _fLoginMain(int argc, char** argv);
int _fSplashMain(int argc, char** argv);
void main (int argc, char** argv)
{
while (1)
{
_fLoginMain(argc, argv);
_fSplashMain(argc, argv);
}
}
int _iReturnVal;
PT(PGEntry) entry1;
PT(PGEntry) entry2;
PT(TextNode) textnode;
static void _fLoginCallback(const Event *ev, void *data)
{
if ( *((char*)data) == 'l')
{
if (entry1->get_plain_text().length() < 4)
{
textnode->set_text("ERROR: \"Account Name\" must be at least 4 character");
textnode->set_text_color(1,0,0,1);
entry1->set_focus(1);
entry2->set_focus(0);
}
else if (entry2->get_plain_text().length() < 4)
{
textnode->set_text("ERROR: \"Password\" must be at least 4 character");
textnode->set_text_color(1,0,0,1);
entry1->set_focus(0);
entry2->set_focus(1);
}
else
{
textnode->set_text("Trying to login...");
textnode->set_text_color(0,1,0,1);
nout << "Attempting to connect to Server with credentials: (" << entry1->get_plain_text() << " , " << entry2->get_plain_text() << ")";
// this is where the networking code will get put in
if ((entry1->get_plain_text() == "admin") && (entry2->get_plain_text() == "pass"))
{
nout << "login screen pass LOGIN";
_iReturnVal = -2;
}
else
{
//self.updateStatus("Invalid login name or password...")
textnode->set_text("ERROR: Invalid account name or password...");
textnode->set_text_color(1,0,0,1);
entry1->set_focus(0);
entry2->set_text("");
entry2->set_focus(1);
}
}
return;
}
else // tab
{
if (entry1->get_focus() == 1)
{
entry1->set_focus(0);
entry2->set_focus(1);
}
else
{
entry1->set_focus(1);
entry2->set_focus(0);
}
}
}
//
// login screen...
// wait username and password match...
//
int _fLoginMain(int argc, char** argv)
{
_iReturnVal = 0;
PandaFramework framework;
framework.open_framework(argc, argv);
framework.set_window_title("Login");
WindowProperties props;
props.set_size(800,400);
props.set_fixed_size(1);
props.set_undecorated(1);
int flags = 0;
WindowFramework *window = framework.open_window(props, 0);
// Check whether the window is loaded correctly
if (NULL == window)
{
framework.close_framework();
return _iReturnVal;
}
entry1 = new PGEntry("login name");
entry1->setup(23,1);
entry1->set_blink_rate(2);
entry1->set_focus(1);
NodePath entry1NP = window->get_aspect_2d().attach_new_node(entry1);
entry1NP.set_scale(0.041,1,0.05);
entry1NP.set_pos(-1.18,0,0.19);
entry2 = new PGEntry("password");
entry2->setup(23,1);
entry2->set_blink_rate(2);
entry2->set_focus(0);
NodePath entry2NP = window->get_aspect_2d().attach_new_node(entry2);
entry2NP.set_scale(0.041,1,0.05);
entry2NP.set_pos(-1.18,0,-0.09);
window->enable_keyboard(); // Enable keyboard detection
framework.define_key("tab","tab",&_fLoginCallback,"t");
framework.define_key("enter","login",&_fLoginCallback,"l");
textnode = new TextNode("instructions");
textnode->set_text("Login screen dummy text");
NodePath statustext(window->get_aspect_2d().attach_new_node(textnode));
statustext.set_pos(-1.4,0,-0.8);
statustext.set_scale(0.05);
Thread *current_thread = Thread::get_current_thread();
while(framework.do_frame(current_thread))
{
if ( _iReturnVal < 0)
break;
}
// Close the framework
framework.close_framework();
return _iReturnVal;
}
static void _fEscapeCallback(const Event *ev, void *data)
{
nout << "splash screen pass QUIT ";
_iReturnVal = -1;
}
//
// splash screen...
//
int _fSplashMain(int argc, char** argv)
{
_iReturnVal = 0;
PandaFramework framework;
framework.open_framework(argc, argv);
framework.set_window_title("Splash");
WindowProperties props;
props.set_size(800,400);
props.set_fixed_size(1);
props.set_undecorated(1);
int flags = 0;
WindowFramework *window = framework.open_window(props, 0);
// Check whether the window is loaded correctly
if (NULL == window)
{
framework.close_framework();
return _iReturnVal;
}
window->enable_keyboard(); // Enable keyboard detection
framework.define_key("escape","QuitTheProgram",_fEscapeCallback,NULL);
textnode = new TextNode("instructions");
textnode->set_text("Splash screen dummy text");
NodePath statustext(window->get_aspect_2d().attach_new_node(textnode));
statustext.set_pos(-1.4,0,-0.8);
statustext.set_scale(0.05);
Thread *current_thread = Thread::get_current_thread();
while(framework.do_frame(current_thread))
{
if ( _iReturnVal < 0)
break;
}
/*
//Run it
framework.main_loop();
*/
// Close the framework
framework.close_framework();
return _iReturnVal;
}