• Crashing when accessing "g_pVGuiSurface" in GMod .dll module
    4 replies, posted
Hi, I am trying to port my Lua code to C++ to improve perfomance. In my visual studio project I have included GMod Lua headers ([url]https://github.com/garrynewman/gmod-module-base[/url]) and Source SDK 2007 headers and libraries. Everything compiles fine, but when this line executes the game crashes. [CODE] g_pVGuiSurface->DrawTexturedRect(x, y, x + w, y + h); [/CODE] As I found out every call to "g_pVGuiSurface" (or "vgui::surface()") makes game to crash. Other functions like "Msg()" work fine, so I just don't know what goes wrong. The crash memory dump file information: [CODE] Process Name: hl2.exe : D:\Program Files (x86)\Steam\steamapps\common\GarrysMod\hl2.exe Process Architecture: x86 Exception Code: 0xC0000005 Exception Information: The thread tried to read from or write to a virtual address for which it does not have the appropriate access. Heap Information: Not Present [/CODE] I guess that the headers from Source SDK 2007 may not be suitable for Garrys Mod, but these are the only headers that I've got.
For starters, you can get a newer SDK here: [url]https://github.com/ValveSoftware/source-sdk-2013[/url] Make sure you are actually creating the vgui interface. It's not just gonna appear in that variable by magic.
[QUOTE=Jcw87;51179175]For starters, you can get a newer SDK here: [url]https://github.com/ValveSoftware/source-sdk-2013[/url] Make sure you are actually creating the vgui interface. It's not just gonna appear in that variable by magic.[/QUOTE] Thanks for the link. I'm trying to create a function that draws 2d objects on screen (similar to lua analogue "surface.DrawTexturedRect()"). What am I missing?
Here's a mockup of what you want. [code] CDllDemandLoader vguisurface_module("vguimatsurface"); GMOD_MODULE_OPEN() { CreateInterfaceFn func = vguisurface_module.GetFactory(); g_pVGuiSurface = (vgui::ISurface*)func(VGUI_SURFACE_INTERFACE_VERSION, NULL); // Now you should be able to do stuff with g_pVGuiSurface } [/code] I haven't tested this. You may need to try other dll names.
[QUOTE=Jcw87;51179583]Here's a mockup of what you want. [code] CDllDemandLoader vguisurface_module("vguimatsurface"); GMOD_MODULE_OPEN() { CreateInterfaceFn func = vguisurface_module.GetFactory(); g_pVGuiSurface = (vgui::ISurface*)func(VGUI_SURFACE_INTERFACE_VERSION, NULL); // Now you should be able to do stuff with g_pVGuiSurface } [/code] I haven't tested this. You may need to try other dll names.[/QUOTE] It worked! Thank you! Btw, for anyone minding this question in future, if you are compiling using Visual Studio 2015 and getting error "LNK2001 unresolved external symbol __vsnwprintf" you should add "legacy_stdio_definitions.lib" in Configuration Properties -> Linker -> Input -> Additional Dependencies.
Sorry, you need to Log In to post a reply to this thread.