7 posts / 0 new
Last post
Pem
Pem's picture
Offline
Joined: 17 Jan 2012
Posts:
TabScreen with GLMoblet

Hello,

My application uses the menu TabScreen.

One Tab integrate a 3D object, so I use GLMoblet.

When I Launch the application I have this error message:

"The application Tried to instantiate More Than One Environment. There Can Be Only One per application."

Thank you 

 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Sam Pickard
rival's picture
Offline
Mobile Archmage
Joined: 19 Mar 2009
Posts:

I've been racking my brains since you posted this. I remember getting it, but only on Android. I remember having to step through all of the moblet and environment code which was where the error was occuring, but it wasn't the cause of the error. I remember that it took me about 2 days to work out what the problem was, but I still can't remember how I fixed it! I'll keep on it.

Pem
Pem's picture
Offline
Joined: 17 Jan 2012
Posts:

main.cpp

#include <ma.h>
#include <mavsprintf.h>
#include <MAUtil/Moblet.h>
#include <NativeUI/Widgets.h>
#include <NativeUI/WidgetUtil.h>

#include "ScreenMain.h"	

using namespace NativeUI;

class NativeUIMoblet : public MAUtil::Moblet
{
public:
	NativeUIMoblet()
	{
		mMainScreen = ScreenMain::createTabUI();
		mMainScreen->show();
	}
private:
	ScreenMain* mMainScreen;
};
extern "C" int MAMain()
{
	MAUtil::Moblet::run(new NativeUIMoblet());
	return 0;
}

ScreenMain.h

#ifndef SCREEN_MAIN_H_
#define SCREEN_MAIN_H_
#include <NativeUI/Widgets.h>
using namespace NativeUI;
class ScreenMain : public TabScreen
{
public:
	ScreenMain();
        [...]
	static ScreenMain* createTabUI();
};
#endif

ScreenMain.cpp

#include <maprofile.h>
#include "ScreenMain.h"
#include "TabItems/ScreenFIN.h"
// Indexes for the tab screens.
#define FIN_TAB			0
/**
 * This is a main screen with three tabs.
 */
class ScreenMainWithTabs :
	public ScreenMain,
	public TabScreenListener
{
public:
    ScreenMainWithTabs() : ScreenMain()
    {
	mScreenFIN = new ScreenFIN();
	this->addTab(mScreenFIN);
    }
    [...]
    void tabScreenTabChanged(TabScreen* tabScreen,const int tabScreenIndex)
    {
		mCurrentTabIndex = tabScreenIndex;
    }
private:
	int mCurrentTabIndex;
	ScreenFIN* mScreenFIN;
};
ScreenMain* ScreenMain::createTabUI()
{
	return new ScreenMainWithTabs();
}
ScreenMain::ScreenMain():
	TabScreen()
{
}

ScreenFIN.h

#ifndef SCREENFIN_H_
#define SCREENFIN_H_
#include "NativeUI/Widgets.h"
#include <MAUtil/GLMoblet.h>
#include <GLES2/gl2.h>

using namespace NativeUI;

class ScreenFIN:
	public Screen,
	public MAUtil::GLMoblet
{
public:
	ScreenFIN();
	void init();
	void draw();
private:
};
#endif /* SCREENFIN_H_ */

ScreenFIN.cpp

#include "../Util.h"
#include "MAHeaders.h"
#include "ScreenFIN.h"

ScreenFIN::ScreenFIN() :
		MAUtil::GLMoblet(GLMoblet::GL2) {
	setTitle("FIN");
	if (isAndroid()) {
		// Set the screen icon for Android.
		setIcon(RES_TAB_ICON_WEB_VIEW_ANDROID);
	} else {
		// Set the screen icon for iOS.
		setIcon(RES_TAB_ICON_WEB_VIEW);
	}
	// Create and add the main layout to the screen.
	VerticalLayout* mainLayout = new VerticalLayout();
	setMainWidget(mainLayout);
	lprintfln("ScreenFIN");
}
void ScreenFIN::init() {
	lprintfln("init");
}
void ScreenFIN::draw() {
	lprintfln("draw");
}

Here is an example of my code, or try to combine OpenGL and tabscreen

Thank you, Cordially

Pem
Pem's picture
Offline
Joined: 17 Jan 2012
Posts:

Re,
Nobody has found a solution to combine tabScreen with GLMoblet?
Thank you, Cordially
;)

eavedrop44
eavedrop44's picture

"The application Tried to instantiate More Than One Environment. There Can Be Only One per application."

Sam Pickard
rival's picture
Offline
Mobile Archmage
Joined: 19 Mar 2009
Posts:

This error is (in my experience) always caused by a memory problem. You've almost certainly done something wrong with object management, probably deleting the same object twice. There isn't a quick way to find out where - you have to start taking your project apart and checking all of the logic again.

Iraklis Rossis
Iraklis Rossis's picture
Offline
Mobile Wizard
Joined: 3 Aug 2011
Posts:

GLMoblet should not be used along with a NativeUI project, because it does it's own thing. If you are using NativeUI tabs, use the GLView widget instead.