NVidia OpenGL display driver lost connection error troubleshooting

In recent operating systems and more recent games you may have encountered the following message every now and then.

Sometimes the message won’t show at all depending on your windows settings and or game.

“The NVIDIA OpenGL driver lost connection with the display driver due to exceeding the Windows Time-Out limit and is unable to continue. The application must now close.
Error code: 7″

nvidia_opengl_lost_connection_error

This is actually a good thing which prevents freezes of your whole operating system. In some cases however we want to workaround it by increasing the time before timeout. You can read more about this on Microsoft Support.

We do this by editing a key in the windows registry. For example I have to change this to 8 seconds or so in order to take high resolution screenshots in SpaceEngine.

Warning! Before proceeding you should know that setting this to a bad value could mess up things on your computer. Create a system restore point and backup your data!

NOTE! This affects all graphics programs and games on your computer. I recommend restoring the value after you’re done testing.

Proceed on your own risk!

Option 1: Right and select save as on any of the registry patches. Double click on them in explorer to install

TdrDelay-8sec.reg – TdrDelay set to 8 seconds (this should be enough for SpaceEngine)
TdrDelay-32sec.reg – TdrDelay set to 32 seconds (try this if error still shows)
TdrDelay-uninstall.reg – This removes the registry value which will use windows default. (Windows default is 2 seconds)

Option 2: Manually edit the registry

Open regedit.exe and navigate to:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\GraphicsDrivers

Create a new key DWORD32 and name it exactly TdrDelay
I tried 64 but it wouldn’t work for me even though I use a 64 bit OS.
Remember that this key name is cAsE sEnSiTiVe.

Double click on the key, choose decimal value and set it to the delay that you want.
I recommend trying 8 to 32. Delete the key when you’re done.

Here is a tiny gif animation. Please excuse the Swedish 🙂

TdrDelay

If you have any additional information to add or if I got anything wrong, please don’t hesitate to leave a comment!
Cheers

Advertisements

Add scaled timestamps to photos using ImageMagick

Here is one way to add timestamps quickly to lots of photos using open source tools and a script.

The image editing is done using ImageMagick  convert.exe and identify.exe

ImageMagick is a free to use open source collection of command line tools for image editing, identifying, manipulation and much more.

stamp

This script will go through all JPG, JPEG, GIF and PNG files inside the current folder, make copies of them in a separate folder and add date and time saved (burned) into the image. The operation is lossy hence it only modifies copies of the files. Date and time is retrieved from the metadata tag Exif.Image.DateTimeOriginal. If the images lack this tag they will be stamped “No timestamp”.

The timestamp font size and placement on the photo will scale in percentage according to the width and resolution of the photo.

If you want to change colors or such you will need to edit the script manually. Here are some examples of photos I’ve taken with added timestamps:

If these kind of timestamps are good enough for you, you’ve found the right post!

Instructions

timestamp

Option a) – quick

1. Download the script (mirror) together with portable ImageMagick convert.exe and identify.exe
MD5: a5363bef4aafbe979dcac875f7f2e263

2. Extract all files in the folder where you keep the images that you wish to add timestamps to

3. Double click on add timestamps.bat to start the process.

A black window should pop up showing the image conversion process in ImageMagick.

timestamp

4. When done you should see a folder named stamped with copies of the files with added timestamps!

Option b) – manual

1. Download ImageMagick from the windows portable edition here and place convert.exe and identify.exe in the same directory where you place the script. Alternately you can use the files supplied in the download above.

2. Copy and paste the code from below into your favorite plain text editor like notepad, notepad2 or notepad++

3. Save it with whichever name you prefer as long as you end the name with the file extension .bat for example add timestamps.bat

4. Double click on the bat file to start the process!

Batch script to copy and paste

@echo off & cls
rem enable variables referencing themselves inside loops
SetLocal EnableDelayedExpansion

rem optional settings
set fontcolor=#FFD800
set fontoutlinecolor=#000000
set fontstyle="Arial-Bold"

rem create a new folder where the stamped images will be placed
mkdir stamped

rem loop through all jpg png jpeg and gif files in the current folder
for /f "delims=" %%a in ('dir /b /A:-D /T:C "%cd%\*.jpg" "%cd%\*.png" "%cd%\*.jpeg" "%cd%\*.gif"') do (
	rem retrieve image date and time
	SetLocal EnableDelayedExpansion
	for /f "tokens=1-2" %%i in ('identify.exe -ping -format "%%w %%h" "%cd%\%%a"') do set W=%%i& set H=%%j

	rem retrieve image timestamp to perform size and distance calculations on
	SetLocal EnableDelayedExpansion
	for /f "tokens=1-2 delims=" %%k in ('identify -format "%%[EXIF:DateTimeOriginal]" "%cd%\%%a"') do set timestamp=%%k
	
	rem set timestamp to no timestamp if there is no timestamp
	if "!timestamp!" == "" (
		set timestamp=No timestamp
	)
	
	rem print some information about the process
	echo %%a is !W! x !H! stamp !timestamp! ...

	rem set timestamp size to a fourth of the screen width
	set /A timestampsize = !W! / 3

	rem set timestamp offset distance from side of the screen
	set /A timestampoffset = !W! / 20

	rem set timestamp outline relative size
	set /A outlinewidth = !W! / 600

	rem echo !timestampsize! !timestampoffset!
	
	rem create a custom image with the timestamp with transparent background and combine it with the image
	convert.exe ^
	-verbose ^
	-background none^
	-stroke !fontoutlinecolor! ^
	-strokewidth !outlinewidth! ^
	-font !fontstyle! ^
	-fill !fontcolor! ^
	-size !timestampsize!x ^
	-gravity center label:"!timestamp!" "%cd%\%%a" +swap ^
	-gravity southeast ^
	-geometry +!timestampoffset!+!timestampoffset! ^
	-stroke !fontoutlinecolor! ^
	-strokewidth !outlinewidth! ^
	-composite "%cd%\stamped\%%a"

	endlocal
	endlocal
	echo.
)
endlocal
echo Complete!
pause

More info

I also wrote a VBScript version of this operation as well but It would have a lot of black windows popping up being quite annoying.

Unfortunately hiding windows gets trickier when using VBScript when you also need to retrieve the return value from command line utilities.

If you want to check out the vbscript anyway you can still get it here (mirror) (git)


HTML image gallery generator using VBScript and ImageMagick

Update 2015-06-11: Added msdos short paths to (hopefully) avoid unicode character errors

This VBScript will create a very basic HTML image gallery of all image files placed in the same directory as the script.

It generates thumbnails using ImageMagick and links to the original images.

ImageMagick is a free to use open source collection of command line tools for image editing, identifying, manipulation and much more.

Result

htmlgallery

Instructions

Option a) – quick

gallery script

1. Download the script (mirror) together with portable ImageMagick mogrify.exe in this zip file.
MD5: 704945e2e269aa222ea321a9eff0871f
(github)

2. Extract both files in the same folder where you keep the images that you wish to use in your gallery

3. Double click on CreateHTMLImageGallery.vbs to start the procedure.

A black window should pop up showing the image conversion process in ImageMagick. The window will close when the thumbnails have been created and a preview window will open in your browser.

cmdwindow

4. When done you should see a folder named thumbs with low resolution copies (thumbnails) of your images inside it.

Option b) – manual

1. Download ImageMagick from the windows portable edition here and place mogrify.exe in the same directory where you place the script. Alternately you can use the file supplied in the download above.

2. Copy and paste the code from below into your favorite plain text editor like notepad, notepad2 or notepad++

3. Save it with whichever name you prefer as long as you end the name with the file extension .vbs for example CreateHTMLImageGallery.vbs.

4. Double click on the script to start the process!

 VBScript to copy and paste

 

'Simple html gallery maker using ImageMagic mogrify.exe
'Written by Nicklas H https://nirklars.wordpress.com

'Updated 2015-06-11

'---DECLARATIONS SECTION---

Set args = Wscript.Arguments
Set FSO = CreateObject("Scripting.FileSystemObject")
Set SHELL = CreateObject("WScript.Shell")

'Get proper current directory
SHELL.CurrentDirectory = FSO.GetParentFolderName(Wscript.ScriptFullName) 
'Declare folder to check files in
Set objFolder = FSO.GetFolder(SHELL.CurrentDirectory)
Set colFiles = objFolder.Files

'Declare global variables
Dim OutputFile 
Dim OutputFileContent
Dim FirstLineCheck

'You can change this to gallery.html or whatever you wish
OutputFile = SHELL.CurrentDirectory & "\index.htm"
'Change this if you want another thumbnail size or quality
ImageMagicArguments = "-thumbnail 200x -quality 65 -verbose"

'---PROGRAM SECTION---

'Check if a gallery already exists, if so then delete if
DelFile(OutputFile)

'Regular html gallery code stuff, this is just an example
W("<html>")
W("	<head>")
W("	<title>Image Gallery</title>")
W("		<style>  ")
W("		a:link")
W("		{")
W("			text-decoration: none;")
W("			color: black;")
W("		}")
W("		a:visited")
W("		{")
W("			color: black;")
W("		}")
W("		a:hover")
W("		{")
W("			color: red;")
W("		}")
W("		img ")
W("		{")
W("			border-style: solid;")
W("			border-width: 2px;")
W("			margin: 2px;")
W("			padding: 0px;")
W("			}")
W("		</style>")
W("	</head>")
W("	<body>")

' Breakdown of the <img> tag to be pieced together in the loop
ImagePart1 = "		<a href='"
ImagePart2 = "'><img src='thumbs/"
ImagePart3 = "'></a>"

' Go through every file in the folder and create the <img> tag and stuff
For Each objFile in colFiles
	complies = false
	
	'check file extensions
	if InStr(objFile.Name,".jpg") > 0 then 
		complies = true
	elseif InStr(objFile.Name,".png") > 0 then 
		complies = true
	elseif InStr(objFile.Name,".jpeg") > 0 then 
		complies = true
	elseif InStr(objFile.Name,".gif") > 0 then 
		complies = true
	else
		'skip
	end if
	
	if complies = true then
		W(ImagePart1 & objFile.Name & ImagePart2 & objFile.Name & ImagePart3)
	end if
	
Next

'Final part of the html code
W("	</body>")
W("</html>")

'Write the file at once to save disk access times
SaveFile()

'Check if imagemagick is there
if FSO.FileExists(SHELL.CurrentDirectory & "\mogrify.exe") then
	'Create folder and launch imagemagick
	MkDir(SHELL.CurrentDirectory & "\thumbs")
	command = Quote(SHELL.CurrentDirectory & "\mogrify.exe") & " -path " & Quote(ShortPath(SHELL.CurrentDirectory) & "\thumbs") & " " & ImageMagicArguments & " " & Quote("*")
	'start imagemagick
	SHELL.run command, 1, true
	'open the gallery in your browser
	SHELL.run Quote(OutputFile), 1, true
else
	msgbox "Unable to create thumbnail images. Please put ImageMagick mogrify.exe in the script folder and retry!"
end if

'---FUNCTIONS SECTION---

'Function to get short msdos path to work with unicode folder names
function ShortPath(myPath)
	ShortPath = FSO.GetFolder(myPath).ShortPath
end function

'Function to put quotation marks around paths
function Quote(this)
  Quote = Chr(34) & this & Chr(34)
end function

'Write a new line in the output file
Function W(strLine)
	'Skip line break on the first entry
	if FirstLineCheck = false then
		OutputFileContent = strLine
		FirstLineCheck = true
	else
		OutputFileContent = OutputFileContent & vbNewLine & strLine
	end if
End Function

'Save the output file
Function SaveFile()
    Set stream = FSO.OpenTextFile(OutputFile, 2, True)
    stream.write OutputFileContent
    stream.close
	OutputFileContent = "" 'Clear memory
End Function

'Create folder until success
function MkDir(myFolder)
	do
		'Fix env strings
		myFolder = translateEnvStr(myFolder)
		
		Err.Clear
		On Error Resume Next
		if FSO.FolderExists(myFolder) = true then 
			exit do
		else
			FSO.CreateFolder(myFolder)
			if ErrorMessage() = false then
				exit do
			end if
		end if
		WScript.Sleep 1000
	loop
end function

'Delete a file if it exists, wait if it doesnt work and retry
function DelFile(myFile)
	do
		'Fix env strings
		myFile = translateEnvStr(myFile)
		
		Err.Clear
		On Error Resume Next
		if FSO.FileExists(myFile) then
			FSO.DeleteFile(myFile)
			if ErrorMessage() = false then
				exit do
			end if
		else
			exit do
		end if
		WScript.Sleep 1000
	loop
end function

'Function that translates all EnvironmentStrings into real paths from inside a larger string. Lets call it strLargeEES.
function translateEnvStr(strLargeEES)
	'Count the number of % characters in the supplied string. This is done by removing all of the % from strLargeEES and subtract it from the original strLargeEES.
	intCharNum = Len(strLargeEES) - Len(Replace(strLargeEES, "%", ""))
	
	'Since there are two % signs for each EnvironmentString that means we divide the total number of EnvironmentStrings by...
	intExpandedStringsNum = intCharNum/2
	
	'Loop through all of the EnvironmentStrings. Because we need to translate each one separately.
	for i = 1 to intExpandedStringsNum
		'Cut out the part to the right of %
		strFirstCut = Right(strLargeEES,Len(strLargeEES)-InStr(strLargeEES,"%"))
		'Cut out the part to the left of %
		strSecondCut = Left(strFirstCut,InStr(strFirstCut,"%")-1)
		
		'The result from our cutting reveals the first EnvironmentString!
		result = "%" & strSecondCut & "%"
		'We translate this to the real folder by using a shell object
		translated = SHELL.ExpandEnvironmentStrings(result)
		
		'When we are done we replace the original EnvironmentString with the translated in strLargeEES
		strLargeEES = Replace(strLargeEES,result,translated)
	'Repeat
	next
	
	'When done return the whole translated string to the function call
	translateEnvStr = strLargeEES
end function

 


SpaceEngine and high resolution screenshots

Scroll down for the instructions to capture high resolution screenshots exceeding your screen size.

If you’re here only for the AutoHotkey script to force window sizes click here.

Update 2016-01-11: In recent versions of SpaceEngine (V 0.973 or higher) you may encounter crashes with OpenGL error messages. Please see here on how you might counter these issues.

BackgroundAldebaran 9.3

I’ve been playing around in a game/simulator named SpaceEngine lately. It’s a simulator exploration game allowing you to travel parts of the known universe and beyond (via procedurally generated) galaxies, star systems and planetary terrain.

If you haven’t checked it out yet you really should! It doesn’t matter if your behind a desk dreaming of being an astronaut, fantasy/scifi stellar explorer extraordinare, a space nut or just mildly fascinated by pretty astronomy photos. It’s free http://en.spaceengine.org/

Special note to security nuts: Space Engine is not open source but I’ve been running version 0.9.7.1 and 0.9.7.2 and my whitelist firewall log hasn’t caught any attempt to even connect to the internet. Considering the large helpful community and experienced users involved in the project it would get some bad rep quickly if it started doing bad things.

Continuing exploring… Spread across this post are some wonderful screenshots that I’ve captured so far. Unfortunately these examples are not all 4K images. 🙂

Taking regular screenshots in SpaceEngine is easy, press F11 to capture the screen without the GUI. The screenshots you capture will end up in this folder: \SpaceEngine 0.972\screenshots\

extrasolar_comet_by_nirklars-d8epalq_png

Setting the proper screenshot file format

Wait! Before you go on a screenshot frenzy there is an important option you need to know about. This option makes sure that the screenshots you save are stored in the best quality. This option is not available from inside the game GUI so you need to manually edit a text file in the config directory.

1. Browse to the following file from the place where you installed SpaceEngine:
\SpaceEngine 0.972\config\main.cfg

2. Open main.cfg it in a text editor like notepad or notepad++ and scroll down until you find this line.

edit

3. Replace “jpg” with “png”. Save the file and restart SpaceEngine. Your screenshots will now be taken in high quality PNG image files instead of lossy JPEGs

Exomoon of binary red dwarfs

In game configuration

To get more visuals out of your experience keep tinkering around with the settings in game. To open the settings menu move your mouse to the lefthand side of the screen for the menu to appear. Then click on the bottom cogwheel icon.

There’s also a hotkey by holding down CTRL and pressing F4 (CTRL+F4) which opens the graphics menu directly.

When exploring terrain on planets what you want to do is to increase the Level of Detail (LOD). Be careful changing this value; it will quickly eat up your graphics card memory and can cause freezes and crashes.

Avoid loosing your position after crashes by saving your location often using F6.

Want even greater visuals using higher resolution screenshots? Keep reading!

marred_tarantula_impact_remnant_3_by_nirklars-d8dn1za_pngBreaking the 1920 x 1080 barrier

After playing around in SpaceEngine as you might have noticed, you can’t capture screenshots higher than your screen max resolution. Not owning a real 4K monitor in order to do this you will require hacks or tricks to manipulate the program to do what you want. Now there are many different programs that can do this to other games or games in general. Some may contain malware or adware. Here is an alternate way using solely open source tools. AutoHotkey specifically.

AutoHotkey is a very versatile and portable scripting language for windows intended to help you with hotkeys, keyboard and mouse automation and moooore. Here are some instructions on how to use a basic script to force a window into any size that you want. Even sizes that exceed your monitor max resolution.

Beware however, forcing programs to do something they were never intended to do is risky. Expect them to crash or freeze; side effects may include hairloss, overfeeding or brain malfunction. (not really… maybe)

Before attempting the following; save your progress in all open programs first! You have been warned!

 AutoHotkey script to force window sizes

This script will work for resolutions exceeding your monitors max resolution.

It’s written to toggle the size of the window that currently has focus whenever you press the key F12. You can change this key into anything you want by editing the following text in the script. For example changing the first line:
F12::
Into:

^F12::
Will toggle it when pressing CTRL+F12

+F12::
Will toggle when pressing SHIFT+F12

^+F12::
Will toggle when pressing CTRL+SHIFT+F12.

Get it? The symbols represent modifiers on your keyboard.  Feel free to read more about using AutHotkey hotkeys.

 AutoHotkey 4096 x 2160 window size script usage instructions

1. Download and install AutoHotkey if you haven’t already.

2. Copy and paste the following into your favourite text editor. Or download the script here (mirror) (Right click and select save as)

F12::
WinGet, TempWindowID, ID, A
If (WindowID != TempWindowID)
{
  WindowID:=TempWindowID
  WindowState:=0
}
If (WindowState != 1)
{
  WinGetPos, WinPosX, WinPosY, WindowWidth, WindowHeight, ahk_id %WindowID%
  WinSet, Style, ^0xC40000, ahk_id %WindowID%
  WinMove, ahk_id %WindowID%, , 0, 0, 4096, 2160
}
Else
{
  WinSet, Style, ^0xC40000, ahk_id %WindowID%
  WinMove, ahk_id %WindowID%, , WinPosX, WinPosY, WindowWidth, WindowHeight
}
WindowState:=!WindowState
return

3. Save the file as 4K resolution.ahk or whichever name you prefer as long as the file extension ending is .ahk

4. Browse to where you saved the file and double click on it.

5. The script is now running in the background, waiting for you to press F12. Pressing once will set the window size to 4096 x 2160. Pressing it again will toggle the window back.

6. Right click the system tray and click exit to turn the script off.

exit2

Optional: Edit the script to run even higher resolutions.
Edit 4096 and 2160 at this line to the values you prefer:

WinMove, ahk_id %WindowID%, , 0, 0, 4096, 2160


m4v_stellar_class_red_dwarf_binary_brown_dwarfs__7_by_nirklars-d88d2li_png

Instant loading mode in SpaceEngine

There is a semi hidden option of changing the loading method inside space engine. It is insanely resource heavy and will freeze the game if you run out of memory.

Press the forward slash key / to toggle using Immediate, Interleaved or Asynchronous loading modes. (This is the apostrophe key on Swedish keyboards for some reason btw)

Immediate loading mode will attempt to load directly speeding up loading time. Avoid moving the camera or your position while in this mode! It will quickly queue up your actions in a buffer until your memory is full. (Which tends to freeze the game)

dfe4bbe7a26e67dfd7e0010ef4a55d12-d86axhn_pngThe sequence of taking high res screenshots

So after reading all this here is my own sequence for taking high res screenshots. Add anything else to this list that you like. If you find easier ways to do this please make sure to share them in the comment section!

 

1. Open up Graphics settings with CTRL+F4 and set your level of detail LOD to -2.0 before you go exploring.

2. When you find a good location, save it with F6.

3. Press ALT+ENTER to go to windowed mode and the Spacebar to pause time.

4. Configure other graphics settings or magnitudes and exposure menu using F7 to what you prefer.

5. Open up Graphics settings again with CTRL+F4 and set your level of detail LOD to 2.0

6. Press F12 to toggle 4096 x 2160 windowed mode. Expect a very low frame rate.

(At this time its useful to use hotkeys for opening options, since the toolbars are out of screen)

7. Press forward slash / to toggle to immediate loading mode. The game will most like freeze, this is normal so don’t click on anything.

8. Wait for it to finish loading and recover from the freeze. Cross your fingers it doesn’t crash… Grab a coffee or something 🙂

(A good way to tell when it has finished loading is to click an object with the selection pointer visible on screen. If the selection pointer is moving, it has finished loading.)

9.  Press F11 to capture a 4K screenshot!

10. Optional: Press SHIFT+C to toggle clouds and press F11 again.

11. Optional: Press SHIFT+A to disable atmospheres and take the last screenshot with F11.

12. Restart because you’re probably out of memory ! (Usually crashes or freezes here for me)

The optional images without atmosphere and clouds are useful if you want to do any post editing. For example placing them in different layers and changing transparency to your liking can be useful if you find beautiful landscapes but atmospheres are too thick and you need to adjust it afterwards.

Here are the results of adding together 3 images into a 4K high res render as described above. I have also added another copy of the layer without clouds or atmosphere; added a glow filter and manually erased parts if it to give it a somewhat glowing effect. Surreal yes, but pretty!

Alien shores lit by a never setting sun – 4096 x 2160 example
alien shores 4k

End words

If you keep getting crashes or permanent freezes while attempting to follow these instructions I’m sorry to say that your computer might not be up to the task. SpaceEngine can be quite resource demanding.

Here are my current computer specifications for comparison:
i7 870 2.93GHz OC ~3.2GHz
GeForce GTX 470 1280MB
16GB DDR3 1600Mhz
Samsung 840Pro 256GB SSD

If want to know more tricks about SpaceEngine you should go visit the forums!

Happy exploring!

More Space Engine

http://nirklars.deviantart.com/gallery/

ringed_dark_side_7k binary_pearls_7680x4320small_magellanic_cloud_by grains_of_silicate extrasolar_comet_4k exomoon_starfield__false_colour_4k

OpenGL error troubleshooting (updated 2016-01-11)

If you’ve been following this guide intently you may had crashes and encountered the following error message.
(Or perhaps another similar error message in case you have a ATI graphics card)

To see how you can workaround this click here for the separate post with instructions.

nvidia_opengl_lost_connection_error