Jump to content

Q:Segmentation fault, Sharing some code

Recommended Posts

Hey hey,

I have been doing some more exploration of the HDK and figured out how to implement volumes :D

So this is the first thing i would like to share with any one who is interested in them.


static PRM_Name PrmNames[]= 

PRM_Template SDF::MyTemplatelist[] = 

Function to get voxol world space position

UT_Vector3 getWorldSpace(GU_PrimVolume *voxPrim,UT_VoxelArray <fpreal> *vox,int tileX,int tileY,int tileZ)
	/*Get Tile position in Voxol Space [0-1]*/
	UT_Vector3 pos;

	UT_BoundingBox bounds;

	/*Calculate to world space*/
	float localX = (((bounds.xsize()/vox->getRes(0))*tileX)+bounds.xmin());
	float localY = (((bounds.ysize()/vox->getRes(1))*tileY)+bounds.ymin());
	float localZ = (((bounds.zsize()/vox->getRes(2))*tileZ)+bounds.zmin());

	pos.x() = localX;
	pos.y() = localY;
	pos.z() = localZ;

	return pos;

Cook method

	/*INITIALISE Parameters*/
	int Volume_Iterations_X_Parameter = evalInt(0,0,context.myTime);
	int Volume_Iterations_Y_Parameter = evalInt(0,1,context.myTime);
	int Volume_Iterations_Z_Parameter = evalInt(0,2,context.myTime);

	float Volume_Position_X_Parameter = evalInt(1,0,context.myTime);
	float Volume_Position_Y_Parameter = evalInt(1,1,context.myTime);
	float Volume_Position_Z_Parameter = evalInt(1,2,context.myTime);

//	float Volume_Position_Sphere_X_Parameter = evalInt(2,0,context.myTime);
//	float Volume_Position_Sphere_Y_Parameter = evalInt(2,1,context.myTime);
//	float Volume_Position_Sphere_Z_Parameter = evalInt(2,2,context.myTime);

	float Volume_Radius_Parameter = 1;//evalFloat(2,0,context.myTime);

	if (lockInputs(context) >= UT_ERROR_ABORT)
		return error();

//	duplicateSource(0,context,gdp,1);

	/*Get Bounds*/
	const UT_Matrix4 boundMat;
	UT_BoundingBox bound;

	/*GU_PrimVolume is a PRIMITIVE type so it just as if it is a polygone or face in houdini*/
	/*It creates a container that holds voxel data*/
	GU_PrimVolume *volume_Container = (GU_PrimVolume*)GU_PrimVolume::build(gdp);

	/*Turn it into a SDF*/

	/*Move voxel array to point out that the voxolo sphere is based on world positions*/
	UT_Matrix4 *transf;
	UT_Vector3 transl;
	transl.x() = Volume_Position_X_Parameter;
	transl.y() = Volume_Position_Y_Parameter;
	transl.z() = Volume_Position_Z_Parameter;

	/*UT_VoxelArray is a template class wich means it can take in difrent types of data like float int UT_Vector or in this case fpreal*/
	UT_VoxelArray <fpreal> *voxols = new UT_VoxelArray <fpreal>;

	/*Lets do a loop thrue the volume*/
	for(int X=0; X<Volume_Iterations_X_Parameter;X++)
		for(int Y=0; Y<Volume_Iterations_Y_Parameter;Y++)
			for(int Z=0; Z<Volume_Iterations_Z_Parameter;Z++)
//				UT_Vector3 pos;
//				voxols->indexToPos(X,Y,Z,pos);
				if(getWorldSpace(volume_Container,voxols,X,Y,Z).length() < Volume_Radius_Parameter)

	/*Here i dump the voxols into the container and then build the geometry detail pointer this means it will insert itself in a compteble format into the gdp*/
//	volume_Container->build(gdp);


	return error();

Now the question i want to ask is do you guys experience a lot of segmentation errors when it comes to parameters?

In my code i just posted you can see i commented out a parameter and when i uncomment this then Houdini will give me a segmentation error.

Sometimes having a comma at the end in my parameter definition fixes this problem and sometimes not putting down a comma fixes it aswel.

Is any one experiencing the same thing or am i working with a somewhat bugged version of houdini?

I'm running on Ubuntu Hardy.

Edited by Tamis
Link to comment
Share on other sites

Offhand, it looks like you're missing a PRM_Template() to terminate your parm list. So something like this:

PRM_Template SDF::MyTemplatelist[] =
	PRM_Template() // sentinel

Link to comment
Share on other sites

ah i didn't know that was needed!

thnx for the help :D


One question if you don't mind....

I'm trying to scale the volume container to the bounding size of the object in the 1st input.

Now this is what i have right now, i know the primitive group is not a necessity but it was just a test, i tried it without as well.

	UT_BoundingBox *bound;
	GU_Detail GEO = *inputGeo(0);
	GB_PrimitiveGroup *Pgrp = GEO.newPrimitiveGroup("blabla",1);
	for(int i = 0; i <= GEO.primitives().entries(); i++)

Now the problem is is that in Houdini i get incorrect value's back.(The bounding box center is 0,0,0)



Now the objects bounding box center is 1,1,1




the last 2 numbers always remain the same :huh:

i print the value's as followed:

	std::cout << bound->centerX() << std::endl;
	std::cout << bound->centerY() << std::endl;
	std::cout << bound->centerZ() << std::endl;

Personally i think the method is just f**** up but it might be that i am doing something wrong.

Edited by Tamis
Link to comment
Share on other sites

Aaah never mind i got it.

I uprated to 9.5 and in 9.5 it gives a segmentation error on that code.

what i did was:

UT_BoundingBox *bound;


And it is suppost to be:

UT_BoundingBox bound;


Hoduini 9.0 just gave me funky numbers back 9.5 actually crashes on it :D

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...