Jump to content

[SOLVED] Crash getting height from terrain in C++ plugin


photo

Recommended Posts

Posted

Hi,

 

I don't know if this bug is related to version 2.5 or the previous one, but the engine crashed when I try to get the height of my ObjectTerrainPtr.

ObjectTerrainPtr objTerrain = ObjectTerrain::cast(newObject); // try to cast NodePtr to ObjectTerrainPtr


	if (objTerrain.get() != NULL)
	{

		Log::message("getStep: %f\n", objTerrain->getStep());             //Step is successfully printed
		Log::message("getHeight: %f\n", objTerrain->getHeight(10, 10));   //Crash on program
	}

I tried either float or integer variables in getting the height, but I got the same result. I tried to reproduce those behavior in UnigineScript (to exclude error in terrain data), but therefor I got the correct height.

 

Posted

Hello Christian
I created a new c ++ project in an SDK browser
In the editor, I added the node ObjectTerrain_0 (you can also import the height and albedo data into it) via Create - Object - ObjectTerrain
In the AppWorldLogic.cpp file, I added the following code:

int AppWorldLogic::init() {
	// Write here code to be called on world initialization: initialize resources for your world scene during the world start.

	NodePtr newObject = Editor::get()->getNodeByName("ObjectTerrain_0");
	ObjectTerrainPtr objTerrain = ObjectTerrain::cast(newObject); 
	if (objTerrain.get() != NULL)
	{
		Log::message("getStep: %f\n", objTerrain->getStep());             
		Log::message("getHeight: %f\n", objTerrain->getHeight(100, 100));   
	}

	return 1;
}

The project was compiled and run without errors
In the console, the following messages (if you import height and albedo data):
getStep: 1.000000
getHeight: 9.803923

Can you elaborate on how you use get-> height in your project?

 

Thanks

Posted

Hi,

 

thanks for the reply. I got it worked on my site. I relinked all the files in VS and the error crash disappeared. Maybe I had some old libraries used.

 

Sorry for the inconvenience caused.

×
×
  • Create New...