Making sure that are not malloc empty string or image
This commit is contained in:
parent
9b78594354
commit
5f8528b324
|
|
@ -840,28 +840,34 @@ EM_ASYNC_JS(void, RequestClipboardData, (void), {
|
||||||
EM_JS(char*, GetLastPastedText, (void), {
|
EM_JS(char*, GetLastPastedText, (void), {
|
||||||
var str = window._lastClipboardString || "";
|
var str = window._lastClipboardString || "";
|
||||||
var length = lengthBytesUTF8(str) + 1;
|
var length = lengthBytesUTF8(str) + 1;
|
||||||
var ptr = _malloc(length);
|
if (length > 1) {
|
||||||
stringToUTF8(str, ptr, length);
|
var ptr = _malloc(length);
|
||||||
return ptr;
|
stringToUTF8(str, ptr, length);
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Returns the image created by RequestClipboardData from JS memory to Emscripten C memory
|
// Returns the image created by RequestClipboardData from JS memory to Emscripten C memory
|
||||||
EM_JS(unsigned char*, GetLastPastedImage, (int* width, int* height), {
|
EM_JS(unsigned char*, GetLastPastedImage, (int* width, int* height), {
|
||||||
if (!window._lastImgData) return 0;
|
if (window._lastImgData) {
|
||||||
|
const data = window._lastImgData;
|
||||||
|
if (data.length > 0) {
|
||||||
|
const ptr = _malloc(data.length);
|
||||||
|
HEAPU8.set(data, ptr);
|
||||||
|
|
||||||
const data = window._lastImgData;
|
// Set the width and height via the pointers passed from C
|
||||||
const ptr = _malloc(data.length);
|
// HEAP32 handles the 4-byte integers
|
||||||
HEAPU8.set(data, ptr);
|
if (width) setValue(width, window._lastImgWidth, 'i32');
|
||||||
|
if (height) setValue(height, window._lastImgHeight, 'i32');
|
||||||
|
|
||||||
// Set the width and height via the pointers passed from C
|
// Clear the JS buffer so we don't fetch the same image twice
|
||||||
// HEAP32 handles the 4-byte integers
|
window._lastImgData = null;
|
||||||
if (width) setValue(width, window._lastImgWidth, 'i32');
|
|
||||||
if (height) setValue(height, window._lastImgHeight, 'i32');
|
|
||||||
|
|
||||||
// Clear the JS buffer so we don't fetch the same image twice
|
return ptr;
|
||||||
window._lastImgData = null;
|
}
|
||||||
|
}
|
||||||
return ptr;
|
return 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Get clipboard text content
|
// Get clipboard text content
|
||||||
|
|
|
||||||
|
|
@ -818,28 +818,34 @@ EM_ASYNC_JS(void, RequestClipboardData, (void), {
|
||||||
EM_JS(char*, GetLastPastedText, (void), {
|
EM_JS(char*, GetLastPastedText, (void), {
|
||||||
var str = window._lastClipboardString || "";
|
var str = window._lastClipboardString || "";
|
||||||
var length = lengthBytesUTF8(str) + 1;
|
var length = lengthBytesUTF8(str) + 1;
|
||||||
var ptr = _malloc(length);
|
if (length > 1) {
|
||||||
stringToUTF8(str, ptr, length);
|
var ptr = _malloc(length);
|
||||||
return ptr;
|
stringToUTF8(str, ptr, length);
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Returns the image created by RequestClipboardData from JS memory to Emscripten C memory
|
// Returns the image created by RequestClipboardData from JS memory to Emscripten C memory
|
||||||
EM_JS(unsigned char*, GetLastPastedImage, (int* width, int* height), {
|
EM_JS(unsigned char*, GetLastPastedImage, (int* width, int* height), {
|
||||||
if (!window._lastImgData) return 0;
|
if (window._lastImgData) {
|
||||||
|
const data = window._lastImgData;
|
||||||
|
if (data.length > 0) {
|
||||||
|
const ptr = _malloc(data.length);
|
||||||
|
HEAPU8.set(data, ptr);
|
||||||
|
|
||||||
const data = window._lastImgData;
|
// Set the width and height via the pointers passed from C
|
||||||
const ptr = _malloc(data.length);
|
// HEAP32 handles the 4-byte integers
|
||||||
HEAPU8.set(data, ptr);
|
if (width) setValue(width, window._lastImgWidth, 'i32');
|
||||||
|
if (height) setValue(height, window._lastImgHeight, 'i32');
|
||||||
|
|
||||||
// Set the width and height via the pointers passed from C
|
// Clear the JS buffer so we don't fetch the same image twice
|
||||||
// HEAP32 handles the 4-byte integers
|
window._lastImgData = null;
|
||||||
if (width) setValue(width, window._lastImgWidth, 'i32');
|
|
||||||
if (height) setValue(height, window._lastImgHeight, 'i32');
|
|
||||||
|
|
||||||
// Clear the JS buffer so we don't fetch the same image twice
|
return ptr;
|
||||||
window._lastImgData = null;
|
}
|
||||||
|
}
|
||||||
return ptr;
|
return 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Get clipboard text content
|
// Get clipboard text content
|
||||||
|
|
@ -868,7 +874,6 @@ Image GetClipboardImage(void)
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Show mouse cursor
|
// Show mouse cursor
|
||||||
void ShowCursor(void)
|
void ShowCursor(void)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user