Help with TailBite: Memory error when using my library

Everything else that doesn't fall into one of the other PB categories.
dracflamloc
Addict
Addict
Posts: 1648
Joined: Mon Sep 20, 2004 3:52 pm
Contact:

Help with TailBite: Memory error when using my library

Post by dracflamloc »

I have a C/C++ DLL with some exposed functions which I wish to wrap into a UserLibrary. I have many functions similar to this:

Code: Select all

 ProcedureDLL.l i3D_Initialize3D(width.l,height.l,bits.l,isFullscreen.l,isResizable.l,*CallBackProcedure) ; Starts the 3d engine. CallBackProcedure(id.l). YOU MUST CALL THIS BEFORE OTHER i3D FUNCTIONS
  i3D_Library=OpenLibrary(#PB_Any,"./PB_Irrlicht.dll")
  If IsLibrary(i3D_Library)
    ProcedureReturn CallCFunction(i3D_Library,"pb_Initialize3D",width,height,bits,isFullscreen,isResizable,*CallBackProcedure)
  Else
    ProcedureReturn 0
  EndIf
EndProcedure

ProcedureDLL.l i3D_IsRunning() ; See if the 3d engine is running or crashed/stopped
  ProcedureReturn CallCFunction(i3D_Library,"pb_Running")
EndProcedure
When I use these functions from an EXE they all work perfectly fine, but when I use TailBite to make a UserLibrary, the function calls make the program crash with a memory read error at address 0x000000ff.

Here's some example of the C code:

Code: Select all

//Create the devices for the PB engine - MUST BE CALLED BEFORE ANYTHING ELSE
API int CALLCONV pb_Initialize3D(int width,int height,int bits,int isFullscreen,int isResizable,void (*EventCallBack)(int))
{
	pb_device = createDevice(OPENGL,dimension2d<s32>(width,height),bits,pb_intToBool(isFullscreen),true,false);
	
	if (pb_device==0)
		return 0;

	EventCallBackPtr = EventCallBack;
	pb_device->setEventReceiver(&pb_receiver);
	pb_device->setResizeAble(pb_intToBool(isResizable));

	//get video driver and scene manager and gui
	pb_driver = pb_device->getVideoDriver();
	pb_scene = pb_device->getSceneManager();
	pb_gui = pb_device->getGUIEnvironment();
	pb_camera = pb_scene->addCameraSceneNode(0,vector3df(0,0,0),vector3df(0,0,0),0);
		
	return 1;
}

//Set the window caption
API void CALLCONV pb_SetWindowCaption(char * text)
{
	stringw k=L"";
	k += text;
	pb_device->setWindowCaption(k.c_str());
}
User avatar
GedB
Addict
Addict
Posts: 1313
Joined: Fri May 16, 2003 3:47 pm
Location: England
Contact:

Post by GedB »

Is the id variable used in the call to CallBackProcedure() a Global?

If so, this could be the problem. The global variable will exist in the executable, but not in the library.
dracflamloc
Addict
Addict
Posts: 1648
Joined: Mon Sep 20, 2004 3:52 pm
Contact:

Post by dracflamloc »

Nah it's not a global. It's okay though I don't think I'll make it a userLibrary unless someone has the holy grail of answers ;) I'm just gonna release my DLL and a .pb file people can include in thier exe if they don't want to use CallCFunction.
El_Choni
TailBite Expert
TailBite Expert
Posts: 1007
Joined: Fri Apr 25, 2003 6:09 pm
Location: Spain

Post by El_Choni »

I'll have a look at this, thanks for the report.

Regards,
El_Choni
Post Reply