Skip to content

Commit

Permalink
Change: Improve graphics init error handling on 32-bit modded process
Browse files Browse the repository at this point in the history
As some drivers are just plain broken, and OpenTK throws an access violation exception when requesting certain GL3 features which should be supported
  • Loading branch information
leezer3 committed Oct 3, 2021
1 parent 3b48616 commit 962360a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
28 changes: 22 additions & 6 deletions source/DevTools/LBAHeader/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ static void Main(string[] args)
{
f = args[0];
}
if (!System.IO.File.Exists(f))
if (!File.Exists(f))
{
//If we can't find our initial argument, try and locate the openBVE executable in our directory
string ff = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
string ff = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
if (ff == null)
{
Console.WriteLine("Unable to find the executing assembly path....");
return;
}
f = System.IO.Path.Combine(ff, "OpenBve.exe");
f = Path.Combine(ff, "OpenBve.exe");
}
if (!System.IO.File.Exists(f))
if (!File.Exists(f))
{
//Not found, log this rather than crashing
Console.WriteLine("No suitable executables found....");
Expand All @@ -34,8 +34,8 @@ static void Main(string[] args)
AddLbaFlag(f);
Add32BitFlag(f);
// ReSharper disable once AssignNullToNotNullAttribute
f = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(f), "RouteViewer.exe");
if (!System.IO.File.Exists(f))
f = Path.Combine(Path.GetDirectoryName(f), "RouteViewer.exe");
if (!File.Exists(f))
{
//Not found, log this rather than crashing
Console.WriteLine("RouteViewer executable not found....");
Expand Down Expand Up @@ -66,6 +66,7 @@ static void AddLbaFlag(string f)
/// <summary>Marks an ANYCPU executable as 32-bit preferred</summary>
public static void Add32BitFlag(string fileToProcess)
{
string configFile = fileToProcess + ".config";
string finalFileName = fileToProcess.Replace(".exe", "-32.exe");
Console.WriteLine("Creating 32-bit preferred copy of executable " + fileToProcess);
var output = Console.Out;
Expand Down Expand Up @@ -101,6 +102,21 @@ public static void Add32BitFlag(string fileToProcess)
Console.WriteLine("An unexpected error occured whilst attempting to apply Corflags to executable " + fileToProcess);
}

if (File.Exists(configFile))
{
//Also copy the application config file, so that LoadFromRemoteSources etc. are preserved
//No clue why a File.Copy command fails on CI
try
{
byte[] bytes = File.ReadAllBytes(configFile);
File.WriteAllBytes(configFile.Replace(".exe", "-32.exe"), bytes);
}
catch
{
Console.WriteLine("An unexpected error occured whilst attempting to create the 32-bit .exe.config file.");
}

}
}
}
}
2 changes: 2 additions & 0 deletions source/LibRender2/BaseRenderer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.ExceptionServices;
using LibRender2.Backgrounds;
using LibRender2.Cameras;
using LibRender2.Fogs;
Expand Down Expand Up @@ -265,6 +266,7 @@ protected BaseRenderer(HostInterface CurrentHost, BaseOptions CurrentOptions, Fi
/// <summary>
/// Call this once to initialise the renderer
/// </summary>
[HandleProcessCorruptedStateExceptions] //As some graphics cards crash really nastily if we request unsupported features
public virtual void Initialize()
{

Expand Down
10 changes: 2 additions & 8 deletions source/OpenBVE/app.config
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
</startup>
<runtime>
<loadFromRemoteSources enabled="true" />
<gcAllowVeryLargeObjects enabled="true" />
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="Data\Formats" />
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.6.0" newVersion="4.0.6.0" />
</dependentAssembly>
</assemblyBinding>
<legacyCorruptedStateExceptionsPolicy enabled="true|false"/>
</runtime>
</configuration>

0 comments on commit 962360a

Please sign in to comment.