View | Details | Raw Unified | Return to bug 80324
Collapse All | Expand All

(-)Eclipse SWT/common/org/eclipse/swt/SWT.java (-2 / +10 lines)
Lines 2223-2228 Link Here
2223
	 */
2223
	 */
2224
	public static final int ERROR_INVALID_FONT = 48;
2224
	public static final int ERROR_INVALID_FONT = 48;
2225
2225
2226
    /** 
2227
     * SWT error constant indicating that an attempt was made to
2228
     * dispose an SWT graphics object while it was still in use
2229
     * (value is 49).
2230
     */
2231
    public static final int ERROR_GRAPHIC_DISPOSED_EARLY = 49;
2232
    
2226
	/**
2233
	/**
2227
	 * Traversal event detail field value indicating that no 
2234
	 * Traversal event detail field value indicating that no 
2228
	 * traversal action should be taken
2235
	 * traversal action should be taken
Lines 2784-2792 Link Here
2784
		case ERROR_DEVICE_DISPOSED:        return "Device is disposed"; //$NON-NLS-1$
2791
		case ERROR_DEVICE_DISPOSED:        return "Device is disposed"; //$NON-NLS-1$
2785
		case ERROR_FAILED_EXEC:            return "Failed to execute runnable"; //$NON-NLS-1$
2792
		case ERROR_FAILED_EXEC:            return "Failed to execute runnable"; //$NON-NLS-1$
2786
		case ERROR_FAILED_LOAD_LIBRARY:    return "Unable to load library"; //$NON-NLS-1$
2793
		case ERROR_FAILED_LOAD_LIBRARY:    return "Unable to load library"; //$NON-NLS-1$
2787
		case ERROR_CANNOT_INVERT_MATRIX:    return "Cannot invert matrix"; //$NON-NLS-1$
2794
		case ERROR_CANNOT_INVERT_MATRIX:   return "Cannot invert matrix"; //$NON-NLS-1$
2788
		case ERROR_NO_GRAPHICS_LIBRARY:    return "Unable to load graphics library"; //$NON-NLS-1$
2795
		case ERROR_NO_GRAPHICS_LIBRARY:    return "Unable to load graphics library"; //$NON-NLS-1$
2789
		case ERROR_INVALID_FONT:    		return "Font not valid"; //$NON-NLS-1$
2796
		case ERROR_INVALID_FONT:    	   return "Font not valid"; //$NON-NLS-1$
2797
        case ERROR_GRAPHIC_DISPOSED_EARLY: return "Graphic was disposed while still in use"; //$NON-NLS-1$
2790
	}
2798
	}
2791
	return "Unknown error"; //$NON-NLS-1$
2799
	return "Unknown error"; //$NON-NLS-1$
2792
}
2800
}
(-)Eclipse SWT/common/org/eclipse/swt/graphics/Resource.java (+47 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.swt.graphics;
11
package org.eclipse.swt.graphics;
12
12
13
import org.eclipse.swt.SWT;
14
13
/**
15
/**
14
 * This class is the abstract superclass of all graphics resource objects.  
16
 * This class is the abstract superclass of all graphics resource objects.  
15
 * Resources created by the application must be disposed.
17
 * Resources created by the application must be disposed.
Lines 38-45 Link Here
38
	 * the device where this resource was created
40
	 * the device where this resource was created
39
	 */
41
	 */
40
	Device device;
42
	Device device;
43
    
44
    int locks = 0;
45
    
46
/**
47
 * Locks this resource, preventing its dispose method from being used.
48
 * This does not necessarily prevent the resource from being disposed
49
 * by the OS, but it will cause an exception to be thrown if an 
50
 * attempt is made to explicitly call dispose. 
51
 * 
52
 * <p>
53
 * Locking the resource permits it to safely be exposed as public API
54
 * without creating a risk that other objects will dispose the resource
55
 * prematurely.
56
 * </p>
57
 * 
58
 * <p>
59
 * Each call to lock must have a matching call to unlock with an identical
60
 * key before the Resource may be disposed.
61
 * </p>
62
 * 
63
 * @param key an integer chosen by the caller that will later be used
64
 * to unlock the resource.
65
 */
66
public void lock(int key) {
67
    locks += key;
68
}
41
69
42
/**
70
/**
71
 * Unlocks a resource previously locked by a call to lock(...). A locked resource
72
 * must be unlocked with the same keys before it can be disposed. Resources 
73
 * cannot be unlocked more than once unless they were locked the same number of
74
 * times.
75
 * 
76
 * @param key a key that had previously been used as an argument to lock(...).
77
 */
78
public void unlock(int key) {
79
    locks -= key;
80
}
81
82
/**
83
 * Throws an exception if this resource is currently locked.
84
 */
85
protected void checkLocks() {
86
    if (locks != 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED_EARLY);
87
}
88
    
89
/**
43
 * Disposes of the operating system resources associated with
90
 * Disposes of the operating system resources associated with
44
 * this resource. Applications must dispose of all resources
91
 * this resource. Applications must dispose of all resources
45
 * which they allocate.
92
 * which they allocate.
(-)Eclipse SWT/win32/org/eclipse/swt/graphics/Color.java (+1 lines)
Lines 118-123 Link Here
118
public void dispose() {
118
public void dispose() {
119
	if (handle == -1) return;
119
	if (handle == -1) return;
120
	if (device.isDisposed()) return;
120
	if (device.isDisposed()) return;
121
    checkLocks();
121
122
122
	/*
123
	/*
123
	 * If this is a palette-based device,
124
	 * If this is a palette-based device,
(-)Eclipse SWT/win32/org/eclipse/swt/graphics/Cursor.java (+1 lines)
Lines 361-366 Link Here
361
public void dispose () {
361
public void dispose () {
362
	if (handle == 0) return;
362
	if (handle == 0) return;
363
	if (device.isDisposed()) return;
363
	if (device.isDisposed()) return;
364
    checkLocks();
364
	
365
	
365
	/*
366
	/*
366
	* It is an error in Windows to destroy the current
367
	* It is an error in Windows to destroy the current
(-)Eclipse SWT/win32/org/eclipse/swt/graphics/Font.java (+1 lines)
Lines 146-151 Link Here
146
public void dispose() {
146
public void dispose() {
147
	if (handle == 0) return;
147
	if (handle == 0) return;
148
	if (device.isDisposed()) return;
148
	if (device.isDisposed()) return;
149
    checkLocks();
149
	OS.DeleteObject(handle);
150
	OS.DeleteObject(handle);
150
	handle = 0;
151
	handle = 0;
151
	if (device.tracking) device.dispose_Object(this);
152
	if (device.tracking) device.dispose_Object(this);
(-)Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java (+1 lines)
Lines 427-432 Link Here
427
public void dispose() {
427
public void dispose() {
428
	if (handle == 0) return;
428
	if (handle == 0) return;
429
	if (data.device.isDisposed()) return;
429
	if (data.device.isDisposed()) return;
430
    checkLocks();
430
	
431
	
431
	if (data.gdipGraphics != 0) Gdip.Graphics_delete(data.gdipGraphics);
432
	if (data.gdipGraphics != 0) Gdip.Graphics_delete(data.gdipGraphics);
432
	if (data.gdipPen != 0) Gdip.Pen_delete(data.gdipPen);
433
	if (data.gdipPen != 0) Gdip.Pen_delete(data.gdipPen);
(-)Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java (+2 lines)
Lines 960-965 Link Here
960
public void dispose () {
960
public void dispose () {
961
	if (handle == 0) return;
961
	if (handle == 0) return;
962
	if (device.isDisposed()) return;
962
	if (device.isDisposed()) return;
963
    checkLocks();
964
    
963
	if (memGC != null) memGC.dispose();
965
	if (memGC != null) memGC.dispose();
964
	if (type == SWT.ICON) {
966
	if (type == SWT.ICON) {
965
		if (OS.IsWinCE) data = null;
967
		if (OS.IsWinCE) data = null;
(-)Eclipse SWT/win32/org/eclipse/swt/graphics/Path.java (+1 lines)
Lines 287-292 Link Here
287
public void dispose() {
287
public void dispose() {
288
	if (handle == 0) return;
288
	if (handle == 0) return;
289
	if (device.isDisposed()) return;
289
	if (device.isDisposed()) return;
290
    checkLocks();
290
	Gdip.GraphicsPath_delete(handle);
291
	Gdip.GraphicsPath_delete(handle);
291
	handle = 0;
292
	handle = 0;
292
	if (device.tracking) device.dispose_Object(this);
293
	if (device.tracking) device.dispose_Object(this);
(-)Eclipse SWT/win32/org/eclipse/swt/graphics/Pattern.java (+1 lines)
Lines 138-143 Link Here
138
public void dispose() {
138
public void dispose() {
139
	if (handle == 0) return;
139
	if (handle == 0) return;
140
	if (device.isDisposed()) return;
140
	if (device.isDisposed()) return;
141
    checkLocks();
141
	int type = Gdip.Brush_GetType(handle);
142
	int type = Gdip.Brush_GetType(handle);
142
	switch (type) {
143
	switch (type) {
143
		case Gdip.BrushTypeSolidColor:
144
		case Gdip.BrushTypeSolidColor:
(-)Eclipse SWT/win32/org/eclipse/swt/graphics/Region.java (+1 lines)
Lines 229-234 Link Here
229
public void dispose () {
229
public void dispose () {
230
	if (handle == 0) return;
230
	if (handle == 0) return;
231
	if (device.isDisposed()) return;
231
	if (device.isDisposed()) return;
232
    checkLocks();
232
	OS.DeleteObject(handle);
233
	OS.DeleteObject(handle);
233
	handle = 0;
234
	handle = 0;
234
	if (device.tracking) device.dispose_Object(this);
235
	if (device.tracking) device.dispose_Object(this);
(-)Eclipse SWT/win32/org/eclipse/swt/graphics/TextLayout.java (+1 lines)
Lines 395-400 Link Here
395
 */
395
 */
396
public void dispose () {
396
public void dispose () {
397
	if (device == null) return;
397
	if (device == null) return;
398
    checkLocks();
398
	freeRuns();
399
	freeRuns();
399
	font = null;	
400
	font = null;	
400
	text = null;
401
	text = null;
(-)Eclipse SWT/win32/org/eclipse/swt/graphics/Transform.java (+1 lines)
Lines 122-127 Link Here
122
public void dispose() {
122
public void dispose() {
123
	if (handle == 0) return;
123
	if (handle == 0) return;
124
	if (device.isDisposed()) return;
124
	if (device.isDisposed()) return;
125
    checkLocks();
125
	Gdip.Matrix_delete(handle);
126
	Gdip.Matrix_delete(handle);
126
	handle = 0;
127
	handle = 0;
127
	if (device.tracking) device.dispose_Object(this);
128
	if (device.tracking) device.dispose_Object(this);

Return to bug 80324