Skip to content

Commit

Permalink
JDK-8201539 Fix DirectWrite crash on Monocle.
Browse files Browse the repository at this point in the history
COM was being initialized in two different places, WinApplication
and in directwrite.cpp when an IWICImagingFactory instance is created
for the first time (on the same d2d thread). The second initialization
has no further effect. But then CoUninitialize is called, which
uninitializes COM and makes IWICImagingFactory go stale.
  • Loading branch information
brcolow committed Aug 27, 2018
1 parent 9eff5fd commit 13b4a8b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 13 deletions.
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ build_script:
$env:VSVARS32FILE = "$env:VCINSTALLDIR\vcvars32.bat"
refreshenv
# Must invoke gradle with cmd.exe so stderr output doesn't fail the build:
- cmd: gradlew all test -PCOMPILE_WEBKIT=false -PCONF=DebugNative --stacktrace -x :web:test --info --no-daemon
- cmd: gradlew all test -PCOMPILE_WEBKIT=false -PCONF=DebugNative -PFULL_TEST=true -PUSE_ROBOT=true -PHEADLESS_TEST=true -PUNSTABLE_TEST=true --stacktrace -x :web:test --info --no-daemon

on_finish:
- ps: |
Expand Down
1 change: 1 addition & 0 deletions buildSrc/win.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ WIN.compileSwing = true;
WIN.compileSWT = true;
WIN.compileFXPackager = true;

WIN.includeMonocle = true;
WIN.includeNull3d = true

// Lambda for naming the generated libs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ static final native int GetGlyphPlacements(long ptr,

//IWICImagingFactory
static final native long CreateBitmap(long ptr, int uiWidth, int uiHeight, int pixelFormat, int options);
static final native void UninitializeCOM(long ptr);

//IWICBitmap
static final native long Lock(long ptr, int x, int y, int width, int height, int flags);
Expand Down
16 changes: 4 additions & 12 deletions modules/javafx.graphics/src/main/native-font/directwrite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -848,27 +848,19 @@ jobject newD2D1_MATRIX_3X2_F(JNIEnv *env, D2D1_MATRIX_3X2_F *lpStruct)
JNIEXPORT jlong JNICALL OS_NATIVE(_1WICCreateImagingFactory)
(JNIEnv *env, jclass that)
{
/* This routine initialize COM in order to create an WICImagingFactory.
* It runs on the prism thread and expects no other codes in this thread
* to interface with COM.
/* COM will already be initialized for the lifespan of the application
* via WinApplication OLE initialization. Therefore we can just create
* the IWICImagingFactory directly.
* Note: This method is called by DWFactory a single time.
*/
HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);

/* This means COM has been initialize with a different concurrency model.
* This should never happen. */
if (hr == RPC_E_CHANGED_MODE) return NULL;

IWICImagingFactory* result = NULL;
hr = CoCreateInstance(
HRESULT hr = CoCreateInstance(
CLSID_WICImagingFactory,
NULL,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&result)
);

/* Unload COM as no other COM objects will be create directly */
CoUninitialize();
return SUCCEEDED(hr) ? (jlong)result : NULL;
}

Expand Down

0 comments on commit 13b4a8b

Please sign in to comment.