
OnResize before OnLoad event
Posted Thursday, 15 October, 2009 - 13:14 by iliak inIn my form, I have two GlControl (from SVN). In each of them in the OnResize and OnLoad events, I put a trace log. Here's the output :
GLTileControl_Resize
Une exception de première chance de type 'System.NullReferenceException' s'est produite dans OpenTK.GLControl.dll
GLTextureControl_Load
GLTileControl_Load
GLTextureControl_Resize
GLTileControl_Resize
GLTextureControl_Resize
How about the first Resize event before the Load event ? Is it normal ? Shoudn't the Load event be the first one to be caught ? Why only one GlControl throw this resize and not the other one ?
In the designer code, GLTextureControl is "newed" first, and after GLTileControl is newed. Nothing change if I swap this order.
Here's the source code here and here for the designer.
And what about the Null Reference exception thrown ???


Comments
Re: OnResize before OnLoad event
Am I correct to assume that the exception is raised in line 378 (
GLTileControl.MakeCurrent())?This "Resize-before-Load" behavior is surprising but normal (as far as I know!) It seems to affect all classes that inherit from Control, when their Size property is set before their handles are created (lines 81 and 227 of the designer code).
I am curious: can you please hook and log the HandleCreated event for the two GLControls? In theory, it should be raised before any Resize events - but this doesn't seem to be the case here.
Re: OnResize before OnLoad event
line 368 here.
Here's with a better error handler :
GLTileControl_Resize
Une exception de première chance de type 'System.NullReferenceException' s'est produite dans OpenTK.GLControl.dll
Exception "La référence d'objet n'est pas définie à une instance d'un objet."
~GLTileControl_Resize
GLTextureControl_Resize
Une exception de première chance de type 'System.NullReferenceException' s'est produite dans OpenTK.GLControl.dll
Exception "La référence d'objet n'est pas définie à une instance d'un objet."
~GLTextureControl_Resize
GLTextureControl_Load
GLTileControl_Load
GLTileControl_Resize
~GLTileControl_Resize
GLTextureControl_Resize
~GLTextureControl_Resize
Should I handle this case (it's a normal situation) or is it anormal ?
Re: OnResize before OnLoad event
That's what I'm trying to determine. This is normal but the GLControl should be safe to during the Resize event (which is why I'd like to know when
GL[Tile|Texture]Control.HandleCreatedis called exactly).You can work around the issue by checking whether the GL[Tile|Texture]Control.Context property is null - but I'd like to fix this inside OpenTK, if at all possible.
Re: OnResize before OnLoad event
GLTileControl_Resize
Une exception de première chance de type 'System.NullReferenceException' s'est produite dans OpenTK.GLControl.dll
Exception "La référence d'objet n'est pas définie à une instance d'un objet."
~GLTileControl_Resize
GLTextureControl_Resize
Une exception de première chance de type 'System.NullReferenceException' s'est produite dans OpenTK.GLControl.dll
Exception "La référence d'objet n'est pas définie à une instance d'un objet."
~GLTextureControl_Resize
GLTextureControl_HandleCreated
GLTextureControl_Load
GLTileControl_HandleCreated
GLTileControl_Load
GLTileControl_Resize
~GLTileControl_Resize
GLTextureControl_Resize
~GLTextureControl_Resize
Re: OnResize before OnLoad event
Thanks. To be honest, I think that's rather braindead on the part of WinForms - they are raising events before the Control has been created!
I have added a workaround to rev. 2337 - the Resize event should no longer cause NullReferenceExceptions. However, you still need to keep in mind that Resize event may occur before the Load event in some (most) cases.
Re: OnResize before OnLoad event
Ok,
Should I post an issue for this or is it ok for you ?
Thanks !
Re: OnResize before OnLoad event
Only if the issue still occurs. Otherwise, it's fine like this (since it's solved already).
Re: OnResize before OnLoad event
Ok, it works fine.
As a side effect, it removes an issue i had when I opened the form / closed it and after reopened it, GLControl have invalid context...
Good news :)