• Advertisement

Archived

This topic is now archived and is closed to further replies.

"Phantom" Access violations?

This topic is 5998 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I''m writing an app that makes great use of the standard Win32 GDI. My app runs fine, however whenever I''m running a debug build, the Output pane in VC6 claims I''m getting tons and tons of Access Violations in GDI32.DLL. This does not crash my app, nor does it seem to be "corrupting" windows GDI resources. Anybody have an idea what might cause something like this? I know what an access violation is, and I also know that they *will* crash your module or executable unless you handle them. I''ve tried to set my debugger to stop on all exception, even if they are handled, but the program runs fine. Basically anytime I redraw the screen, I see more and more of those errors. Call me anal, but I want them out of my program Problem is, I don''t know where to look for this error! I stepped through my drawing code and everything was in order. The actual error I get is "First-chance exception in App.exe (GDI32.DLL): 0xC0000005: Access Violation." If it''s any help, I''m forced to develop under Win98, so I don''t know if this behaviour is platform specific. *sigh* Thanks in advance

Share this post


Link to post
Share on other sites
Advertisement
Possibly whats going on is that you are passing a resource handle that is invalid. i.e. an uninitialised HPEN or HFONT or HWND for instance.

D.V.

Share this post


Link to post
Share on other sites
I had a similar problem, in one of my drawing routines in one of my classes. Problem was that there were 30 some odd classes. Then I decided to clean up the code, and went about rebuilding the structure of my app. Probably the best thing you can do is to remove just about everything from the code, and add one thing at a time. When the errors reappear, you know where they are. The problem is then fixing them (which can be sooo much more painful).

Z.

Share this post


Link to post
Share on other sites
Wwll, I figured out where they are happening, but I''ll be damned if I know why.

I''m using WTL which has many of benefits of MFC with none of the drawback IMHO. Anyway, they have DC object which instead of having a SelectObject method, they have a type-safe SelectPen, SelectBrush, etc.

Inside these methods, there is an assert that calls ::GetObjectType, the Win32 API call that returns what kind of object a HGDIOBJ is (Pen, brush, etc) to make sure that the HGDIOBJ passes in is of the appropriate type. It is the call to this function that is causing the access violation! More baffling, Windows is more than happy to paint with my brush! The handle of the brush is valid, so I don''t understand why the violation.

Here is a possible clue I have yet to decifer. I create a white brush using the CreateSolidBrush function. When I select it into the DC, it should return a handle to the brush that used to be selected... the brush is none other than the one I just selected! Selecting the old brush back into the DC causes another violation! I can''t win!

Thanks again,
-OberonZ

---
PAGE FAULT: Please insert "Swap File, Disk 2"
and press any key to continue.

Share this post


Link to post
Share on other sites
Grrr!

Here is the best part. The exceptions are random! Yes, it''s true! Sometimes one API call will do it on the 6th time through, other times it will be another on the 2nd or 3rd or 4th! Given the same exact repro steps, I cannot reproduce the error the same way twice. AAARGH!!

I even tried after a fresh reboot, to no avail.

I have tracked down my legitimate errors (the ones that reproduced every time) and they definately were errors on my type. Beware desctructor releasing handles while they are selected The other random times it happens, I have no idea.

---
PAGE FAULT: Please insert "Swap File, Disk 2"
and press any key to continue.

Share this post


Link to post
Share on other sites
it's quite possible with that fallacy of an operating system, that the gdi32.dll itself has been corrupted. i had to develop on that pile of sh*t OS for a month and after a while, the thing would just blue screen immediately after rebooting. my suggestion to you is to try selecting in the brushes with plain old GDI to see if the exceptions still occur. if they don't then the problem may be wtl or your code, otherwise your system is probably hosed. here is some sample code guaranteed not to cause exceptions

HBRUSH hBrush = CreateSolidBrush(RGB(255,255,255));
HBRUSH hOldBrush = (HBRUSH)SelectObject(hdc, hBrush);
... draw something
SelectObject(hdc, hOldBrush);
DeleteObject(hBrush);


hope this helps


one more thing, is the program you are running an .exe with only your code or are you using VB? if it's VB and you have other controls on a form you could be seeing exceptions caused by someone else's stuff.




Edited by - Fragmo on September 20, 2001 7:22:32 PM

Share this post


Link to post
Share on other sites
-- Begin Rant ---------------
Gah! I hate Windows98 and all the incarnations of that damnable 9x kernel! I don't care if XP has an invasive anal probe anti piracy verification test so long as it does away with the shoddy excuse of an OS that Windows9x/ME is.

Tooltips crash my system! Hover the mouse over the start button? BLAM! Down goes Explorer. Hover the mouse over the notification tray? BLAM! Hover the mouse over an icon? BLAM! BLAM! BLAM! I can't work like this!

Randmly, my system decides that the mouse can move anywhere on the screen except on the taskbar at the bottom of the screen! That's right, the taskbar has closed for a siesta is isn't accepting visitors. Grr!
-- End Rant -----------------

Ah... feel better.
Fragmo, WTL does not have a DLL or LIB file to include in your project, but actuall source code you compile with your code. It is a thin wrapper over the API and when I step through it it does exactly what you have shown here. Reguadless, I tried your suggestion and guess what? Same thing.

The most retarded thing is that GetObjectType causes the access violation, yet it works, it returns the correct value. I fear that you are correct, my GDI32.DLL may be corrupted, God knows that wont be the first.

Still I'm apprehensive about blaming something on the OS if there is a chance that it is my fault. Too many programmers blame their program's faults on 3rd party components while they should really take a closer look at their code.

Whatever is causing this it has something to do with brushes, because only the by passing a brush handle to GetObjectType will you get an access violation... Actually, hold on, I'll try something....

Dog-Gammit!! I wrote an ultra simplistic app whose responsibility is only to create a brush and figure out if the handle returned is a brush or not... It causes this exception!
    
1. #include <windows.h>
2. int main (int argc, char * argv[])
3. {
4. HBRUSH hBrush = (HBRUSH) GetStockObject (WHITE_BRUSH);
5. return GetObjectType (hBrush);
6. }

Line 5 causes an access violation. Can anyone verify if this happens on their machines? I would be eternally greatful. I just want to know that I'm not going crazy.

Thanks,
-OberonZ
}

---
PAGE FAULT: Please insert "Swap File, Disk 2"
and press any key to continue.

Edited by - OberonZ on September 21, 2001 11:28:14 AM

Share this post


Link to post
Share on other sites
hmmmm... must be something with calling GetObjectType on a stock object. i tried it with CreateSolidBrush and nothing, used GetStockObject and i got that same exception.

oh and btw, i know what wtl is


Edited by - Fragmo on September 22, 2001 9:13:58 PM

Share this post


Link to post
Share on other sites

  • Advertisement