PDA

View Full Version : Interface::SelectNode() Crashes in Max2008 (SDK)


clc
04-08-2008, 06:48 AM
Hello,

I'm having trouble with crashes in Max2008 when calling Interface::SelectNode(). To test, I created a new GUP using the wizard and added the code below. When the plugin starts, it creates a new thread. When the thread first runs, it immediately sleeps for 10 seconds to wait for Max to finish starting. When it wakes up, it then creates 256 spheres in the scene and then goes to sleep for another second. From there on out, the thread wakes, selects the i-th sphere, and then sleeps again. The loop usually cycles several times through all 256 spheres, but it will always eventually crash within a few minutes. I've tried sleep times between 1 and 1000 ms, and the thing always crashes eventually. The error it gives is "Unhandled exception at 0x0060e684 in 3dsmax.exe: 0xC0000005: Access violation reading location 0x00000288." Is there anything I need to do to ensure proper synchronization between Max and my plugin when selecting nodes to prevent the crash?

Thanks,
Chris


enum State {Startup, Create, Select};
HANDLE SelectionThread = 0;
static DWORD WINAPI ThreadProc(LPVOID lpParameter)
{
static const int count = 256;
static int index = 0;
static State state = Startup;
while (true)
{
DWORD sleep = 1;
switch (state)
{
case Startup:
// on entry, switch states and go back to sleep for 10 seconds
state = Create;
sleep = 10000;
break;
case Create:
// create 256 spheres
for (int i = 0; i != count; ++i)
{
Interface *ip = GetCOREInterface();
assert(ip);
Object *obj = static_cast<Object*>(ip->CreateInstance(GEOMOBJECT_CLASS_ID, Class_ID(SPHERE_CLASS_ID,0)));
assert(obj);
ip->CreateObjectNode(obj);
}
// switch states and sleep for 1 second
state = Select;
sleep = 1000;
break;
case Select:
// select the i-th sphere and sleep a while
Interface *ip = GetCOREInterface();
assert(ip);
INode *root = ip->GetRootNode();
assert(root);
INode *child = root->GetChildNode(index);
assert(child);
ip->SelectNode(child);
++index %= count;
sleep = 1;
break;
}
SleepEx(sleep, FALSE);
}
return 0;
}
DWORD SelectionTest::Start( ) {
SelectionThread = CreateThread(NULL, 0, ThreadProc, static_cast<void*>(this), 0, NULL);
assert(SelectionThread);
return GUPRESULT_KEEP;
}
void SelectionTest::Stop( ) {
if (SelectionThread)
{
TerminateThread(SelectionThread, 0);
CloseHandle(SelectionThread);
SelectionThread = 0;
}
}

CGTalk Moderation
04-08-2008, 06:48 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.