Very odd null object RTE on FocusManager - apache-flex

I am getting this error, randomly when I start my application (and it's sub applications). As you can see the stack trace is rather useless, although through the debugger I can see the parent of container (second in the stack) is an MXML class that has a repeater that repeats another component.
Therefore I guess the component with the problem is that repeated component, although I am unsure what I can change to stop this from happening. If anyone can give me some insight to the FocusManager or the getFocus() function it would be really handy.
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at mx.managers::FocusManager/getFocus()[C:\autobuild\galaga\frameworks\projects\framework\src\mx\managers\FocusManager.as:542]
at mx.core::Container/createOrDestroyScrollbars()[C:\autobuild\galaga\frameworks\projects\framework\src\mx\core\Container.as:4571]
at mx.core::Container/createScrollbarsIfNeeded()[C:\autobuild\galaga\frameworks\projects\framework\src\mx\core\Container.as:4402]
at mx.core::Container/createContentPaneAndScrollbarsIfNeeded()[C:\autobuild\galaga\frameworks\projects\framework\src\mx\core\Container.as:4218]
at mx.core::Container/validateDisplayList()[C:\autobuild\galaga\frameworks\projects\framework\src\mx\core\Container.as:2734]
at mx.managers::LayoutManager/validateDisplayList()[C:\autobuild\galaga\frameworks\projects\framework\src\mx\managers\LayoutManager.as:622]
at mx.managers::LayoutManager/doPhasedInstantiation()[C:\autobuild\galaga\frameworks\projects\framework\src\mx\managers\LayoutManager.as:677]
at Function/http://adobe.com/AS3/2006/builtin::apply()
at mx.core::UIComponent/callLaterDispatcher2()[C:\autobuild\galaga\frameworks\projects\framework\src\mx\core\UIComponent.as:8733]
at mx.core::UIComponent/callLaterDispatcher()[C:\autobuild\galaga\frameworks\projects\framework\src\mx\core\UIComponent.as:8673]
Thanks
Rob

It seems that the problem was related to removing a SWF from the stage whilst is was still loading.
http://tech.groups.yahoo.com/group/flexcoders/message/147691
The solution would be to only remove SWFs from the stage once they are fully loaded.

Related

Modeling best practices

I worked some days on models that should be used with aframe, built with blender, exported to .obj. All went mostly very well, so the experience so far was very positive.
Until an object started to throw exceptions after some small changes at a model that worked well so far. The stacktrace is
aframe.js:sourcemap:27095 Uncaught TypeError: Cannot set property 'value' of undefined
at initMaterial (aframe.js:sourcemap:27095)
at setProgram (aframe.js:sourcemap:27191)
at WebGLRenderer.renderBufferDirect (aframe.js:sourcemap:26139)
at renderObjects (aframe.js:sourcemap:26961)
at WebGLRenderer.render (aframe.js:sourcemap:26698)
at THREE.VREffect.render (aframe.js:sourcemap:79772)
at HTMLElement.value (aframe.js:sourcemap:74829)
at bound (aframe.js:sourcemap:78097)
56aframe.js:sourcemap:27732 Uncaught TypeError: Cannot set property 'needsUpdate' of undefined
at markUniformsLightsNeedsUpdate (aframe.js:sourcemap:27732)
at setProgram (aframe.js:sourcemap:27325)
at WebGLRenderer.renderBufferDirect (aframe.js:sourcemap:26139)
at renderObjects (aframe.js:sourcemap:26961)
at WebGLRenderer.render (aframe.js:sourcemap:26698)
at THREE.VREffect.render (aframe.js:sourcemap:79772)
at HTMLElement.value (aframe.js:sourcemap:74829)
at bound (aframe.js:sourcemap:78097)
I found the problematic object, so I just rebuild it, no big deal this time.
But: When such a problem pops up later in the process, it might not be so easy to just rebuild. So my question is if there are any general tips to prevent such breakage. For example what to watch out for or what blender features to stay away from.
It's easy to rebuild the model now, but might be much harder later in the production process. I'd like to prevent this in the future.
Exporting from blender to gltf failed for me with pretty simple objects already.

"Cannot access a property or method of a null object reference." without any meaningfull stack trace

Regularly during my application run, I get
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at mx.managers::SystemManager/stageEventHandler()[C:\autobuild\3.4.0\frameworks\projects\framework\src\mx\managers\SystemManager.as:5649]
This is the full stack trace. Obviously, I guess there is something wrong, but I can't understand what.
Is there any way for me to find the origin of that bad behaviour ?
EDIT
Having added my SDK sources to my debugger, I can now say precisely which line it is :
private function stageEventHandler(event:Event):void
{
if (event.target is Stage)
mouseCatcher.dispatchEvent(event); // This is line 5649
}
mouseCatcher is indeed null. The current event target is indeed a Stage object, and event type contains the "deactivate" String. As event occurs at application startup (before I try to do any kind of user interaction), I guess it's a kind of initialization bug, but where ? and why ?
Look at the source code, this is always your best option. The 3.4 SDK is open source (datavisualization and the flash player itself aside) and you probably already have the source for it in your FlashBuilder/FlexBuilder install/sdks folder. Use grep or windows grep to find the file in question (or find, whatever floats your boat). Open the SystemManager file and check what's happening at that line, check for calls to the method (if it's public use grep again, if it's private you just need to look within the SystemManager). Try to understand why it gets to this point, as pointed out by some others it's likely a timing related issue where you're trying to access something before it has been assigned, in this case the SystemManager, you probably need to defer whatever action you're taking that is causing the error to a later part of the life-cycle (if you're using initialize event or pre-initialize try on creationComplete instead since that will be dispatched after the createChildren method is called).
Note: Mine is located here
C:\CleanFS\SDKs\flex\3.4.0.9271\frameworks\projects\framework\src\mx\managers
In my copy of SystemManager with the version of the SDK I have that line number doesn't make any sense since it's a block closure not an executable line so you'll have to look at your specific version.
It looks like you are using the Flex 3.4 SDK. Are you listening for the ADDED_TO_STAGE event when the application loads? Or doing anything with the Stage object on load? If so, you might be hitting a bug specific to the 3.4 SDK:
http://bugs.adobe.com/jira/browse/SDK-23332
The most obvious solution is to swap out the 3.4 SDK for a later version (3.4A, 3.5 or 3.6). You can do that here: http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+3
All of your code should be backwards compatable with the newer Flex 3 SDKs.

Flex Error #1009: Cannot access a property or method of a null object reference

I'm getting error while running a game I created with flex.
I know there has been some question about this, but my case is quite weird. I created a simple typing game that is running OK on my computer, but when I tried to deploy it online to facebook, I got those errors. I used code from the tutorial from adobe here http://www.adobe.com/devnet/facebook/articles/flex_fbgraph_pt4.html to deploy my flex game to facebook
This is the error message:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at FacebookUserStatusWeb/init()
at FacebookUserStatusWeb/___FacebookUserStatusWeb_Application1_creationComplete()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.core::UIComponent/dispatchEvent()
at mx.core::UIComponent/set initialized()
at mx.managers::LayoutManager/doPhasedInstantiation()
at mx.managers::LayoutManager/doPhasedInstantiationCallback()
And here is snippet of the init() function:
protected var text1:String="Text to be typed"; //hard-coded temporarily
protected const TIMER_INTERVAL:int = 10;
protected var t:Timer = new Timer(TIMER_INTERVAL);
protected var topURL:String=ExternalInterface.call('top.location.toString');
protected function init():void
{
t.addEventListener(TimerEvent.TIMER, updateTimer);
ProblemText.text = new String(text1);
Facebook.init("<my app id>",loginHandler);
currentState = (topURL) ? "loggedout": "loggedoutonfacebook";
}
Some notes:
1.my app id is my facebook app id which I prefer not to show
2.ProblemText is a richtext which I placed the paragraph to be typed by the player.
3.I have deleted the method Application1_creationComplete() but it still appears at the error listing
And also I am curious about the errors other than the first two. What do they mean?
Ah, and if it is helpful, I can post some more of the code
First: You're only seeing one error. Everything you see below the #1009 error is your stack trace, not additional errors.
The stack trace basically tells you the series of things that happened prior to the error occurring, with the most recent at the top. This is useful because often things which happen prior to the actual error you see will contribute to said error.
Second: The null object reference is occurring because something in your init() function tried to access a property in an object that doesn't exist, or an object that doesn't exist. One (slightly messy but effective) way to debug this would be to drop some trace statements in the code to see how far it gets before barfing with the error -- the idea being to isolate the specific line that's causing the problem. Once you've done that, you need to work backwards to figure out why the object or property you're trying to use is null. It could be something simple, like a typo, or it could be more complex. You'll have to sleuth it out, one way or another =)
Good luck!
Finally got the bug. Just in case people have the same case with me, what exactly happened is at my computer I simulated the game with just one state, but when I'm deploying to facebook I have several states (loggedin,loggedout,etc). In the init() I tried to access ProblemText Label that is not present in the current state.

ASP.NET Cannot evaluate expression because a thread is stopped at a point where garbage collection is impossible

I have a weird problem, I get an object from my DB, like this:
var user = BLL.Managers.Users.UserTmpManager.GetUser((int)customerID);
when I debug that code, and expand the user object, for each property I see the error as I mentioned at this topic's title. What causes it ?
unfortunately, it is still not being resolved, as I thought at the beginning..
I got this too, when I hit a NullReferenceException from a 3rd party control.
In this one case, I found that if I set a breakpoint before I hit the exception, I could then single step through the rest of the code without seeing the problem.
No idea why, but this worked for me - in this case at least.

How can addChild choose the wrong insertion index?

So, In a Flex app I add a new GUI component by creating it and calling parent.addChild(). However in some cases, this causes an error in the bowels of Flex. Turns out, addChild actually does:
return addChildAt(child, numChildren);
In the cases where it breaks, somehow the numChildren is off by one. Leading to this error:
RangeError: Error #2006: The supplied
index is out of bounds. at
flash.display::DisplayObjectContainer/addChildAt()
at
mx.core::Container/addChildAt()
at
mx.core::Container/addChild()
. . at
flash.events::EventDispatcher/dispatchEventFunction()
at
flash.events::EventDispatcher/dispatchEvent()
at
mx.core::UIComponent/dispatchEvent()
at
mx.controls::SWFLoader::contentLoaderInfo_completeEventHandler()
Is this a bug in Flex or in how I am using it? It kind of looks like it could be a threading bug, but since Flex doesn't support threads that is a bit confusing.
I have noticed that it most often occurs when re-parenting a UIComponent that is already on the display list. Are you re-parenting in this situation?
Could it be possible that you are adding a child before the component has been full initialized? Maybe try adding a child after Event.COMPLETE has been broadcast?
It may not support threads but it's still asynchronous...
numChildren doesn't validly reference an existing index in the children array. Arrays in AS3 are indexed starting at 0. This means that the last item in your array as for index numChildren - 1, not numChildren.
try addChildAt(child, numChildren - 1);
OK, like a dope, I was trying to add a child to a container even though it was already there, hence the confusing "wrong insertion index" message.
cf. http://forums.devshed.com/flash-help-38/scroll-pane-scroll-bars-not-working-818174.html - what you need to do is add children to a display object, and then set the source of the scrollpane to the be the display object. Kinda like this...
Code:
var myDisplay : DisplayObject = new DisplayObject();
myDisplay.addChild(myChild1);
myDisplay.addChild(myChild2);
myDisplay.addChild(myChild3);
myDisplay.addChild(myChild4);
ScrollPane.source = myDisplay;
ScrollPane.update();

Resources