зеркало из https://github.com/mozilla/pjs.git
Bug 636356 - WebGL crash [@mozilla::WebGLBuffer::ZeroDataIfElementArray] - r=jrmuizel, a=joe
This commit is contained in:
Родитель
eef61f8409
Коммит
01188c7b00
|
@ -361,6 +361,7 @@ public:
|
|||
nsresult ErrorInvalidEnumInfo(const char *info, PRUint32 enumvalue) {
|
||||
return ErrorInvalidEnum("%s: invalid enum value 0x%x", info, enumvalue);
|
||||
}
|
||||
nsresult ErrorOutOfMemory(const char *fmt = 0, ...);
|
||||
|
||||
WebGLTexture *activeBoundTextureForTarget(WebGLenum target) {
|
||||
return target == LOCAL_GL_TEXTURE_2D ? mBound2DTextures[mActiveTexture]
|
||||
|
@ -710,19 +711,25 @@ public:
|
|||
|
||||
// element array buffers are the only buffers for which we need to keep a copy of the data.
|
||||
// this method assumes that the byte length has previously been set by calling SetByteLength.
|
||||
void CopyDataIfElementArray(const void* data) {
|
||||
PRBool CopyDataIfElementArray(const void* data) {
|
||||
if (mTarget == LOCAL_GL_ELEMENT_ARRAY_BUFFER) {
|
||||
mData = realloc(mData, mByteLength);
|
||||
if (!mData)
|
||||
return PR_FALSE;
|
||||
memcpy(mData, data, mByteLength);
|
||||
}
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
// same comments as for CopyElementArrayData
|
||||
void ZeroDataIfElementArray() {
|
||||
PRBool ZeroDataIfElementArray() {
|
||||
if (mTarget == LOCAL_GL_ELEMENT_ARRAY_BUFFER) {
|
||||
mData = realloc(mData, mByteLength);
|
||||
if (!mData)
|
||||
return PR_FALSE;
|
||||
memset(mData, 0, mByteLength);
|
||||
}
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
// same comments as for CopyElementArrayData
|
||||
|
|
|
@ -398,7 +398,8 @@ WebGLContext::BufferData_size(WebGLenum target, WebGLsizei size, WebGLenum usage
|
|||
MakeContextCurrent();
|
||||
|
||||
boundBuffer->SetByteLength(size);
|
||||
boundBuffer->ZeroDataIfElementArray();
|
||||
if (!boundBuffer->ZeroDataIfElementArray())
|
||||
return ErrorOutOfMemory("bufferData: out of memory");
|
||||
boundBuffer->InvalidateCachedMaxElements();
|
||||
|
||||
gl->fBufferData(target, size, 0, usage);
|
||||
|
@ -428,7 +429,8 @@ WebGLContext::BufferData_buf(WebGLenum target, js::ArrayBuffer *wb, WebGLenum us
|
|||
MakeContextCurrent();
|
||||
|
||||
boundBuffer->SetByteLength(wb->byteLength);
|
||||
boundBuffer->CopyDataIfElementArray(wb->data);
|
||||
if (!boundBuffer->CopyDataIfElementArray(wb->data))
|
||||
return ErrorOutOfMemory("bufferData: out of memory");
|
||||
boundBuffer->InvalidateCachedMaxElements();
|
||||
|
||||
gl->fBufferData(target, wb->byteLength, wb->data, usage);
|
||||
|
@ -458,7 +460,8 @@ WebGLContext::BufferData_array(WebGLenum target, js::TypedArray *wa, WebGLenum u
|
|||
MakeContextCurrent();
|
||||
|
||||
boundBuffer->SetByteLength(wa->byteLength);
|
||||
boundBuffer->CopyDataIfElementArray(wa->data);
|
||||
if (!boundBuffer->CopyDataIfElementArray(wa->data))
|
||||
return ErrorOutOfMemory("bufferData: out of memory");
|
||||
boundBuffer->InvalidateCachedMaxElements();
|
||||
|
||||
gl->fBufferData(target, wa->byteLength, wa->data, usage);
|
||||
|
@ -656,7 +659,7 @@ WebGLContext::CopyTexSubImage2D_base(WebGLenum target,
|
|||
// Hopefully calloc will just mmap zero pages here.
|
||||
void *tempZeroData = calloc(1, bytesNeeded);
|
||||
if (!tempZeroData)
|
||||
return SynthesizeGLError(LOCAL_GL_OUT_OF_MEMORY, "%s: could not allocate %d bytes (for zero fill)", info, bytesNeeded);
|
||||
return ErrorOutOfMemory("%s: could not allocate %d bytes (for zero fill)", info, bytesNeeded);
|
||||
|
||||
// now initialize the texture as black
|
||||
|
||||
|
@ -4048,7 +4051,7 @@ WebGLContext::TexImage2D_base(WebGLenum target, WebGLint level, WebGLenum intern
|
|||
// Hopefully calloc will just mmap zero pages here.
|
||||
void *tempZeroData = calloc(1, bytesNeeded);
|
||||
if (!tempZeroData)
|
||||
return SynthesizeGLError(LOCAL_GL_OUT_OF_MEMORY, "texImage2D: could not allocate %d bytes (for zero fill)", bytesNeeded);
|
||||
return ErrorOutOfMemory("texImage2D: could not allocate %d bytes (for zero fill)", bytesNeeded);
|
||||
|
||||
gl->fTexImage2D(target, level, internalformat, width, height, border, format, type, tempZeroData);
|
||||
|
||||
|
|
|
@ -315,3 +315,15 @@ WebGLContext::ErrorInvalidValue(const char *fmt, ...)
|
|||
|
||||
return SynthesizeGLError(LOCAL_GL_INVALID_VALUE);
|
||||
}
|
||||
|
||||
nsresult
|
||||
WebGLContext::ErrorOutOfMemory(const char *fmt, ...)
|
||||
{
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
LogMessageIfVerbose(fmt, va);
|
||||
va_end(va);
|
||||
|
||||
return SynthesizeGLError(LOCAL_GL_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче