Code Problem

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Mr.Matze
Posts: 3
Joined: Wed Mar 12, 2008 3:48 pm

Code Problem

Post by Mr.Matze »

hi,

i am new at the irrlicht scene and just have a problem. I have some years programm experience in Basic and already some experience in C++. But with irrlicht i am a total noob.
Sorry for the nothing-saying title but it's hard to explain your Problem with just a few words ;).

Here we go:

I downloaded Irrlicht 1.4 and configured my Microsoft Visual Studio 2005
Version 8.0.50727.42 like I were told in the Hello World Tutorial. Now I wanted to play with the examples to create a feeling for the new enviroument. I created a new project ( empty Project ), copied the source code of ex. 12 Terrain Rendering and copied the files I need for the project. First everything wored well, I started the programm and it worked. Then i just changed the code a bit and started again but then it didn't work anymore so I copied the Code of the example again and started the programm again and it didn't still work. I created a new Project and it doesn't still work. Here u can see what the debugger tells all three times:

Code: Select all

------ Erstellen gestartet: Projekt: Terrain, Konfiguration: Debug Win32 ------
Kompilieren...
main.cpp
g:\engines\irrlicht-1.4\include\irrString.h(59) : error C3861: "snprintf": Bezeichner wurde nicht gefunden.
        g:\engines\irrlicht-1.4\include\irrString.h(55): Bei der Kompilierung der  Klassen-template der irr::core::string<T>::string(const double)-Memberfunktion
        with
        [
            T=wchar_t
        ]
        g:\engines\irrlicht-1.4\include\IGUIElement.h(911): Siehe Verweis auf die Instanziierung der gerade kompilierten Klassen-template "irr::core::string<T>".
        with
        [
            T=wchar_t
        ]
Das Buildprotokoll wurde unter "file://g:\Eigene Programme\C++\Terrain\Terrain\Debug\BuildLog.htm" gespeichert.
Terrain - 1 Fehler, 0 Warnung(en)
========== Erstellen: 0 erfolgreich, Fehler bei 1, 0 aktuell, 0 übersprungen ==========
Sorry it's german but I think you can see the mistake. He tells something like:

error C3861: "snprintf": Bezeichner wurde nicht gefunden.
- error C3861: "snprintf": Designator not found

Hope you can help me

thx

Matze
Morgawr
Posts: 95
Joined: Wed Sep 26, 2007 7:04 pm

Re: Code Problem

Post by Morgawr »

Mr.Matze wrote:hi,

i am new at the irrlicht scene and just have a problem. I have some years programm experience in Basic and already some experience in C++. But with irrlicht i am a total noob.
Sorry for the nothing-saying title but it's hard to explain your Problem with just a few words ;).

Here we go:

I downloaded Irrlicht 1.4 and configured my Microsoft Visual Studio 2005
Version 8.0.50727.42 like I were told in the Hello World Tutorial. Now I wanted to play with the examples to create a feeling for the new enviroument. I created a new project ( empty Project ), copied the source code of ex. 12 Terrain Rendering and copied the files I need for the project. First everything wored well, I started the programm and it worked. Then i just changed the code a bit and started again but then it didn't work anymore so I copied the Code of the example again and started the programm again and it didn't still work. I created a new Project and it doesn't still work. Here u can see what the debugger tells all three times:

Code: Select all

------ Erstellen gestartet: Projekt: Terrain, Konfiguration: Debug Win32 ------
Kompilieren...
main.cpp
g:\engines\irrlicht-1.4\include\irrString.h(59) : error C3861: "snprintf": Bezeichner wurde nicht gefunden.
        g:\engines\irrlicht-1.4\include\irrString.h(55): Bei der Kompilierung der  Klassen-template der irr::core::string<T>::string(const double)-Memberfunktion
        with
        [
            T=wchar_t
        ]
        g:\engines\irrlicht-1.4\include\IGUIElement.h(911): Siehe Verweis auf die Instanziierung der gerade kompilierten Klassen-template "irr::core::string<T>".
        with
        [
            T=wchar_t
        ]
Das Buildprotokoll wurde unter "file://g:\Eigene Programme\C++\Terrain\Terrain\Debug\BuildLog.htm" gespeichert.
Terrain - 1 Fehler, 0 Warnung(en)
========== Erstellen: 0 erfolgreich, Fehler bei 1, 0 aktuell, 0 übersprungen ==========
Sorry it's german but I think you can see the mistake. He tells something like:

error C3861: "snprintf": Bezeichner wurde nicht gefunden.
- error C3861: "snprintf": Designator not found

Hope you can help me

thx

Matze
mm. With that alone I don't think a lot of people will be able to solve your problem... mind posting all (or some parts) of the code which is giving problems?
Mr.Matze
Posts: 3
Joined: Wed Mar 12, 2008 3:48 pm

Post by Mr.Matze »

Yea I'll post it but it's exactly the code of the example:

Code: Select all

/*
This tutorial will briefly show how to use the terrain renderer of Irrlicht. It will also
show the terrain renderer triangle selector to be able to do collision detection with
terrain.

Note that the Terrain Renderer in Irrlicht is based on Spintz' GeoMipMapSceneNode, lots 
of thanks go to him.
DeusXL provided a new elegant simple solution for building larger area on small heightmaps
-> terrain smoothing.
In the beginning there is nothing special. We include the needed header files and create
an event listener to listen if the user presses the 'W' key so we can switch to wireframe
mode and if he presses 'D' we toggle to material between solid and detail mapped.
*/
#include <irrlicht.h>
#include <iostream>

using namespace irr;

#pragma comment(lib, "Irrlicht.lib")


class MyEventReceiver : public IEventReceiver
{
public:

	MyEventReceiver(scene::ISceneNode* terrain)
	{
		// store pointer to terrain so we can change its drawing mode
		Terrain = terrain;
	}

	bool OnEvent(const SEvent& event)
	{
		// check if user presses the key 'W' or 'D'
		if (event.EventType == irr::EET_KEY_INPUT_EVENT && !event.KeyInput.PressedDown)
		{
			switch (event.KeyInput.Key)
			{
			case irr::KEY_KEY_W: // switch wire frame mode
				Terrain->setMaterialFlag(video::EMF_WIREFRAME, !Terrain->getMaterial(0).Wireframe);
				Terrain->setMaterialFlag(video::EMF_POINTCLOUD, false);
				return true;
			case irr::KEY_KEY_P: // switch wire frame mode
				Terrain->setMaterialFlag(video::EMF_POINTCLOUD, !Terrain->getMaterial(0).PointCloud);
				Terrain->setMaterialFlag(video::EMF_WIREFRAME, false);
				return true;
			case irr::KEY_KEY_D: // toggle detail map
				Terrain->setMaterialType(
					Terrain->getMaterial(0).MaterialType == video::EMT_SOLID ? 
					video::EMT_DETAIL_MAP : video::EMT_SOLID);
				return true;
			}
		}

		return false;
	}

private:
	scene::ISceneNode* Terrain;
};


/*
The start of the main function starts like in most other example. We ask the user
for the desired renderer and start it up.
*/
int main()
{
	// let user select driver type

	video::E_DRIVER_TYPE driverType = video::EDT_DIRECT3D9;


	// create device

	IrrlichtDevice* device = createDevice(driverType, core::dimension2d<s32>(640, 480));

	if (device == 0)
		return 1; // could not create selected driver.

	
	/*
	First, we add standard stuff to the scene: A nice irrlicht engine
	logo, a small help text, a user controlled camera, and we disable
	the mouse cursor.
	*/   

	video::IVideoDriver* driver = device->getVideoDriver();
	scene::ISceneManager* smgr = device->getSceneManager();
	gui::IGUIEnvironment* env = device->getGUIEnvironment();

	driver->setTextureCreationFlag(video::ETCF_ALWAYS_32_BIT, true);

	// add irrlicht logo
	env->addImage(driver->getTexture("../../media/irrlichtlogo2.png"),
		core::position2d<s32>(10,10));

	//set other font
	env->getSkin()->setFont(env->getFont("../../media/fontlucida.png"));

	// add some help text
	gui::IGUIStaticText* text = env->addStaticText(
		L"Press 'W' to change wireframe mode\nPress 'D' to toggle detail map",
		core::rect<s32>(10,440,250,475), true, true, 0, -1, true);

	// add camera
	scene::ICameraSceneNode* camera = 
		smgr->addCameraSceneNodeFPS(0,100.0f,1200.f);

	camera->setPosition(core::vector3df(1900*2,255*2,3700*2));
	camera->setTarget(core::vector3df(2397*2,343*2,2700*2));
	camera->setFarValue(12000.0f);

	// disable mouse cursor
	device->getCursorControl()->setVisible(false);

	/*
	Here comes the terrain renderer scene node: We add it just like any 
	other scene node to the scene using ISceneManager::addTerrainSceneNode(). 
	The only parameter we use is a file name to the heightmap we use. A heightmap
	is simply a gray scale texture. The terrain renderer loads it and creates 
	the 3D terrain from it.
	To make the terrain look more big, we change the scale factor of it to (40, 4.4, 40).
	Because we don't have any dynamic lights in the scene, we switch off the lighting,
	and we set the file terrain-texture.jpg as texture for the terrain and 
	detailmap3.jpg as second texture, called detail map. At last, we set
	the scale values for the texture: The first texture will be repeated only one time over 
	the whole terrain, and the second one (detail map) 20 times. 
	*/

	// add terrain scene node
	scene::ITerrainSceneNode* terrain = smgr->addTerrainSceneNode( 
		"../../media/terrain-heightmap.bmp",
		0,										// parent node
		-1,										// node id
		core::vector3df(0.f, 0.f, 0.f),			// position
		core::vector3df(0.f, 0.f, 0.f),			// rotation
		core::vector3df(40.f, 4.4f, 40.f),		// scale
		video::SColor ( 255, 255, 255, 255 ),	// vertexColor,
		5,										// maxLOD
		scene::ETPS_17,							// patchSize
		4										// smoothFactor
		);

	terrain->setMaterialFlag(video::EMF_LIGHTING, false);

	terrain->setMaterialTexture(0, driver->getTexture("../../media/terrain-texture.jpg"));
	terrain->setMaterialTexture(1, driver->getTexture("../../media/detailmap3.jpg"));
	
	terrain->setMaterialType(video::EMT_DETAIL_MAP);

	terrain->scaleTexture(1.0f, 20.0f);
	//terrain->setDebugDataVisible ( true );

	/*
	To be able to do collision with the terrain, we create a triangle selector.
	If you want to know what triangle selectors do, just take a look into the 
	collision tutorial. The terrain triangle selector works together with the
	terrain. To demonstrate this, we create a collision response animator 
	and attach it to the camera, so that the camera will not be able to fly 
	through the terrain.
	*/

	// create triangle selector for the terrain	
	scene::ITriangleSelector* selector
		= smgr->createTerrainTriangleSelector(terrain, 0);
	terrain->setTriangleSelector(selector);

	// create collision response animator and attach it to the camera
	scene::ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(
		selector, camera, core::vector3df(60,100,60),
		core::vector3df(0,0,0), 
		core::vector3df(0,50,0));
	selector->drop();
	camera->addAnimator(anim);
	anim->drop();

	/*
	To make the user be able to switch between normal and wireframe mode, we create
	an instance of the event reciever from above and let Irrlicht know about it. In 
	addition, we add the skybox which we already used in lots of Irrlicht examples.
	*/

	// create event receiver
	MyEventReceiver receiver(terrain);
	device->setEventReceiver(&receiver);

   	// create skybox
	driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, false);

	smgr->addSkyBoxSceneNode(
		driver->getTexture("../../media/irrlicht2_up.jpg"),
		driver->getTexture("../../media/irrlicht2_dn.jpg"),
		driver->getTexture("../../media/irrlicht2_lf.jpg"),
		driver->getTexture("../../media/irrlicht2_rt.jpg"),
		driver->getTexture("../../media/irrlicht2_ft.jpg"),
		driver->getTexture("../../media/irrlicht2_bk.jpg"));

	driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, true);


	/*
	That's it, draw everything. Now you know how to use terrain in Irrlicht.
	*/

	int lastFPS = -1;

	while(device->run())
	if (device->isWindowActive())
	{
		driver->beginScene(true, true, 0 );

		smgr->drawAll();
		env->drawAll();

		driver->endScene();

		// display frames per second in window title
		int fps = driver->getFPS();
		if (lastFPS != fps)
		{
			core::stringw str = L"Terrain Renderer - Irrlicht Engine [";
			str += driver->getName();
			str += "] FPS:";
			str += fps;
			// Also print terrain height of current camera position
			// We can use camera position because terrain is located at coordinate origin
			str += " Height: ";
			str += terrain->getHeight(camera->getAbsolutePosition().X, camera->getAbsolutePosition().Z);

			device->setWindowCaption(str.c_str());
			lastFPS = fps;
		}
	}

	device->drop();
	
	return 0;
}

vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

If the example compiles and runs cleanly, then save yourself some trouble just copy the example project directory. Why bother trying to create a project file from scratch if you have one that you already know works just fine?

Travis
silvertoken
Posts: 2
Joined: Thu Mar 13, 2008 1:17 am

I had this problem too

Post by silvertoken »

I had this problem a couple of days ago... I wonder if M$ changed something in there system so that you can't use snprintf anymore. Anyways just double click the error message that it says it gets from the header and it should jump you right to the line in irrstring.h change the snprintf to sprintf_s and this should fix it. It looks like a define is going to need to be added to the irrlicht code to keep this portable.

Silver~
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

The define is in irrTypes.h It should convert snprint to either _sprintf or _sprintf_s. But it seems to fail from time to time.
Mr.Matze
Posts: 3
Joined: Wed Mar 12, 2008 3:48 pm

Post by Mr.Matze »

I changed snprintf(tmpbuf, 255, "%0.6f", number); to _snprintf_s(tmpbuf, 255, "%0.6f", number);

And now it works fine. Thanks to you all!
silvertoken
Posts: 2
Joined: Thu Mar 13, 2008 1:17 am

I found the problem...

Post by silvertoken »

Okay I found the root cause of the problem. It seems Microsoft's compiler does not define WIN32 it defines _WIN32.

all I had to do was change irrcomileconfig.h's

#if defined(WIN32) || defined(WIN64)

to

#if defined(_WIN32) || defined(_WIN64)

Silver~
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Yup, WIN32 is defined in the project settings, it's not a cl.exe intrinsic. I'm not clear on why IrrCompileConfig.h doesn't use _WIN32 / _WIN64.

Presumably someone at some point wanted to do a cl.exe build but not actually include all the Windows code.

Or, it's just a snafu. ;)
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Ok, that's an easy fix then :D
klabauter
Posts: 1
Joined: Wed Apr 30, 2008 3:23 pm

Post by klabauter »

Hello everybody,

I have a problem with that snprinf as well, however the above fix doesn't work for me. It seems to be related with the _WIN32 definition, but actually the default makefile defines both _WIN32 and WIN32. Whats more, the define doesn't seem to apply when building (_IRR_WINDOWS_API_ doesn't become defined, causing X11-related include-trouble, even with _IRR_COMPILE_WITH_X11_ turned off).

Is there a good introduction how to adapt the default makefile, or do I do wrong anything else?

I am currently building with only make to learn to handle that basic stuff better, rather than have an IDE handle everything for me.

Best regards, Klabauter
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

if you use the provided makefile, the default target will use the linux static rules. For win32 machines you have to call 'make all_win32'
Post Reply