the Fiddler's picture

OnResize called multiple times when changing WindowState

Project:The Open Toolkit library
Version:1.0.0-rc1
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed
Description

I have another issue with OnResize()

When setting (I use Windows 7 x64)
WindowState = WindowState.Fullscreen;
OnResize() is called 2 times, and when going back from fullscreen by setting
WindowState = WindowState.Normal
OnResize() is called 3 times. This is not you expect should happen.

In my project I need to do some initialization every time the window is resized.

protected override void OnResize(EventArgs e)
{
    Init();
}

And calling Init() three times causes a noticeable delay. I solved this with the following code that works, but is not very intuitive (and has a high probability of failing in an upcoming version or on another platform).

protected override void OnResize(EventArgs e)
{
    if (WindowBorder == WindowBorder.Resizable)
        MyResize();
}
 
protected override void OnWindowStateChanged(EventArgs e)
{
    if (WindowState == OpenTK.WindowState.Fullscreen)
       MyResize();
}
 
private new void MyResize()
{
    Init();
}

This is probably not a problem for that many, but it would be good if it could be fixed.


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

#1

Thanks for reporting this issue.

The window is actually resized multiple times when changing to/from fullscreen mode on Windows (most changes to WindowBorder or WindowState will first change the window into Resizable/Normal, apply the new value, and finally restore the window to its previous state if necessary. Some state changes cannot work reliably without this roundabout approach). In that sense, multiple events are correct, even if conceptually surprising.

I'm trying to determine whether there is a good way to suppress unnecessary resize events in a clean manner.

Edit: I should mention that, in my experience, it may be better to avoid reinitializing resources like FBOs inside the Resize event. It is usually slightly more efficient to set a flag inside the Resize event and check it at some later point (RenderFrame is a good place) - not only does this avoid unnecessary strain on the drivers and video memory, it also avoids UI lag while the user is dragging the window border.

the Fiddler's picture

#3

Status:open» in progress

r2625 of branches/1.0 fixes this issue on Windows. Working on a fix for Linux.

the Fiddler's picture

#4

Status:in progress» fixed

Linux part of the issue filed as #1626: GameWindow.Resize event is fired twice on Linux during startup.

the Fiddler's picture

#5

Version:1.0-beta-2» 1.0.0-rc1
Status:fixed» closed

Closing issues fixed in opentk-1.0.0-rc1.