map filename error

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
funjobie
Posts: 5
Joined: Tue Mar 08, 2005 5:16 am

map filename error

Post by funjobie »

hi!
i got a little problem with my app. when i try to load a map, it crashes cause the filename is mixed up.
first i started based on the gui-tutorial, where there is a button for a filebrowser which should give an output:

Code: Select all

//i have declared the variables const wchar_t* so;
//const c8* map; in the beginning of the code
if (id == 103)
{
listbox->addItem(L"File open");
IGUIFileOpenDialog* dia =env->addFileOpenDialog(L"Please choose a file.");
	so = dia->getFilename();
	stringc temp(so);
	map = temp.c_str();
return true;
}
then later in the while-loop i got this:

Code: Select all

// taste_a is set when the user presses a
if (taste_a == 1 && lvgeladen == 0 && map != 0)
{
      scene::IAnimatedMesh* levelmesh = smgr->getMesh(map);
  	node = smgr->addOctTreeSceneNode(levelmesh->getMesh(0));
		node->setMaterialFlag(video::EMF_LIGHTING, false);
		lvgeladen = 1;
}

There are no errors while compiling, but the games crashes when i have chosen a file and then press a. luckily the console gives out
"file could not be opened: p||$%§ "
or something like that so i think the mapname got damaged in the type conversation.
i took a look in the other threads about types like the one of the messagebox and they brought me at least to being able to compile, but i think i got another mistake as well...
Fraza
Posts: 113
Joined: Sat Feb 26, 2005 11:28 am
Location: Leeds

Post by Fraza »

I think if you make your variable map a stringc and assign it as you did temp, then when you call getMesh you put

getMesh(map.c_str());

that would work. As I understand c_str() returns the pointer to the string, which is why the map name would be lost when assigning map to temp.c_str().

I, of course, could be wrong. I haven't been using C++ for very long and I just started Irrlicht VERY recently. But I definetly think it's worth a try.

(stringc is a typedef for char* and stringw is a typedef for wchar_t* as far as I know, c8 is also a type def for char)
jox
Bug Slayer
Posts: 726
Joined: Thu Apr 22, 2004 6:55 pm
Location: Germany

Post by jox »

Listen to Fraza, he should know now:

http://irrlicht.sourceforge.net/phpBB2/ ... php?t=6239

;)

Fraza wrote:(stringc is a typedef for char* and stringw is a typedef for wchar_t* as far as I know ...)
That's wrong though. stringc is a wrapper class for char* and stringw is a wrapper class for wchar_t*.
It is like it is. And because it is like it is, things are like they are.
Fraza
Posts: 113
Joined: Sat Feb 26, 2005 11:28 am
Location: Leeds

Post by Fraza »

What is a wrapper class exactly.

P.S. After extensive testing I managed to make a pretty effective crash from reading/writing outside of array bounds :D, I had to go out by 16 spaces (for some unknown reason, probably just what was in my RAM at the time). But I had to reset my computer several times :twisted:. So the way Dev-C++ compiles the program can't be entirely bad.

Apparently the reason no error is thrown up is for efficiencey, C++ just assumes the programmer gets everything right.
jox
Bug Slayer
Posts: 726
Joined: Thu Apr 22, 2004 6:55 pm
Location: Germany

Post by jox »

Fraza wrote:What is a wrapper class exactly.
It's a class that contains another class, struct or type, or several of them, which you can't access directly, but have to use the wrapper class functions. The wrapper class takes care of memory handling, deleting, modifying etc. of the wrapped element(s). This ensures integrity. core::string is an example, core::array is another.
Fraza wrote: P.S. After extensive testing I managed to make a pretty effective crash from reading/writing outside of array bounds :D, I had to go out by 16 spaces (for some unknown reason, probably just what was in my RAM at the time). But I had to reset my computer several times :twisted:. So the way Dev-C++ compiles the program can't be entirely bad.

Apparently the reason no error is thrown up is for efficiencey, C++ just assumes the programmer gets everything right.
C++, yes. But the IDE normally complains about access violations in debug mode. If not, then the memory after the array probably belongs also to the application (in your case 16 somethings).
It is like it is. And because it is like it is, things are like they are.
funjobie(guest)

Post by funjobie(guest) »

sry, took me longer to post.
im sitting now in school and cookies dont work here so i cant login properly

i tried what Fraza said, and made map a stringc and changed the getmesh, but it didnt change. just that the error now doesn't show a wrong name, just nothing.
could it be possible that the getFilename doesnt include the complete path?

the code with the temp vars is something i got from Fraza's post ;)
funjobie
Posts: 5
Joined: Tue Mar 08, 2005 5:16 am

Post by funjobie »

ok i solved it, there was a good way to get the filename in the dmf-sdk.
Post Reply