[Bug 26350] Dungeons demo (OGRE) fails to load its plugins (LoadLibraryEx with LOAD_WITH_ALTERED_SEARCH_PATH and relative path)

WineHQ Bugzilla wine-bugs at winehq.org
Fri Mar 13 14:13:01 CDT 2020


https://bugs.winehq.org/show_bug.cgi?id=26350

Anastasius Focht <focht at gmx.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|-unknown                    |ntdll
            Summary|Dungeons demo doesn't run   |Dungeons demo (OGRE) fails
                   |(LoadLibraryEx with         |to load its plugins
                   |LOAD_WITH_ALTERED_SEARCH_PA |(LoadLibraryEx with
                   |TH and relative path)       |LOAD_WITH_ALTERED_SEARCH_PA
                   |                            |TH and relative path)
                URL|http://www.gamershell.com/d |https://www.moddb.com/games
                   |ownload_69192.shtml         |/dungeons/downloads/dungeon
                   |                            |s-demo

--- Comment #7 from Anastasius Focht <focht at gmx.net> ---
Hello folks,

still present.

--- snip ---
$ pwd
/home/focht/.wine/drive_c/Program Files (x86)/Kalypso Media/Dungeons Demo

$ wine ./Dungeons.exe
...
17:22:44.443:         > Ogre: *-*-* OGRE Initialising
17:22:44.443:         > Ogre: *-*-* Version 1.7.1 (Cthugha)
17:22:44.497:         > Ogre: Loading library dlls/ParticleUniverse.dll
17:22:44.499: *ERROR* > Ogre: OGRE EXCEPTION(7:InternalErrorException): Could
not load dynamic library dlls/ParticleUniverse.dll.  System Error: Module not
found.
                         in DynLib::load at
..\..\Ogre\OgreMain\src\OgreDynLib.cpp (line 91)
17:22:44.509: *ERROR* > System.Runtime.InteropServices.SEHException: External
component has thrown an exception.
                           at Ogre.Root.loadPlugin(Root* ,
basic_string<char\,std::char_traits<char>\,std::allocator<char> >* )
                           at Mogre.Root.LoadPlugin(String pluginName)
                           at
Realmforge.MogreUtil.Application.Ogre.LoadPlugins(Root root)
                           at Realmforge.MogreUtil.Application.Ogre..ctor(Form
form, GameApplicationData appData)
                           at
Realmforge.MogreUtil.Application.Ogre.InitInstance(Form form,
GameApplicationData appData)
                           at
Realmforge.MogreUtil.Application.MainApplication`3.Run()
17:22:44.511: *ERROR* > External component has thrown an exception.
...
Unhandled Exception: System.Runtime.InteropServices.SEHException: External
component has thrown an exception.
   at Ogre.Root.loadPlugin(Root* ,
basic_string<char\,std::char_traits<char>\,std::allocator<char> >* )
   at Mogre.Root.LoadPlugin(String pluginName)
   at Realmforge.MogreUtil.Application.Ogre.LoadPlugins(Root root)
   at Realmforge.MogreUtil.Application.Ogre..ctor(Form form,
GameApplicationData appData)
   at Realmforge.MogreUtil.Application.Ogre.InitInstance(Form form,
GameApplicationData appData)
   at Realmforge.MogreUtil.Application.MainApplication`3.Run()
   at Realmforge.Dungeons.DungeonsMain.Main(String[] args)
wine: Unhandled exception 0xe06d7363 in thread 10f at address 7B00DB91 (thread
010f), starting debugger...
...
--- snip ---

--- snip ---
$ file dlls/*

dlls/ParticleUniverse.dll:          PE32 executable (DLL) (GUI) Intel 80386,
for MS Windows
dlls/Plugin_CgProgramManager.dll:   PE32 executable (DLL) (GUI) Intel 80386,
for MS Windows
dlls/Plugin_OctreeSceneManager.dll: PE32 executable (DLL) (GUI) Intel 80386,
for MS Windows
dlls/RenderSystem_Direct3D9.dll:    PE32 executable (DLL) (GUI) Intel 80386,
for MS Windows
--- snip ---

--- snip ---
$ WINEDEBUG=+seh,+relay,+module,+loaddll,+ntdll wine ./Dungeons.exe >>log.txt
2>&1

...
0046:Call KERNEL32.SetCurrentDirectoryA(0032eaf4 "C:\\Program Files
(x86)\\Kalypso Media\\Dungeons Demo\\data") ret=0eb41505
...
0046:Ret  KERNEL32.SetCurrentDirectoryA() retval=00000001 ret=0eb41505
...
0046:Call KERNEL32.LoadLibraryExA(03c7a150
"dlls/ParticleUniverse.dll",00000000,00000008) ret=0e87fd84
...
0046:Call ntdll.LdrGetDllPath(7ffd8c00
L"dlls/ParticleUniverse.dll",00000008,0032eca0,0032ec98) ret=7b016626
0046:Ret  ntdll.LdrGetDllPath() retval=00000000 ret=7b016626
0046:Call ntdll.LdrLoadDll(03ec0820
L"dlls;C:\\windows\\system32;C:\\windows\\system;C:\\windows;.;C:\\windows\\system32;C:\\windows;C:\\windows\\system32\\wbem;C:\\windows\\system32\\WindowsPowershell\\v1.0",00000008,0032ecc0,0032eca8)
ret=7b0167f8
0046:trace:module:load_dll looking for L"dlls/ParticleUniverse.dll" in
L"dlls;C:\\windows\\system32;C:\\windows\\system;C:\\windows;.;C:\\windows\\system32;C:\\windows;C:\\windows\\system32\\wbem;C:\\windows\\system32\\WindowsPowershell\\v1.0"
...
0046:warn:ntdll:FILE_CreateFile L"\\??\\C:\\Program Files (x86)\\Kalypso
Media\\Dungeons Demo\\data\\dlls\\dlls\\ParticleUniverse.dll" not found
(c000003a)
...
0046:warn:ntdll:FILE_CreateFile
L"\\??\\C:\\windows\\system32\\dlls\\ParticleUniverse.dll" not found (c000003a)
...
0046:warn:ntdll:FILE_CreateFile
L"\\??\\C:\\windows\\system\\dlls\\ParticleUniverse.dll" not found (c000003a)
...
0046:warn:ntdll:FILE_CreateFile
L"\\??\\C:\\windows\\dlls\\ParticleUniverse.dll" not found (c000003a)
...
0046:warn:ntdll:FILE_CreateFile L"\\??\\C:\\Program Files (x86)\\Kalypso
Media\\Dungeons Demo\\data\\dlls\\ParticleUniverse.dll" not found (c000003a)
...
0046:warn:ntdll:FILE_CreateFile
L"\\??\\C:\\windows\\system32\\dlls\\ParticleUniverse.dll" not found (c000003a)
...
0046:warn:ntdll:FILE_CreateFile
L"\\??\\C:\\windows\\dlls\\ParticleUniverse.dll" not found (c000003a)
...
0046:warn:ntdll:FILE_CreateFile
L"\\??\\C:\\windows\\system32\\wbem\\dlls\\ParticleUniverse.dll" not found
(c000003a)
...
0046:warn:ntdll:FILE_CreateFile
L"\\??\\C:\\windows\\system32\\WindowsPowershell\\v1.0\\dlls\\ParticleUniverse.dll"
not found (c000003a)
...
0046:warn:module:load_dll Failed to load module L"dlls/ParticleUniverse.dll";
status=c0000135
0046:Ret  ntdll.LdrLoadDll() retval=c0000135 ret=7b0167f8
0046:Call ntdll.RtlNtStatusToDosError(c0000135) ret=7b01681c
0046:Ret  ntdll.RtlNtStatusToDosError() retval=0000007e ret=7b01681c
0046:Call ntdll.RtlReleasePath(03ec0820) ret=7b01682f
0046:Ret  ntdll.RtlReleasePath() retval=00000008 ret=7b01682f
0046:Ret  KERNEL32.LoadLibraryExA() retval=00000000 ret=0e87fd84 
--- snip ---

.NET code:

--- snip ---
// Type: Realmforge.MogreUtil.Application.Ogre
// Assembly: Realmforge.MogreUtil, Version=2.1.0.0, Culture=neutral,
PublicKeyToken=null
// MVID: FEDA0E96-3FAF-4FE1-B63C-87C3E5A99039
// Assembly location: C:\Program Files (x86)\Kalypso Media\Dungeons
Demo\Realmforge.MogreUtil.dll

using Mogre;
using Realmforge.Util;
using Realmforge.Util.Calculation;
using Realmforge.Util.Configuration;
using Realmforge.Util.LogSystem;
using Realmforge.Util.Text;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows.Forms;

namespace Realmforge.MogreUtil.Application
{
...
    public static void LoadPlugins(Root root)
    {
      foreach (string file in
Directory.GetFiles(Path.Combine(Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath),
"dlls"), "*.dll", SearchOption.TopDirectoryOnly))
      {
        if (!file.Contains("Plugin_OctreeZone") &&
!file.ToLower().EndsWith("_d.dll"))
          root.LoadPlugin("dlls/" + Path.GetFileName(file));
      }
    }

--- snip ---

Ogre framework code:

https://github.com/OGRECave/ogre/blob/a9ab158f6f6f1ba87b413525d418c49a9e0528f8/OgreMain/src/OgreDynLib.cpp#L75

---

Although already cited by Louis (comment #1), the exact quote from Microsoft
docs:

https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibraryexa

--- quote ---
...

If lpFileName specifies an absolute path and dwFlags is set to
LOAD_WITH_ALTERED_SEARCH_PATH, LoadLibraryEx uses the altered search path. The
behavior is undefined when LOAD_WITH_ALTERED_SEARCH_PATH flag is set, and
lpFileName specifiies a relative path.

...
--- quote ---

There are a number of FOSS projects on github that fixed this problem on their
own after bug reports from users (Windows XP behaves different -> fails). They
don't use relative paths anymore in conjunction with 'LoadLibraryEx( ...
LOAD_WITH_ALTERED_SEARCH_PATH)'.

But still - if it somehow works on Windows 7+ then I guess it should be fixed
in Wine as well.

Since Wine loader/dll path functions have been moved from kernel32 to ntdll,
the current location:

https://source.winehq.org/git/wine.git/blob/c3165b4c96a021a96dc6dd8a0b8e1030682dd6e5:/dlls/ntdll/loader.c#l4087

--- snip ---
4087 NTSTATUS WINAPI LdrGetDllPath( PCWSTR module, ULONG flags, PWSTR *path,
PWSTR *unknown )
4088 {
4089     NTSTATUS status;
4090     const ULONG load_library_search_flags =
(LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR |
4091                                             
LOAD_LIBRARY_SEARCH_APPLICATION_DIR |
4092                                              LOAD_LIBRARY_SEARCH_USER_DIRS
|
4093                                              LOAD_LIBRARY_SEARCH_SYSTEM32
|
4094                                             
LOAD_LIBRARY_SEARCH_DEFAULT_DIRS);
4095 
4096     if (flags & LOAD_WITH_ALTERED_SEARCH_PATH)
4097     {
4098         if (flags & load_library_search_flags) return
STATUS_INVALID_PARAMETER;
4099         if (default_search_flags) flags |= default_search_flags |
LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR;
4100     }
4101     else if (!(flags & load_library_search_flags)) flags |=
default_search_flags;
4102 
4103     RtlEnterCriticalSection( &dlldir_section );
4104 
4105     if (flags & load_library_search_flags)
4106     {
4107         status = get_dll_load_path_search_flags( module, flags, path );
4108     }
4109     else
4110     {
4111         const WCHAR *dlldir = dll_directory.Length ? dll_directory.Buffer
: NULL;
4112         if (!(flags & LOAD_WITH_ALTERED_SEARCH_PATH))
4113             module =
NtCurrentTeb()->Peb->ProcessParameters->ImagePathName.Buffer;
4114         status = get_dll_load_path( module, dlldir, dll_safe_mode, path );
4115     }
4116 
4117     RtlLeaveCriticalSection( &dlldir_section );
4118     *unknown = NULL;
4119     return status;
4120 }
--- snip ---

Line 4112 is in question here. Remove the condition to have the current
executable path added to search paths which gets later combined with relative
dll path.

$ wine --version
wine-5.3-341-gc3165b4c96

Regards

-- 
Do not reply to this email, post in Bugzilla using the
above URL to reply.
You are receiving this mail because:
You are watching all bug changes.



More information about the wine-bugs mailing list