kring789's picture

WinGLNative's window class registration strategy does not take AppDomains into account

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

WinGLNative has a static counter that it increments each time an instance is created. It uses this counter to form the name of the window class that is registered in CreateWindow. This is necessary because window classes within a process must be unique.

The problem with this strategy is that each AppDomain gets its own copy of all statics. So the window class name is unique only within the AppDomain, not within the process. So if you use WinGLNative in two different app domains in the same process, you'll get exceptions like this:

OpenTK.PlatformException : Failed to register window class. Error: 1410
at MiniGlobe.Renderer.Device.CreateWindow(Int32 width, Int32 height)

Error code 1410 indicates that the class is already registered.

This may all sound academic, but it's actually fairly important because NUnit runs tests in a separate AppDomain, and it creates a new AppDomain for each new test run. So this bug makes it impossible to run tests multiple times without restarting NUnit.

The attached patch fixes this problem, and simplifies the code, by using a Guid for the window class name. I also eliminated the static counter completely by using the fact that the ID in a call to SetTimer only needs to be unique within a window, not within the entire process. So I just hard-coded a timer ID of 1 instead of using the static counter. The patch is hereby contributed to the public domain.

AttachmentSize
WinGLNative.patch2.22 KB

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

Version:1.0-beta-3» 0.9.x-dev
Status:open» fixed

Thanks, I have applied the patch to r2622 of branches/1.0 and will backport to trunk.

the Fiddler's picture

#3

Version:0.9.x-dev» 1.0.0-rc1
Status:fixed» closed

Closing issues fixed in opentk-1.0.0-rc1.