Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4063888

HJV can crash after printing on win 95/nt



    • Type: Bug
    • Status: Closed
    • Priority: P1
    • Resolution: Fixed
    • Affects Version/s: 1.1.3
    • Fix Version/s: 1.1.4
    • Component/s: client-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
    • CPU:
    • OS:
      windows_95, windows_nt
    • Verification:
      Not verified


      The latest version of HJ Views (1.1) provides printing support.
      On Win 95/NT, I found that after printing, HJ Views would
      occassionally crash. It appeared to be when the printing related
      objects were garbage collected. I debugged this and found it
      appears to be because a field in the AwtGraphics object is not
      initialized when the object is created, so sometimes it has a
      value of zero (which is good), but sometimes it does not (and
      this is when Views will crash).

      Here is more detailed info:

      For Views 1.1 printing support has been added and one thing
      we wanted to do was to use the same print dialog on all
      platforms (one that had the Views look and feel). On
      Windows, this was a real challenge, given the way the
      PrintJob related classes (and native code) were written.
      However, I was able to get this working by also writing
      native code. Basically, I'm doing this:

      * Calling CreateDC using the specific printer info to
        create an HDC.
      * Creating a WGraphics object using the HDC, such
        that the WGraphics constructor which calls
        createFromHDC is called.
      * Retrieve the pData field of the WGraphics object
        and set the pGraphics field of the WPrintJob object
        equal to this value (which is basically the awtGraphics
      * Continue with the print job (ie. call getGraphics, etc).

      For the most part, this worked great. However, occassionally
      I found that after printing, Views would crash. I finally
      tracked this down to the garbage collection of the print job
      related classes. It seems that when the WGraphics class was
      garbaged collected, eventually AwtGraphics::Dispose was called.
      Here's the function:

      void AwtGraphics::Dispose() {
          if (m_pJavaObject != NULL) {
              unhand(m_pJavaObject)->pData = 0;
          delete this;

      The problem is occurring because when the WGraphics object
      was created, the m_pJavaObject field of the associated
      AwtGraphics object was not set, so sometimes its zero (which
      is good), but sometimes its not zero (which is bad). I
      checked the source code and I guess that it was not expected
      that a WGraphics object that was created using createFromHDC
      would ever be destroyed.

      Anyway, the change I was hoping you could make would be
      to initialize the m_pJavaObject field of the AwtGraphics
      object to NULL in the AwtGraphics constructor, ie:

          m_hDC = NULL;
          m_pSharedDC = NULL;
          m_isPrinter = FALSE;
          m_bPenSet = FALSE;
          m_hPen = NULL;
          m_color = RGB(0, 0, 0);
          m_xorcolor = RGB(255, 255, 255);
          m_bBrushSet = FALSE;
          m_hBrush = NULL;
          m_pFont = NULL;
          m_bPaletteSelected = FALSE;
          m_bClipping = FALSE;
          m_rop = R2_COPYPEN;
          // if rect has no area, rgn will be null, but that's OK
          m_hClipRgn = ::CreateRectRgnIndirect(&m_rectClip);
          m_printing = FALSE;
          m_pJavaObject = NULL; /* ADD THIS */

      I ended up making my own jdk1.1.3 child ws and making this
      change and it appears to fix the problem.




            tballsunw Tom Ball (Inactive)
            jwarzech Joe Warzecha (Inactive)
            0 Vote for this issue
            1 Start watching this issue