Stuart Marks (one of the UI Controls “heavies”) has a great write-up on that “Infernal Scene Graph Warning Message”. You know, the one that showed up in JavaFX 1.2 in seemingly innocuous situations such as the following:
[jfx]
var g = bind Group {
translateX: someX
content: node
}
[/jfx]
In this code, whenever “someX” changes, a new Group is created and the node is mysteriously moved from this Group to the new one, and in the process the “infernal scenegraph warning message” is printed. Stuart goes into a lot of great history and detail to give context to the problem, but here is probably the money-quote as to why the warning message was useful:
When we added the enforcement code, we were surprised that it uncovered a few bugs and quite a number of questionable coding practices in our code, both in our runtime library and in our samples. In one case a node from the scene graph was also being used as a clip. This was illegal and didn’t actually work, but nobody had noticed up to that point. As for questionable coding practices, the enforcement turned up quite a number of cases where a scene graph was being constructed with some initial structure, and some code later on would rearrange the nodes into a different structure for no good reason. This caused the scene graph machinery to do a lot of extra work. The fix was to rewrite the code to create the scene graph in the desired structure, avoiding the rearranging and any error messages that the old code had caused.
Go visit his blog to get more information, I’m waiting for the second installment which I anticipate will go into all the nitty gritty details. Its kind of a cliff hanger because he doesn’t tell you what the final unanimous decision was regarding the warning message. Codify it as an error? Remove it? Something else?
I learned this technique from the X-Files TV show. There’s a cliffhanger *every* week. 🙂
I’ve seen the message plenty of times after 1.2 first came out. But they were all for legitimate scene graph abuses. So when I first read this entry, my reaction was that the example was a little contrived because you would just bind someX instead of the whole Group.
In other words: point taken, but surely situations in which this would interfere with legitimate code are rare in the real world?
Ha! While working on a new control this morning I just wrote this:
content: bind [
Group {
content: [
contentBackground,
panelControl.contentNode,
]
clip: bind contentClip
}
if (panelControl.title != “”) {
[titleBar, titleText]
} else {
null
}
]
Hello infernal scene graph warning message! I’m off to restructure my “contrived” code now. 🙂