bkaradzic / bgfx

Cross-platform, graphics API agnostic, "Bring Your Own Engine/Framework" style rendering library.
https://bkaradzic.github.io/bgfx/overview.html
BSD 2-Clause "Simplified" License
15.08k stars 1.94k forks source link

JS TypeError when WebGL not supported #1083

Open hcomere opened 7 years ago

hcomere commented 7 years ago

Hello,

When WebGL is not supported by the browser ( ex : adding --disable-webgl flag to chrome ), bgfx::init() will trigger

[BGFX FATAL | UnableToInitialize] Failed to create context.

then will continue to do some initialisation, leading to a JS TypeError due to gl context == null :

index.html:201 bad name in getProcAddress: glVertexAttribIPointer,glVertexAttribIPointer
index.html:201 bad name in getProcAddress: glGetInternalformativ,glGetInternalformativ
index.html:201 bad name in getProcAddress: glGetInternalformati64v,glGetInternalformati64v
index.html:201 bad name in getProcAddress: glStringMarkerGREMEDY,glStringMarkerGREMEDY
index.html:201 bad name in getProcAddress: glFrameTerminatorGREMEDY,glFrameTerminatorGREMEDY
index.html:201 bad name in getProcAddress: glGetTranslatedShaderSourceANGLE,glGetTranslatedShaderSource
index.html:201 bad name in getProcAddress: glPointSize,glPointSize
index.html:201 bad name in getProcAddress: glPolygonMode,glPolygonMode
index.html:201 bad name in getProcAddress: glBlitFramebufferANGLE,glBlitFramebuffer
index.html:201 bad name in getProcAddress: glRenderbufferStorageMultisampleANGLE,glRenderbufferStorageMultisample
index.html:201 bad name in getProcAddress: glCopyImageSubDataEXT,glCopyImageSubData
index.html:201 bad name in getProcAddress: glDebugMessageControlKHR,glDebugMessageControlKHR
index.html:201 bad name in getProcAddress: glDebugMessageInsertKHR,glDebugMessageInsertKHR
index.html:201 bad name in getProcAddress: glDebugMessageCallbackKHR,glDebugMessageCallbackKHR
index.html:201 bad name in getProcAddress: glGetDebugMessageLogKHR,glGetDebugMessageLogKHR
index.html:201 bad name in getProcAddress: glGetCompressedTexImageXXXXX,glGetCompressedTexImageXXXXX
index.html:201 bad name in getProcAddress: glGetTexImageXXXXX,glGetTexImageXXXXX
index.html:201 bad name in getProcAddress: glGetStringi,glGetStringi
index.html:201 bad name in getProcAddress: glTexImage3DOES,glTexImage3D
index.html:201 bad name in getProcAddress: glTexSubImage3DOES,glTexSubImage3D
index.html:201 bad name in getProcAddress: glCompressedTexImage3DOES,glCompressedTexImage3D
index.html:201 bad name in getProcAddress: glCompressedTexSubImage3DOES,glCompressedTexSubImage3D
index.html:201 bad name in getProcAddress: glTexStorage2DEXT,glTexStorage2D
index.html:201 bad name in getProcAddress: glTexStorage3DEXT,glTexStorage3D
index.html:201 bad name in getProcAddress: glTexImage2DMultisample,glTexImage2DMultisample
index.html:201 bad name in getProcAddress: glTexImage3DMultisample,glTexImage3DMultisample
index.html:201 bad name in getProcAddress: glInsertEventMarkerEXT,glInsertEventMarker
index.html:201 bad name in getProcAddress: glPushGroupMarkerEXT,glPushGroupMarker
index.html:201 bad name in getProcAddress: glPopGroupMarkerEXT,glPopGroupMarker
index.html:201 bad name in getProcAddress: glObjectLabelEXT,glObjectLabel
index.html:201 bad name in getProcAddress: glDrawArraysIndirectEXT,glDrawArraysIndirect
index.html:201 bad name in getProcAddress: glDrawElementsIndirectEXT,glDrawElementsIndirect
index.html:201 bad name in getProcAddress: glMultiDrawArraysIndirectEXT,glMultiDrawArraysIndirect
index.html:201 bad name in getProcAddress: glMultiDrawElementsIndirectEXT,glMultiDrawElementsIndirect
index.html:201 bad name in getProcAddress: glGetProgramBinaryOES,glGetProgramBinary
index.html:201 bad name in getProcAddress: glProgramBinaryOES,glProgramBinary
index.html:201 bad name in getProcAddress: glClipControlXXXXX,glClipControlXXXXX
index.html:201 bad name in getProcAddress: glEnableiXXXXX,glEnableiXXXXX
index.html:201 bad name in getProcAddress: glDisableiXXXXX,glDisableiXXXXX
index.html:201 bad name in getProcAddress: glBlendEquationiXXXXX,glBlendEquationiXXXXX
index.html:201 bad name in getProcAddress: glBlendEquationSeparateiXXXXX,glBlendEquationSeparateiXXXXX
index.html:201 bad name in getProcAddress: glBlendFunciXXXXX,glBlendFunciXXXXX
index.html:201 bad name in getProcAddress: glBlendFuncSeparateiXXXXX,glBlendFuncSeparateiXXXXX
index.html:201 bad name in getProcAddress: glDrawBufferXXXXX,glDrawBufferXXXXX
index.html:201 bad name in getProcAddress: glReadBufferXXXXX,glReadBufferXXXXX
index.html:201 bad name in getProcAddress: glGenSamplersXXXXX,glGenSamplersXXXXX
index.html:201 bad name in getProcAddress: glDeleteSamplersXXXXX,glDeleteSamplersXXXXX
index.html:201 bad name in getProcAddress: glBindSamplerXXXXX,glBindSamplerXXXXX
index.html:201 bad name in getProcAddress: glSamplerParameterfXXXXX,glSamplerParameterfXXXXX
index.html:201 bad name in getProcAddress: glSamplerParameteriXXXXX,glSamplerParameteriXXXXX
index.html:201 bad name in getProcAddress: glSamplerParameterfvXXXXX,glSamplerParameterfvXXXXX
index.html:201 bad name in getProcAddress: glBindBufferBaseXXXXX,glBindBufferBaseXXXXX
index.html:201 bad name in getProcAddress: glBindBufferRangeXXXXX,glBindBufferRangeXXXXX
index.html:201 bad name in getProcAddress: glBindImageTextureXXXXX,glBindImageTextureXXXXX
index.html:201 bad name in getProcAddress: glGetProgramInterfaceivXXXXX,glGetProgramInterfaceivXXXXX
index.html:201 bad name in getProcAddress: glGetProgramResourceIndexXXXXX,glGetProgramResourceIndexXXXXX
index.html:201 bad name in getProcAddress: glGetProgramResourceivXXXXX,glGetProgramResourceivXXXXX
index.html:201 bad name in getProcAddress: glGetProgramResourceNameXXXXX,glGetProgramResourceNameXXXXX
index.html:201 bad name in getProcAddress: glGetProgramResourceLocationXXXXX,glGetProgramResourceLocationXXXXX
index.html:201 bad name in getProcAddress: glGetProgramResourceLocationIndexXXXXX,glGetProgramResourceLocationIndexXXXXX
index.html:201 bad name in getProcAddress: glMemoryBarrierXXXXX,glMemoryBarrierXXXXX
index.html:201 bad name in getProcAddress: glDispatchComputeXXXXX,glDispatchComputeXXXXX
index.html:201 bad name in getProcAddress: glDispatchComputeIndirectXXXXX,glDispatchComputeIndirectXXXXX
index.html:201 bad name in getProcAddress: glDrawBuffersNV,glDrawBuffersNV
index.html:201 bad name in getProcAddress: glGenQueriesNV,glGenQueriesNV
index.html:201 bad name in getProcAddress: glDeleteQueriesNV,glDeleteQueriesNV
index.html:201 bad name in getProcAddress: glBeginQueryNV,glBeginQueryNV
index.html:201 bad name in getProcAddress: glEndQueryNV,glEndQueryNV
index.html:201 bad name in getProcAddress: glGetQueryObjectivNV,glGetQueryObjectivNV
index.html:201 bad name in getProcAddress: glGetQueryObjectui64vNV,glGetQueryObjectui64vNV
index.html:201 bad name in getProcAddress: glQueryCounterNV,glQueryCounterNV
index.html:201 bad name in getProcAddress: glDiscardFramebufferEXT,glDiscardFramebuffer

Uncaught TypeError: Cannot read property 'getParameter' of undefined

I was expecting in this case that bgfx::init() stops all initializations and return false directly.

Is it a bug or a bad usage on my side ?

Regards, Harold

bkaradzic commented 7 years ago

non-GL renderers handle this case better. For now just detect webgl presence before calling bgfx::init.