Page 1 of 1

Screen freezes

Posted: Sun Sep 16, 2007 12:21 am
by mybrainisfull
This is a piece of code in one of my event receiver. The screen freezes when it should actually be rendering the nodes to the color red according to the time elapsed. When the screen unfreezes again, it gives me all the nodes red at one go instead of having it in order of the 'Start time'. Here is the code

Code: Select all

                                                        int timeelapsed=0;
							int presenttime=0;
							
							ITimer *timenow1=mydevice->getTimer();
							for(int j=0;j<=projectfinish;j++)
							{	
								
								presenttime=timenow1->getRealTime();
								do
								{for(int i=0;i<50;i++)
								{if((activities[i]->existsAttribute("Start time")==true)&&(j==activities[i]->getAttributeAsInt("Start time")))
									{if(activities[i]->getAttributeAsInt("Group 1")!=0&&groups[activities[i]->getAttributeAsInt("Group 1")]!=0)
									{	listofchildren=groups[activities[i]->getAttributeAsInt("Group 1")]->getChildren();
										if(listofchildren.empty()!=true)
										{core::list<ISceneNode*>::Iterator it = listofchildren.begin();
										do
										{
										(*it)->getMaterial(0).EmissiveColor.setRed(255);
										it++;}
										while(it!=listofchildren.end() ); 
										}
									}
									if(activities[i]->getAttributeAsInt("Group 2")!=0&&groups[activities[i]->getAttributeAsInt("Group 2")]!=0)
									{	listofchildren=groups[activities[i]->getAttributeAsInt("Group 2")]->getChildren();
										if(listofchildren.empty()!=true)
										{core::list<ISceneNode*>::Iterator it = listofchildren.begin();
										do
										{
										(*it)->setMaterialFlag(video::EMF_LIGHTING, false);
										it++;}
										while(it!=listofchildren.end() ); 
										}
									}
									if(activities[i]->getAttributeAsInt("Group 3")!=0&&groups[activities[i]->getAttributeAsInt("Group 3")]!=0)
									{	listofchildren=groups[activities[i]->getAttributeAsInt("Group 3")]->getChildren();
										if(listofchildren.empty()!=true)
										{core::list<ISceneNode*>::Iterator it = listofchildren.begin();
										do
										{
										(*it)->setMaterialFlag(video::EMF_LIGHTING, false);
										it++;}
										while(it!=listofchildren.end() ); 
										}
									}
									if(activities[i]->getAttributeAsInt("Group 4")!=0&&groups[activities[i]->getAttributeAsInt("Group 4")]!=0)
									{	listofchildren=groups[activities[i]->getAttributeAsInt("Group 4")]->getChildren();
										if(listofchildren.empty()!=true)
										{core::list<ISceneNode*>::Iterator it = listofchildren.begin();
										do
										{
										(*it)->setMaterialFlag(video::EMF_LIGHTING, false);
										it++;}
										while(it!=listofchildren.end() ); 
										}
									
									}}}

								myscene->drawAll();
								timeelapsed=timenow1->getRealTime()-presenttime;
								timeelapsed+=1;
								}while(timeelapsed<=1000);
									
								
								}
Any help would be appreciated. Thanks.

Posted: Sun Sep 16, 2007 1:59 am
by vitek
I'm sure there are a lot of ways to do this that are a bit simpler. Your code is quite complicated, and much of it is copy/paste. That will make it a real pain to maintain and debug.

Anyways, the problem is that you need to call beginScene() before you call drawAll() and endScene() after. If you don't do that, then nothing is actually sent to the hardware to be displayed.

Travis

Posted: Sun Sep 16, 2007 2:17 am
by mybrainisfull
Oops...that drawall() was just something i was trying out
Just ignore that bit.

What I'm trying to do:
I have a bunch of scene nodes and I have an interface setup to create an attribute 'activities'. This attribute 'activities' has a way of keeping track of the scenenodes associated with that 'activity' along with when the 'activity' is supposed to start 'j' or "Start time". Now I just want to play this back by either highlighting the nodes or coloring them red according to the "Start time".

Coding in general:
This is my first go and I have a deadline to meet so just did stuff on the fly. I'm almost done and thankfully debugging is not that big a deal presently. :)

Posted: Mon Sep 17, 2007 2:17 am
by vitek
I don't care if you think the call to drawAll() is for debugging or not. You need to call beginScene(), drawAll() and endScene() in there somewhere.
The screen freezes when it should actually be rendering the nodes to the color red according to the time elapsed.
If you eliminate all of the complicated copy/paste cruft, you'll see the problem.

Code: Select all

int timeelapsed = 0;
int presenttime = 0;

ITimer *timenow1 = mydevice->getTimer();
for(int j = 0; j <= projectfinish; j++)
{
    presenttime = timenow1->getRealTime();
    do
    {
        // bunch of complicated stuff
        // ...

        timeelapsed = timenow1->getRealTime() - presenttime;
        timeelapsed += 1;
    } while(timeelapsed <= 1000);

    // ...
}
When i read that code, it sure looks to me like the inner loop is going to run for at least 1 second for each value of j. If you aren't calling beginScene(), drawAll() and endScene() in there, then you're just spinning doing stuff that you won't see until the outer loop is done.

Travis

Posted: Mon Sep 17, 2007 4:57 am
by mybrainisfull
Yup...I figured that out today. Fixed it too and it works :D. Thank you though.

I just modified the code and put it in main() where I did have beginscene(), drawall() and endscene(). I wasn't sure if putting beginscene, drawall and endscene in the event receiver would have worked since the functions would be called in two places, main() and the event receiver. I should prolly try that too just for the heck of it.

Posted: Mon Sep 17, 2007 5:02 am
by mybrainisfull
Oh btw...travis for moderator!