mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-08 08:48:39 +09:00
Add size checks to WebGLContext::BufferData()
On MacOS, particularly large allocations within the platform limits (1.2G+) will fail and crash. This adds a specific size check for that when working around driver bugs (default). While there, added a generic size_t limited size check for the platform, and reporting OOM if too large.
This commit is contained in:
parent
8896e73c1a
commit
0771bbb58c
1 changed files with 12 additions and 0 deletions
|
|
@ -9,6 +9,8 @@
|
||||||
#include "WebGLBuffer.h"
|
#include "WebGLBuffer.h"
|
||||||
#include "WebGLVertexArray.h"
|
#include "WebGLVertexArray.h"
|
||||||
|
|
||||||
|
#include "mozilla/CheckedInt.h"
|
||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
|
|
||||||
WebGLRefPtr<WebGLBuffer>*
|
WebGLRefPtr<WebGLBuffer>*
|
||||||
|
|
@ -345,6 +347,16 @@ WebGLContext::BufferData(GLenum target, WebGLsizeiptr size, GLenum usage)
|
||||||
|
|
||||||
////
|
////
|
||||||
|
|
||||||
|
const auto checkedSize = CheckedInt<size_t>(size);
|
||||||
|
if (!checkedSize.isValid())
|
||||||
|
return ErrorOutOfMemory("%s: Size too large for platform.", funcName);
|
||||||
|
|
||||||
|
#if defined(XP_MACOSX)
|
||||||
|
if (gl->WorkAroundDriverBugs() && size > 1200000000) {
|
||||||
|
return ErrorOutOfMemory("Allocations larger than 1200000000 fail on MacOS.");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
const UniqueBuffer zeroBuffer(calloc(size, 1));
|
const UniqueBuffer zeroBuffer(calloc(size, 1));
|
||||||
if (!zeroBuffer)
|
if (!zeroBuffer)
|
||||||
return ErrorOutOfMemory("%s: Failed to allocate zeros.", funcName);
|
return ErrorOutOfMemory("%s: Failed to allocate zeros.", funcName);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue