[SOLVED! by DC] AccessViolationException on full screen app

ElectricBliss

07-04-2006 14:49:17

Greetings,

When exiting a full screen app I get this sequence of complaints:

(the app will appear to lock-up… but this is because the IDE is waiting for you to respond to the first message box that says,

“No symbols are loaded for any call stack frame. The source code cannot be displayed.”

If you press the OK button, on that MessBox, then you get the AccessViolationException we unhandled error box. This message goes on to say,

“Attempted to read or write protected memory. This is often an indication that other memory is corrupt.”

Here is the call stack at this point:

[In a sleep, wait, or join]
-->Microsoft.VisualStudio.HostingProcess.Utilities.dll!Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() + 0x64 bytes
mscorlib.dll!System.Threading.ThreadHelper.ThreadStart_Context(object state) + 0x3b bytes
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x81 bytes
mscorlib.dll!System.Threading.ThreadHelper.ThreadStart() + 0x40 bytes



Here is my Ogre.log:

07:22:49: Creating resource group General
07:22:49: Creating resource group Internal
07:22:49: Creating resource group Autodetect
07:22:49: Registering ResourceManager for type Material
07:22:49: Registering ResourceManager for type Mesh
07:22:49: Registering ResourceManager for type Skeleton
07:22:49: MovableObjectFactory for type 'ParticleSystem' registered.
07:22:49: Loading library OgrePlatform_d.dll
07:22:49: OverlayElementFactory for type Panel registered.
07:22:49: OverlayElementFactory for type BorderPanel registered.
07:22:49: OverlayElementFactory for type TextArea registered.
07:22:49: Registering ResourceManager for type Font
07:22:49: ArchiveFactory for archive type FileSystem registered.
07:22:49: ArchiveFactory for archive type Zip registered.
07:22:49: DevIL version: Developer's Image Library (DevIL) 1.6.7 Nov 9 2005
07:22:49: DevIL image formats: bmp dib cut dcx dds gif hdr ico cur jpg jpe jpeg lif mdl mng jng pcx pic pix png pbm pgm pnm ppm psd pdd psp pxr sgi bw rgb rgba tga vda icb vst tif tiff wal xpm raw
07:22:49: Registering ResourceManager for type HighLevelGpuProgram
07:22:49: Registering ResourceManager for type Compositor
07:22:49: MovableObjectFactory for type 'Entity' registered.
07:22:49: MovableObjectFactory for type 'Light' registered.
07:22:49: MovableObjectFactory for type 'BillboardSet' registered.
07:22:49: MovableObjectFactory for type 'ManualObject' registered.
07:22:49: MovableObjectFactory for type 'BillboardChain' registered.
07:22:49: MovableObjectFactory for type 'RibbonTrail' registered.
07:22:49: Loading library .\RenderSystem_Direct3D9
07:22:49: D3D9 : Direct3D9 Rendering Subsystem created.
07:22:49: D3D9: Driver Detection Starts
07:22:49: D3D9: Driver Detection Ends
07:22:49: Loading library .\RenderSystem_GL
07:22:50: OpenGL Rendering Subsystem created.
07:22:50: Loading library .\Plugin_ParticleFX
07:22:50: Particle Emitter Type 'Point' registered
07:22:50: Particle Emitter Type 'Box' registered
07:22:50: Particle Emitter Type 'Ellipsoid' registered
07:22:50: Particle Emitter Type 'Cylinder' registered
07:22:50: Particle Emitter Type 'Ring' registered
07:22:50: Particle Emitter Type 'HollowEllipsoid' registered
07:22:50: Particle Affector Type 'LinearForce' registered
07:22:50: Particle Affector Type 'ColourFader' registered
07:22:50: Particle Affector Type 'ColourFader2' registered
07:22:50: Particle Affector Type 'ColourImage' registered
07:22:50: Particle Affector Type 'ColourInterpolator' registered
07:22:50: Particle Affector Type 'Scaler' registered
07:22:50: Particle Affector Type 'Rotator' registered
07:22:50: Particle Affector Type 'DirectionRandomiser' registered
07:22:50: Particle Affector Type 'DeflectorPlane' registered
07:22:50: Loading library .\Plugin_BSPSceneManager
07:22:50: Registering ResourceManager for type BspLevel
07:22:50: Loading library .\Plugin_OctreeSceneManager
07:22:50: Loading library .\Plugin_CgProgramManager
07:22:50: *-*-* OGRE Initialising
07:22:50: *-*-* Version 1.3.0 (Eihort)
07:22:50: Creating resource group Bootstrap
07:22:50: Added resource location '../../media/packs/OgreCore.zip' of type 'Zip' to resource group 'Bootstrap'
07:22:50: Added resource location '../../media' of type 'FileSystem' to resource group 'General'
07:22:50: Added resource location '../../media/fonts' of type 'FileSystem' to resource group 'General'
07:22:50: Added resource location '../../media/materials/programs' of type 'FileSystem' to resource group 'General'
07:22:50: Added resource location '../../media/materials/scripts' of type 'FileSystem' to resource group 'General'
07:22:50: Added resource location '../../media/materials/textures' of type 'FileSystem' to resource group 'General'
07:22:50: Added resource location '../../media/models' of type 'FileSystem' to resource group 'General'
07:22:50: Added resource location '../../media/overlays' of type 'FileSystem' to resource group 'General'
07:22:50: Added resource location '../../media/particle' of type 'FileSystem' to resource group 'General'
07:22:50: Added resource location '../../media/gui' of type 'FileSystem' to resource group 'General'
07:22:50: Added resource location '../../media/DeferredShadingMedia' of type 'FileSystem' to resource group 'General'
07:22:50: Added resource location '../../media/packs/cubemap.zip' of type 'Zip' to resource group 'General'
07:22:50: Added resource location '../../media/packs/cubemapsJS.zip' of type 'Zip' to resource group 'General'
07:22:50: Added resource location '../../media/packs/dragon.zip' of type 'Zip' to resource group 'General'
07:22:50: Added resource location '../../media/packs/fresneldemo.zip' of type 'Zip' to resource group 'General'
07:22:50: Added resource location '../../media/packs/ogretestmap.zip' of type 'Zip' to resource group 'General'
07:22:50: Added resource location '../../media/packs/skybox.zip' of type 'Zip' to resource group 'General'
07:22:50: D3D9 : RenderSystem Option: Allow NVPerfHUD = No
07:22:50: D3D9 : RenderSystem Option: Anti aliasing = None
07:22:50: D3D9 : RenderSystem Option: Floating-point mode = Fastest
07:22:50: D3D9 : RenderSystem Option: Full Screen = Yes
07:22:50: D3D9 : RenderSystem Option: Rendering Device = RADEON 9800 PRO
07:22:50: D3D9 : RenderSystem Option: VSync = No
07:22:50: D3D9 : RenderSystem Option: Video Mode = 640 x 480 @ 32-bit colour
07:22:51: D3D9 : Subsystem Initialising
07:22:51: D3D9RenderSystem::createRenderWindow "Ogre Render Window", 640x480 fullscreen miscParams: FSAA=0 FSAAQuality=0 colourDepth=32 useNVPerfHUD=false vsync=false
07:22:51: D3D9 : Created D3D9 Rendering Window 'Ogre Render Window' : 640x480, 32bpp
07:22:52: Registering ResourceManager for type Texture
07:22:52: Registering ResourceManager for type GpuProgram
07:22:52: RenderSystem capabilities
07:22:52: -------------------------
07:22:52: * Hardware generation of mipmaps: yes
07:22:52: * Texture blending: yes
07:22:52: * Anisotropic texture filtering: yes
07:22:52: * Dot product texture operation: yes
07:22:52: * Cube mapping: yes
07:22:52: * Hardware stencil buffer: yes
07:22:52: - Stencil depth: 8
07:22:52: - Two sided stencil support: yes
07:22:52: - Wrap stencil values: yes
07:22:52: * Hardware vertex / index buffers: yes
07:22:52: * Vertex programs: yes
07:22:52: - Max vertex program version: vs_2_0
07:22:52: * Fragment programs: yes
07:22:52: - Max fragment program version: ps_2_0
07:22:52: * Texture Compression: yes
07:22:52: - DXT: yes
07:22:52: - VTC: no
07:22:52: * Scissor Rectangle: yes
07:22:52: * Hardware Occlusion Query: yes
07:22:52: * User clip planes: yes
07:22:52: * VET_UBYTE4 vertex element type: yes
07:22:52: * Infinite far plane projection: yes
07:22:52: * Hardware render-to-texture: yes
07:22:52: * Floating point textures: yes
07:22:52: * Non-power-of-two textures: yes
07:22:52: * Volume textures: yes
07:22:52: * Multiple Render Targets: 4
07:22:52: * Max Point Size: 256
07:22:52: ***************************************
07:22:52: *** D3D9 : Subsystem Initialised OK ***
07:22:52: ***************************************
07:22:52: ResourceBackgroundQueue - threading disabled
07:22:52: Particle Renderer Type 'billboard' registered
07:22:52: Creating viewport on target 'Ogre Render Window', rendering from camera 'MainCamera', relative dimensions L: 0.00 T: 0.00 W: 1.00 H: 1.00 ZOrder: 0
07:22:52: Viewport for camera 'MainCamera', actual dimensions L: 0 T: 0 W: 640 H: 480
07:22:52: Parsing scripts for resource group Autodetect
07:22:52: Finished parsing scripts for resource group Autodetect
07:22:52: Parsing scripts for resource group Bootstrap
07:22:52: Parsing script OgreCore.material
07:22:52: Parsing script OgreProfiler.material
07:22:52: Parsing script Ogre.fontdef
07:22:52: Parsing script OgreDebugPanel.overlay
07:22:52: Texture: New_Ogre_Border_Center.png: Loading 1 faces(PF_A8B8G8R8,256x128x1) with hardware generated mipmaps from Image. Internal format is PF_A8R8G8B8,256x128x1.
07:22:52: Texture: New_Ogre_Border.png: Loading 1 faces(PF_A8B8G8R8,256x256x1) with hardware generated mipmaps from Image. Internal format is PF_A8R8G8B8,256x256x1.
07:22:53: Texture: New_Ogre_Border_Break.png: Loading 1 faces(PF_A8B8G8R8,32x32x1) with hardware generated mipmaps from Image. Internal format is PF_A8R8G8B8,32x32x1.
07:22:53: Font TrebuchetMSBoldusing texture size 512x512
07:22:53: Info: Freetype returned null for character 160 in font TrebuchetMSBold
07:22:53: Texture: TrebuchetMSBoldTexture: Loading 1 faces(PF_BYTE_LA,512x512x1) with 0 generated mipmaps from Image. Internal format is PF_BYTE_LA,512x512x1.
07:22:53: Texture: ogretext.png: Loading 1 faces(PF_A8B8G8R8,256x128x1) with hardware generated mipmaps from Image. Internal format is PF_A8R8G8B8,256x128x1.
07:22:53: Parsing script OgreLoadingPanel.overlay
07:22:53: Finished parsing scripts for resource group Bootstrap
07:22:53: Parsing scripts for resource group General
07:22:53: Parsing script Examples.program
07:22:53: Parsing script StdQuad_vp.program
07:22:53: Parsing script deferred.glsl.program
07:22:53: Parsing script deferred.hlsl.program
07:22:53: Parsing script deferred_post_debug.glsl.program
07:22:53: Parsing script deferred_post_debug.hlsl.program
07:22:53: Parsing script deferred_post_minilight.glsl.program
07:22:53: Parsing script deferred_post_minilight.hlsl.program
07:22:53: An exception has been thrown!

-----------------------------------
Details:
-----------------------------------
Error #: 7
Function: GpuProgramParameters::getParamIndex
Description: Cannot find a parameter named lightSpecularColor.
File: c:\ogre\ogrenew\ogremain\src\ogregpuprogram.cpp
Line: 768
Stack unwinding: <<beginning of stack>>
07:22:53: Error at line 29 of deferred_post_minilight.hlsl.program: Invalid param_named_auto attribute - An exception has been thrown!

-----------------------------------
Details:
-----------------------------------
Error #: 7
Function: GpuProgramParameters::getParamIndex
Description: Cannot find a parameter named lightSpecularColor.
File: c:\ogre\ogrenew\ogremain\src\ogregpuprogram.cpp
Line: 768
Stack unwinding: <<beginning of stack>>
07:22:53: Parsing script deferred_post_multipass.glsl.program
07:22:53: Parsing script deferred_post_multipass.hlsl.program
07:22:53: Parsing script deferred_post_onepass.glsl.program
07:22:53: Parsing script deferred_post_onepass.hlsl.program
07:22:53: Parsing script BlackAndWhite.material
07:22:53: Parsing script Bloom.material
07:22:53: Parsing script DOF.material
07:22:54: Parsing script Embossed.material
07:22:54: Parsing script Example-DynTex.material
07:22:54: Parsing script Example-Water.material
07:22:54: Parsing script Example.material
07:22:54: Parsing script Examples-Advanced.material
07:22:54: Parsing script facial.material
07:22:54: Parsing script Glass.material
07:22:54: Parsing script HeatVision.material
07:22:54: Parsing script Hurt.material
07:22:54: Parsing script MotionBlur.material
07:22:54: Parsing script Ocean.material
07:22:55: Parsing script OffsetMapping.material
07:22:55: Parsing script Ogre.material
07:22:55: Parsing script OldTV.material
07:22:55: Parsing script RZR-002.material
07:22:55: Parsing script smoke.material
07:22:55: Parsing script deferred.material
07:22:55: Parsing script deferreddemo.material
07:22:55: Parsing script deferred_post_debug.material
07:22:55: Parsing script deferred_post_minilight.material
07:22:55: Parsing script deferred_post_multipass.material
07:22:55: Parsing script deferred_post_onepass.material
07:22:55: Parsing script fresnelenviron.material
07:22:55: Parsing script Examples.compositor
07:22:55: Parsing script sample.fontdef
07:22:55: Bad attribute line: glyph 0.152344 0.125 0.160156 0.1875 in font Ogre
07:22:55: Parsing script Example-Water.particle
07:22:55: Parsing script Example.particle
07:22:55: Parsing script smoke.particle
07:22:55: Parsing script Compositor.overlay
07:22:55: Parsing script DP3.overlay
07:22:55: Parsing script Example-CubeMapping.overlay
07:22:55: Parsing script Example-DynTex.overlay
07:22:56: Parsing script Example-Water.overlay
07:22:56: Parsing script Shadows.overlay
07:22:56: Finished parsing scripts for resource group General
07:22:56: Parsing scripts for resource group Internal
07:22:56: Finished parsing scripts for resource group Internal
07:22:56: Win32Input8: DirectInput Activation Starts
07:22:56: Win32Input8: Establishing keyboard input.
07:22:56: Win32Input8: Keyboard input established.
07:22:56: Win32Input8: Establishing mouse input.
07:22:56: Win32Input8: Mouse input established.
07:22:56: Win32Input8: DirectInput OK.
07:22:56: Texture: clouds.jpg: Loading 1 faces(PF_B8G8R8,256x256x1) with hardware generated mipmaps from Image. Internal format is PF_X8R8G8B8,256x256x1.
07:22:56: Texture: TaharezLook.tga: Loading 1 faces(PF_A8R8G8B8,256x256x1) with 0 generated mipmaps from Image. Internal format is PF_A8R8G8B8,256x256x1.
07:22:56: Texture: _cegui_ogre_0: Loading 1 faces(PF_A8R8G8B8,32x32x1) with 0 generated mipmaps from Image. Internal format is PF_A8R8G8B8,32x32x1.
07:22:56: Texture: _cegui_ogre_1: Loading 1 faces(PF_A8R8G8B8,128x128x1) with 0 generated mipmaps from Image. Internal format is PF_A8R8G8B8,128x128x1.
07:22:56: Texture: _cegui_ogre_2: Loading 1 faces(PF_A8R8G8B8,32x32x1) with 0 generated mipmaps from Image. Internal format is PF_A8R8G8B8,32x32x1.
07:22:56: Texture: _cegui_ogre_3: Loading 1 faces(PF_A8R8G8B8,128x128x1) with 0 generated mipmaps from Image. Internal format is PF_A8R8G8B8,128x128x1.
07:22:56: Texture: _cegui_ogre_4: Loading 1 faces(PF_A8R8G8B8,32x32x1) with 0 generated mipmaps from Image. Internal format is PF_A8R8G8B8,32x32x1.
07:22:56: Texture: _cegui_ogre_5: Loading 1 faces(PF_A8R8G8B8,128x128x1) with 0 generated mipmaps from Image. Internal format is PF_A8R8G8B8,128x128x1.
07:22:58: Unregistering ResourceManager for type BspLevel
07:22:58: *-*-* OGRE Shutdown
07:22:58: Unregistering ResourceManager for type Compositor
07:22:58: Unregistering ResourceManager for type Font
07:22:58: Unregistering ResourceManager for type Skeleton
07:22:58: Unregistering ResourceManager for type Mesh
07:22:58: Unregistering ResourceManager for type HighLevelGpuProgram
07:22:58: Unloading library .\Plugin_CgProgramManager
07:22:58: Unloading library .\Plugin_OctreeSceneManager
07:22:58: Unloading library .\Plugin_BSPSceneManager
07:22:58: Unloading library .\Plugin_ParticleFX
07:22:58: *** Stopping Win32GL Subsystem ***
07:22:58: Unloading library .\RenderSystem_GL
07:22:58: Render Target 'Ogre Render Window' Average FPS: 105.368 Best FPS: 105.368 Worst FPS: 105.368
07:22:59: D3D9 : Shutting down cleanly.
07:22:59: Unregistering ResourceManager for type Texture
07:22:59: Unregistering ResourceManager for type GpuProgram
07:22:59: D3D9 : Direct3D9 Rendering Subsystem destroyed.
07:22:59: Unloading library .\RenderSystem_Direct3D9
07:22:59: Unregistering ResourceManager for type Material
07:22:59: Unloading library OgrePlatform_d.dll


Interesting things to note:

- If I don’t call base.Dispose() on application exit I don’t get the error.

- If I don’t put [STAThread] on main then I can call base.Dispose() on exit.

- The App runs fine if not running it in the IDE (i.e. just running the .exe file)

- If I disable the “Enable the Visual Studio hosting process” (in project->properties->Debug) then I don’t get the error.

My current bet is on the idea that the GC is trying to collect memory that has already been destroyed by the cpp in the dll. But I’m just guessing here.

Any ideas?

EB

DigitalCyborg

09-04-2006 05:04:58

I've seen this too.

As EB said, you can get around it several ways, the easiest of which is just to comment out the [STAThread].

If you look at the OgreDotNet tutorials, you'll notice that STAThread is commented out :?

The simplest code EB & I have come up with that reproduces the error is


using System;
using System.Drawing;
using OgreDotNet;
using Math3D;

namespace FRIGGINGBUGEXITINGFROMFULLSCREEN
{
class BugDemoApplication : ExampleApplication
{

protected override void CreateScene()
{
}

[STAThread]
static void Main(string[] args)
{
using(BugDemoApplication app = new BugDemoApplication())
{
app.Start();
}//using
}//main
}//class
}//namespace


Are EB & I the only ones seeing this?

DigitalCyborg

09-04-2006 05:48:33

changing STAThread to MTAThread also fixes the problem..

Since I'm still new to windows programming, I don't fully understand the difference between the two..

When I figure it out, I'll update this thread.

ElectricBliss

09-04-2006 05:56:10

Brilliant DC!

This works for me... excellent find brotha!

Multi-threaded... makes sense...

Thanks again!

Sincerely,

EB

EagleEye

09-04-2006 05:57:49

I found the following:

Why is STAThread required?

Over the top of your Main method, you may have noticed this funny decoration:

[STAThread]
static void Main() {

Several people have asked, what is this and is it this actually necessary?

When the STAThreadAttribute is applied, it changes the apartment state of the current thread to be single threaded. Without getting into a huge discussion about COM and threading, this attribute ensures the communication mechanism between the current thread and other threads that may want to talk to it via COM. When you're using Windows Forms, depending on the feature you're using, it may be using COM interop in order to communicate with operating system components. Good examples of this are the Clipboard and the File Dialogs.

Windows Forms is not supported within a MTA or free threaded apartment. Applications using Windows Forms should always declare the apartment style they're using, as some other component could initialize the apartment state of thread improperly.

If the application cannot control the apartment state of the current thread, it should start up a new thread. Here's a quick example:

using System.Threading;

Thread t = new Thread(new ThreadStart(StartNewStaThread));

// Make sure to set the apartment state BEFORE starting the thread.
t.ApartmentState = ApartmentState.STA;
t.Start();

private void StartNewStaThread() {
Application.Run(new Form1());
}


Also look here:
http://www.csharphelp.com/archives3/archive558.html

http://www.developerfusion.co.uk/show/4272/4/

The impression I get is that you only need to use STAThread if you are using COM objects, or windows forms... neither of which we're using, I believe.

ElectricBliss

09-04-2006 06:14:51

Excellent, thanks for the link Eagle. This clarifies it

http://www.csharphelp.com/archives3/archive558.html

For the definition of [MTAThread] it says,

[MTAThread] is short for [MTAThreadAttribute], in C#. In other words "Attribute" suffix is optional. If you are working in a mixed environment, you should use the full name MTAThreadAttribute versus the shortcut MTAThread.

I would like to emphasize the phrase, "mixed environment," in the quote above.

Thanks again!

EB