Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stack Overflow Line 1 1

Status
Not open for further replies.

Einstein47

Programmer
Nov 29, 2001
737
US
This is the worst bug to track down. I have created a navigation for my site using suckerfish like menus. It is tricky in that my site uses frames and the top frame holds buttons (like menu options) and when the user clicks on a button the appropriate suckerfish menu is created and displayed below the button clicked. Being able to create this and script between frames has been quite a chore. But I have nearly everything figured out, except for 1 small bug.

Stack Overflow at line: 1

The bug is reproducible but I can't for the life of me figure out what is happening. No amount of alerts can pinpoint the error. One thing that is confusing is that I have dozens of links in the various menus, and this issue only happens on 1 link (the main search page). And it only happens if that page is the first one the user navigates to after logging on.

This makes me think that the error is happening because of the lookup page, but it has never had a stack overflow error before. And why would any subsequent views of the lookup page not have the stack overflow error?

The really unfortunate part is that I can't link to my web app since it is for the state juvenile court. The data is very sensitive. I could post the code here, but I really don't know how much of it someone would need to help me pinpoint the error. I really don't expect/want to burden any of you with doing the grunt work of understanding my code.

I guess my main question is what would be the best way to try to pinpoint this Stack Overflow error? Any particular debug methods I should try? Any useful utilities? Anything? .... Beuler?

Einstein47
“Evil abounds when good men do nothing.“ - Nelson R.
[[]Starbase47.com]
 
how completely have you scoured your code for infinite loops, infinitely recursive function calls, etc.? that'd be the first thing i'd check.

second: if you're using frames, is it possible that a page hasn't loaded yet, in one of the frames?



*cLFlaVA
----------------------------
[tt]"quote goes here"[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Woo Hoo - Ok, I found this using the FF error console:

too much recursion - Line: 265

Ok, so here is that part of the code:
Code:
// Run this immediately to attach the event listener
function PopupMenu_attachListener() {
	var frameWin = window.top.window.frames["mainFrame"].document;
	if (document.layers) {
		document.captureEvents(Event.MOUSEUP | Event.SCROLL | Event.MOUSEWHEEL);
	}
	window.popupWindowOldEventListener = frameWin.onmouseup;
	if (window.popupWindowOldEventListener != null) {
		[red]frameWin.onmouseup = new Function("window.popupWindowOldEventListener(); PopupMenu_hidePopupMenus();");[/red]
//alert("adding onmouseup listener");
	}
	else {
		frameWin.onmouseup = PopupMenu_hidePopupMenus;
	}

// Added for scroll wheel to hide menu
	window.popupWindowOldMouseWheel = frameWin.onmousewheel;
	if (window.popupWindowOldMouseWheel != null) {
		frameWin.onmousewheel = new Function("window.popupWindowOldMouseWheel(); PopupMenu_hidePopupMenus();");
	}
	else {
		frameWin.onmousewheel = PopupMenu_hidePopupMenus;
	}

// Added for scrolling to hide menu
   //If we are browsing with IE, reassign frameWin
    if (document.all) {    
        frameWin = window.top.window.frames["mainFrame"].document.body;
    }
	window.popupWindowOldScroll = frameWin.onscroll;
	if (window.popupWindowOldScroll != null) {
		frameWin.onscroll = new Function("window.popupWindowOldScroll(); PopupMenu_hidePopupMenus();");
//alert("adding to onscroll");
	}
	else {
		frameWin.onscroll = PopupMenu_hidePopupMenus;
//alert("creating new onscroll event");
	}
}
I didn't want to lose any existing onmouseup event, so that is why I tried to capture and reset that to the onmouseup event along with my own onmouseup event handler. [red]Is this not the correct way to do that?[/red] I will try without saving the previous method and see what that does. It is odd that only on the lookup page and only on the first time it is called (and only if no other pages have been called) is that a problem.

Einstein47
“Evil abounds when good men do nothing.“ - Nelson R.
[[]Starbase47.com]
 
actually, i think this speaks for itself:

Code:
    window.popupWindowOldEventListener = frameWin.onmouseup;
    if (window.popupWindowOldEventListener != null) {
        frameWin.onmouseup = new Function("window.popupWindowOldEventListener(); PopupMenu_hidePopupMenus();");
//alert("adding onmouseup listener");
    }

you are saying that the function definition of popupWindowOldEventListener should be that of onmouseup.

In your next line of code, you are saying that onmouseup is popupWindowOldEventListener, which you've already set as onmouseup.

So, your mouse button raises and calls popupWindowOldEventListener, which has already been defined as onmouseup, so it calls itself, over and over again.



*cLFlaVA
----------------------------
[tt]"quote goes here"[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Yes - I can see that it is being set to itself - and that it is being called iteratively.

What I have done is add an alert to the function so I can see that each time a new page is called from my menu, it is adding to the event listener another instance of the function. [red]How do I prevent that?[/red]

Here is my updated code - with many sections commented out, as well as the hidePopupMenus() function:
Code:
[teal]// This global function checks all PopupMenu objects to see if they should be hidden[/teal]
function PopupMenu_hidePopupMenus(e) {
	for (var i=0; i<popupWindowObjects.length; i++) {
		if (popupWindowObjects[i] != null) {
			var p = popupWindowObjects[i];
			p.hideIfNotClicked(e);
		}
	}
}

[teal]// Run this immediately to attach the event listener[/teal]
function PopupMenu_attachListener() {
	var frameWin = window.top.window.frames["mainFrame"].document;
	if (document.layers) {
		document.captureEvents(Event.MOUSEUP | Event.SCROLL | Event.MOUSEWHEEL);
	}
[teal]//	window.popupWindowOldEventListener = frameWin.onmouseup;
//	if (window.popupWindowOldEventListener != null) {
//		frameWin.onmouseup = new Function("window.popupWindowOldEventListener(); PopupMenu_hidePopupMenus();");
//alert("adding onmouseup listener");
//	}
//	else {[/teal]
		frameWin.onmouseup = PopupMenu_hidePopupMenus;
[teal]//	}[/teal]

[teal]// Added for scroll wheel to hide menu
//	window.popupWindowOldMouseWheel = frameWin.onmousewheel;
//	if (window.popupWindowOldMouseWheel != null) {
//		frameWin.onmousewheel = new Function("window.popupWindowOldMouseWheel(); PopupMenu_hidePopupMenus();");
//	}
//	else {[/teal]
		frameWin.onmousewheel = PopupMenu_hidePopupMenus;
[teal]//	}[/teal]

[teal]// Added for scrolling to hide menu
   //If we are browsing with IE, reassign frameWin[/teal]
    if (document.all) {    
        frameWin = window.top.window.frames["mainFrame"].document.body;
    }
[teal]//	window.popupWindowOldScroll = frameWin.onscroll;
//	if (window.popupWindowOldScroll != null) {
//		frameWin.onscroll = new Function("window.popupWindowOldScroll(); PopupMenu_hidePopupMenus();");
//alert("adding to onscroll");
//	}
//	else {[/teal]
		frameWin.onscroll = PopupMenu_hidePopupMenus;
[teal]//alert("creating new onscroll event");
//	}[/teal]
}


Einstein47
“Evil abounds when good men do nothing.“ - Nelson R.
[&#91;]Starbase47.com]
 
I am confused now. I have tried this to only set the event handlers once, but now my onmouseup is only being triggered on the first page. Scripting between frames is just so confusing.

Here's my code, now:
Code:
[teal]// Run this immediately to attach the event listener[/teal]
var listenerNotAttached = true;
function PopupMenu_attachListener() {
  if (listenerNotAttached) 
  {
	var frameWin = window.top.window.frames["mainFrame"].document;
	if (document.layers) {
		document.captureEvents(Event.MOUSEUP | Event.SCROLL | Event.MOUSEWHEEL);
	}
	frameWin.onmouseup = PopupMenu_hidePopupMenus;

[teal]// Added for scroll wheel to hide menu[/teal]
	frameWin.onmousewheel = PopupMenu_hidePopupMenus;

[teal]// Added for scrolling to hide menu[/teal]
   [teal]//If we are browsing with IE, reassign frameWin[/teal]
    if (document.all) {    
        frameWin = window.top.window.frames["mainFrame"].document.body;
    }
	frameWin.onscroll = PopupMenu_hidePopupMenus;
  }
  listenerNotAttached = false;
}

[teal]// Hide the popup[/teal]
function PopupMenu_hidePopup() {
	if (this.divName != null) {
		if (this.use_gebi) {
			var obj = window.frames["mainFrame"].document.getElementById(this.divName);
			obj.style.visibility = "hidden";
		}
		this.unhideSelect(); [teal]// Added to re-display select drop-downs on main page.[/teal]
	}
	else {
		if (this.popupWindow && !this.popupWindow.closed) {
			this.popupWindow.close();
			this.popupWindow = null;
		}
	}
}

[teal]// Pass an event and return whether or not it was the popup DIV that was clicked[/teal]
function PopupMenu_isClicked(e) {
	if (this.divName != null) {
		if (this.use_layers) {
			var clickX = e.pageX;
			var clickY = e.pageY;
			var t = document.layers[this.divName];
			if ((clickX > t.left) && (clickX < t.left+t.clip.width) && (clickY > t.top) && (clickY < t.top+t.clip.height)) {
				return true;
			}
			else { return false; }
		}
		else if (document.all) { [teal]// Need to hard-code this to trap IE for error-handling[/teal]
			var t = window.frames["mainFrame"].event.srcElement;
			if (t) {
			  while (t.parentElement != null) {
				if (t.id==this.divName) {
					return true;
				}
				t = t.parentElement;
			  }
			}
			return false;
		}
		else if (this.use_gebi) {
			var t = e.originalTarget;
			while (t.parentNode != null) {
				if (t.id==this.divName) {
					return true;
				}
				t = t.parentNode;
			}
			return false;
		}
		return false;
	}
	return false;
}

[teal]// Check an onMouseDown event to see if we should hide[/teal]
function PopupMenu_hideIfNotClicked(e) {
	if (this.autoHideEnabled && !this.isClicked(e)) {
		this.hidePopup();
	}
}

[teal]// Call this to make the DIV disable automatically when mouse is clicked outside it[/teal]
function PopupMenu_autoHide() {
	this.autoHideEnabled = true;
}

[teal]// This global function checks all PopupMenu objects to see if they should be hidden[/teal]
function PopupMenu_hidePopupMenus(e) {
	for (var i=0; i<popupWindowObjects.length; i++) {
		if (popupWindowObjects[i] != null) {
			var p = popupWindowObjects[i];
			p.hideIfNotClicked(e);
		}
	}
}

Einstein47
“Evil abounds when good men do nothing.“ - Nelson R.
[&#91;]Starbase47.com]
 
Ok - call me an idiot.


I started with Matt Kruse's PopupWindow script. I changed it to be a dynamic DIV to hold my suckerfish menu navigation. However, Matt made his script so that multiple popups could be launched from the same page - I left that code in. Oops. It was creating an array of popupmenu objects each with its own event handler routines.

I thought that I was adding the event handlers multiple times. But that isn't the case. I'm probably not making much sense here. But even still - you earned that Star.

Sometimes just having someone stand over your shoulder is all you need to find the appropriate answer - Thanks again.

Einstein47
“Evil abounds when good men do nothing.“ - Nelson R.
[&#91;]Starbase47.com]
 
It is working now - you helped me solve the stack overflow with your comments about my code and the suggestion to use Firefox's error console to find the particular line number.

I just kept going figuring out even more of my script (ok, it really is Matt Kruse's script - I just modified it). So that it is doing EXACTLY what I need.

Thanks again - I really love the help at TEK-TIPS. I only hope I can return the favors.

Einstein47
“Evil abounds when good men do nothing.“ - Nelson R.
[&#91;]Starbase47.com]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top