Skip to content

Commit 5507fa0

Browse files
committed
Merge branch 'master' into play-with-transitions
Conflicts: PyTutorGAE/js/pytutor.js
2 parents 632160e + 831e202 commit 5507fa0

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

PyTutorGAE/js/pytutor.js

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,6 +1094,8 @@ ExecutionVisualizer.prototype.precomputeCurTraceLayouts = function() {
10941094
}
10951095

10961096

1097+
var heapPtrSrcRE = /__heap_pointer_src_/;
1098+
10971099
// The "3.0" version of renderDataStructures renders variables in
10981100
// a stack, values in a separate heap, and draws line connectors
10991101
// to represent both stack->heap object references and, more importantly,
@@ -1120,6 +1122,19 @@ ExecutionVisualizer.prototype.renderDataStructures = function() {
11201122
// Heap object rendering phase:
11211123

11221124

1125+
// This is VERY crude, but to prevent multiple redundant HEAP->HEAP
1126+
// connectors from being drawn with the same source and origin, we need to first
1127+
// DELETE ALL existing HEAP->HEAP connections, and then re-render all of
1128+
// them in each call to this function. The reason why we can't safely
1129+
// hold onto them is because there's no way to guarantee that the
1130+
// *__heap_pointer_src_<src id> IDs are consistent across execution points.
1131+
myViz.jsPlumbInstance.select().each(function(c) {
1132+
if (c.sourceId.match(heapPtrSrcRE)) {
1133+
myViz.jsPlumbInstance.detachAllConnections(c.sourceId);
1134+
}
1135+
});
1136+
1137+
11231138
// Key: CSS ID of the div element representing the stack frame variable
11241139
// (for stack->heap connections) or heap object (for heap->heap connections)
11251140
// the format is: '<this.visualizerID>__heap_pointer_src_<src id>'
@@ -1318,8 +1333,6 @@ ExecutionVisualizer.prototype.renderDataStructures = function() {
13181333

13191334
var dstDivID = myViz.generateID('heap_object_' + objID);
13201335

1321-
// TODO: we might be able to further optimize, since we might be re-drawing
1322-
// HEAP->HEAP connections when we can just keep the existing ones
13231336
assert(!connectionEndpointIDs.has(srcDivID));
13241337
connectionEndpointIDs.set(srcDivID, dstDivID);
13251338
//console.log('HEAP->HEAP', srcDivID, dstDivID);
@@ -1574,6 +1587,10 @@ ExecutionVisualizer.prototype.renderDataStructures = function() {
15741587
var heapObjID = myViz.generateID('heap_object_' + getRefID(val));
15751588
connectionEndpointIDs.set(varDivID, heapObjID);
15761589
//console.log('STACK->HEAP', varDivID, heapObjID);
1590+
1591+
// GARBAGE COLLECTION GOTCHA! we need to get rid of the old
1592+
// connector in preparation for rendering a new one:
1593+
myViz.jsPlumbInstance.detachAllConnections(varDivID);
15771594
}
15781595

15791596
//console.log('CHANGED', varname, prevValStringRepr, valStringRepr);
@@ -1717,6 +1734,10 @@ ExecutionVisualizer.prototype.renderDataStructures = function() {
17171734
var heapObjID = myViz.generateID('heap_object_' + getRefID(val));
17181735
connectionEndpointIDs.set(varDivID, heapObjID);
17191736
//console.log('STACK->HEAP', varDivID, heapObjID);
1737+
1738+
// GARBAGE COLLECTION GOTCHA! we need to get rid of the old
1739+
// connector in preparation for rendering a new one:
1740+
myViz.jsPlumbInstance.detachAllConnections(varDivID);
17201741
}
17211742

17221743
//console.log('CHANGED', frame.unique_hash, varname, prevValStringRepr, valStringRepr);
@@ -1746,9 +1767,12 @@ ExecutionVisualizer.prototype.renderDataStructures = function() {
17461767
myViz.jsPlumbInstance.connect({source: varID, target: valueID});
17471768
});
17481769

1770+
/*
17491771
myViz.jsPlumbInstance.select().each(function(c) {
1750-
console.log('CONN', c.sourceId, c.targetId);
1772+
console.log('CONN:', c.sourceId, c.targetId);
17511773
});
1774+
*/
1775+
//console.log('---', myViz.jsPlumbInstance.select().length, '---');
17521776

17531777

17541778
function highlight_frame(frameID) {

0 commit comments

Comments
 (0)