TinyWindow icon indicating copy to clipboard operation
TinyWindow copied to clipboard

Crash on example window creation in visual studio 2017, windows 7, window 10 sdk

Open LiveAsynchronousVisualizedArchitecture opened this issue 8 years ago • 52 comments

I've had TinyWindow working with a previous version and msvc 2013. With the latest version combined with msvc 2017, it crashes on the following line:

glRenderingContextHandle = wglCreateContextAttribsARB(window->deviceContextHandle, NULL, attribs);

I've traced it back to where I think the problem starts - this line:

wglMakeCurrent(dummyDeviceContextHandle, glDummyContextHandle);

This returns 0, but does not set a windows error. The extension function addresses end up NULL and eventually it crashes on wglCreateContextAttribsARB(...) because the function address is NULL.

I've also noticed that there is minimal error handling. I used the following function that I found elsewhere to help debug this issue. It seems that there are dozens of windows functions that are not error checked, which I can understand for a prototype, but for the library to mature I think it will be very helpful.

auto GetLastErrorStdStr() -> std::string { DWORD error = GetLastError(); if (error) { LPVOID lpMsgBuf; DWORD bufLen = FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL ); if (bufLen) { LPCSTR lpMsgStr = (LPCSTR)lpMsgBuf; std::string result(lpMsgStr, lpMsgStr+bufLen);

  LocalFree(lpMsgBuf);

  return result;
}

} return std::string(); } #include #define printWinError std::cout << "\n" << LINE << " windows error " << GetLastErrorStdStr() << std::endl;

Let me know if I can do anything else to help!

Hey I'm having trouble reproducing this issue. I'm using VS studio 2017 community and MSCV v141 and v140. but still I cannot reproduce the crash

ziacko avatar May 25 '17 21:05 ziacko

Thanks for looking into it. One more element is that I didn't have a wgext.h file in the include install so I used one from the Khronos website.

ok so I installed the latest version of wglext.h but still no crash

ziacko avatar May 26 '17 10:05 ziacko

Thanks again for looking into it. On startup there is actually an error of "The specified module could not be loaded." I'll see what I can figure out about that. The Window utility Dependency Walker doesn't show anything out of the ordinary, just KERNEL32.dll USER32.dll GDI32.dll and OPENGL32.dll

it could be your driver. if you have an NVIDIA card that might be trouble as I don't have a NVIDIA card to dev with

ziacko avatar May 26 '17 14:05 ziacko

It is possible but I don't think it is likely since glfw and even a previous version of TinyWindow.h have both worked before. I do have two monitors running at different refresh rates however. I took a quick look at glfw and it looks like they loop through lots of pixel formats on initialization. I'm not certain if the pixel format is even affecting the problem I'm having, but it is a a difference I noticed at a glance.

The module not loaded windows error seemed to be from compiling statically. When I use the debug DLL in msvc it goes away, though this does't solve the wgl problem.

Here is what I've been running: https://github.com/LiveAsynchronousVisualizedArchitecture/lava/tree/master/TinyWindow

it does seem like the most obvious answer. right now I'll be adding the ability to enumerate through pixel formats. I'm thinking of storing it either in the monitor class or making it a struct and having the window or manager store the information in a list. lucky i have the superbible to help me out

ziacko avatar May 26 '17 16:05 ziacko

you could change up the RGB | depth values in the tWindow constructor to see what works for you. you could debug GLFW to see what RGB|depth values it has picked for you and plug them into TinyWindow to hack it

ziacko avatar May 26 '17 17:05 ziacko

That is true, and a good idea. It would at least get rid of one possible source of error.

is this what you see?

tinywindow

ziacko avatar May 26 '17 17:05 ziacko

Close - it crashes on wglCreateContextAttribsARB because the function pointer itself is NULL.

tinywindow 1

if its null then It hasn't been loaded at all which means it's not supported. is the EXT version of the function NULL too?

ziacko avatar May 26 '17 18:05 ziacko

Yes. It doesn't get to that point normally though, because wglGetExtensionsStringARB and wglGetExtensionsStringEXT are both NULL, which makes the function return. If I comment out the error check, all the calls to wglGetProcAddress return NULL.

are any of the other extensions being loaded? if none are that could mean the dummy context that I create in order to load these extensions may not be working on your setup

ziacko avatar May 26 '17 18:05 ziacko

Right. None of the extensions load as far as I can tell. dummyDeviceContextHandle from GetDC() is not NULL however its unused struct member can't be read by the msvc debugger (should it contain something?)

wglCreateContext returns a non-null handle with unused set to 0, then wglMakeCurrent returns false.

None of these functions create a windows error from what I've seen.

ok by default the openGL version TinyWindow uses is 4.5. make sure your GPU can handle that. also change it from a core context to a compatibility context. just in case while im researching this

ziacko avatar May 26 '17 18:05 ziacko

Ok. I have a 970, but I have been using glfw with 3.3 so it is certainly worth a try.

How do I change the version? From what I can tell these errors all happen before any version numbers are used.

the dummy context does'nt use version numbers because it need to use the old context creation system in order to load the extensions for the new context creation system that uses those numbers

ziacko avatar May 26 '17 19:05 ziacko

That makes sense, but the crash comes from the extensions not loading, so I don't get to the point where I can choose the version.

you can change the verision in the constructor for the window class as glMajor and glMinor parameters

ziacko avatar May 26 '17 19:05 ziacko

in Windows_CreateDummyContext can you do some error checks before and after the dummy context is made. maybe the dummy is invalid

ziacko avatar May 26 '17 19:05 ziacko

I see the glMajor and glMinor variables in the tWindow constructor, but that is never hit.

I'm checking for windows errors before and after the GetDC(GetDesktopWindow()); line and not getting anything. dummyDeviceContextHandle isn't NULL so I'm not sure what else to check.

in CreateDummyContexts try this. if it hits the error message then im out of ideas. make sure to comment out the code between pfd.redBits to pfd.Depthbits. this should widen the pool for creating dummy contexts

void Windows_CreateDummyContext() { dummyDeviceContextHandle = GetDC(GetDesktopWindow()); PIXELFORMATDESCRIPTOR pfd; pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR); pfd.nVersion = 1; pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER | PFD_SUPPORT_OPENGL; pfd.iPixelType = PFD_TYPE_RGBA; pfd.cColorBits = 24;

		int LocalPixelFormat = ChoosePixelFormat(dummyDeviceContextHandle,
			&pfd);

		if (LocalPixelFormat)
		{
			if (!SetPixelFormat(dummyDeviceContextHandle, LocalPixelFormat, &pfd))
			{
				printf("Error: dummy context pixel format is invalid\n");
				return;
			}
		}

		glDummyContextHandle = wglCreateContext(dummyDeviceContextHandle);
		if (!glDummyContextHandle)
		{
			printf("Error: dummy context creation failed\n");
			return;
		}

		if (!wglMakeCurrent(dummyDeviceContextHandle, glDummyContextHandle))
		{
			printf("failed to make dummy context current\n");
			return;
		}
	}

ziacko avatar May 26 '17 19:05 ziacko

Ok, I will try this, though it may be a few hours later.

no worries i got to sleep in a few hours anyway

ziacko avatar May 26 '17 19:05 ziacko

just checking in. how'd it go?

ziacko avatar May 27 '17 20:05 ziacko

I wasn't able to get it to work with the minimal settings. I took another look at glfw's source and didn't see anything that jumped out at me as too different. I think the next step might be for me to step through glfw to see it work. If I do that, maybe I can learn a lot.

Ok i made another update that if the dummy context fails, then TinyWindow will create windows using the old fashioned method. I doubt this will solve the problem but now you should at lest still be able to work somewhat. plus some more smaller updates

ziacko avatar May 28 '17 11:05 ziacko

Your new update works to get a window up for me. The window title works and closing the window works. The screen is white however, even though it looks like it should be clearing to 0.25 grey.

Also I put

Platform_InitExtensions(); on line 2568 to see if the extensions would load correctly and they did.

Edit: 2658