<br><br>perjantai 8. toukokuuta 2015 Ian Romanick <<a href="mailto:idr@freedesktop.org">idr@freedesktop.org</a>> kirjoitti:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 05/07/2015 05:21 AM, Pohjolainen, Topi wrote:<br>
> On Tue, May 05, 2015 at 02:25:29PM +0300, Juha-Pekka Heikkila wrote:<br>
>> Stop context creation if something failed. If something errored<br>
>> during context creation we'd segfault. Now will clean up and<br>
>> return error.<br>
>><br>
>> Signed-off-by: Juha-Pekka Heikkila <<a href="javascript:;" onclick="_e(event, 'cvml', 'juhapekka.heikkila@gmail.com')">juhapekka.heikkila@gmail.com</a>><br>
>> ---<br>
>> src/mesa/main/shared.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++---<br>
>> 1 file changed, 62 insertions(+), 4 deletions(-)<br>
>><br>
>> diff --git a/src/mesa/main/shared.c b/src/mesa/main/shared.c<br>
>> index 0b76cc0..cc05b05 100644<br>
>> --- a/src/mesa/main/shared.c<br>
>> +++ b/src/mesa/main/shared.c<br>
>> @@ -64,9 +64,21 @@ _mesa_alloc_shared_state(struct gl_context *ctx)<br>
>><br>
>> mtx_init(&shared->Mutex, mtx_plain);<br>
>><br>
>> + /* Mutex and timestamp for texobj state validation */<br>
>> + mtx_init(&shared->TexMutex, mtx_recursive);<br>
>> + shared->TextureStateStamp = 0;<br>
><br>
> Do you really need to move this here?<br>
<br>
I was going to ask the same thing. I think moving it here means that it<br>
can be unconditionally mtx_destroy'ed in the error path below.</blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"></blockquote><div><br></div><div>Yes, Ian got it correct. When moving mutex creation here there is no need to go checking about it if need to clean up. I though this makes things more clean and simple.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> <br></blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
>> +<br>
>> shared->DisplayList = _mesa_NewHashTable();<br>
>> + if (!shared->DisplayList)<br>
>> + goto error_out;<br>
>> +<br>
>> shared->TexObjects = _mesa_NewHashTable();<br>
>> + if (!shared->TexObjects)<br>
>> + goto error_out;<br>
>> +<br>
>> shared->Programs = _mesa_NewHashTable();<br>
>> + if (!shared->Programs)<br>
>> + goto error_out;<br>
>><br>
>> shared->DefaultVertexProgram =<br>
>> gl_vertex_program(ctx->Driver.NewProgram(ctx,<br>
>> @@ -76,17 +88,28 @@ _mesa_alloc_shared_state(struct gl_context *ctx)<br>
>> GL_FRAGMENT_PROGRAM_ARB, 0));<br>
>><br>
>> shared->ATIShaders = _mesa_NewHashTable();<br>
>> + if (!shared->ATIShaders)<br>
>> + goto error_out;<br>
>> +<br>
>> shared->DefaultFragmentShader = _mesa_new_ati_fragment_shader(ctx, 0);<br>
>><br>
>> shared->ShaderObjects = _mesa_NewHashTable();<br>
>> + if (!shared->ShaderObjects)<br>
>> + goto error_out;<br>
>><br>
>> shared->BufferObjects = _mesa_NewHashTable();<br>
>> + if (!shared->BufferObjects)<br>
>> + goto error_out;<br>
>><br>
>> /* GL_ARB_sampler_objects */<br>
>> shared->SamplerObjects = _mesa_NewHashTable();<br>
>> + if (!shared->SamplerObjects)<br>
>> + goto error_out;<br>
>><br>
>> /* Allocate the default buffer object */<br>
>> shared->NullBufferObj = ctx->Driver.NewBufferObject(ctx, 0);<br>
>> + if (!shared->NullBufferObj)<br>
>> + goto error_out;<br>
>><br>
>> /* Create default texture objects */<br>
>> for (i = 0; i < NUM_TEXTURE_TARGETS; i++) {<br>
>> @@ -107,22 +130,57 @@ _mesa_alloc_shared_state(struct gl_context *ctx)<br>
>> };<br>
>> STATIC_ASSERT(ARRAY_SIZE(targets) == NUM_TEXTURE_TARGETS);<br>
>> shared->DefaultTex[i] = ctx->Driver.NewTextureObject(ctx, 0, targets[i]);<br>
>> +<br>
>> + if (!shared->DefaultTex[i])<br>
>> + goto error_out;<br>
>> }<br>
>><br>
>> /* sanity check */<br>
>> assert(shared->DefaultTex[TEXTURE_1D_INDEX]->RefCount == 1);<br>
>><br>
>> - /* Mutex and timestamp for texobj state validation */<br>
>> - mtx_init(&shared->TexMutex, mtx_recursive);<br>
>> - shared->TextureStateStamp = 0;<br>
>> -<br>
>> shared->FrameBuffers = _mesa_NewHashTable();<br>
>> + if (!shared->FrameBuffers)<br>
>> + goto error_out;<br>
>> +<br>
>> shared->RenderBuffers = _mesa_NewHashTable();<br>
>> + if (!shared->RenderBuffers)<br>
>> + goto error_out;<br>
>><br>
>> shared->SyncObjects = _mesa_set_create(NULL, _mesa_hash_pointer,<br>
>> _mesa_key_pointer_equal);<br>
>> + if (!shared->SyncObjects)<br>
>> + goto error_out;<br>
>><br>
>> return shared;<br>
>> +<br>
>> +error_out:<br>
>> + for (i = 0; i < NUM_TEXTURE_TARGETS; i++) {<br>
>> + if (shared->DefaultTex[i]) {<br>
>> + ctx->Driver.DeleteTexture(ctx, shared->DefaultTex[i]);<br>
>> + }<br>
>> + }<br>
>> +<br>
>> + _mesa_reference_buffer_object(ctx, &shared->NullBufferObj, NULL);<br>
>> +<br>
>> + _mesa_DeleteHashTable(shared->RenderBuffers);<br>
>> + _mesa_DeleteHashTable(shared->FrameBuffers);<br>
>> + _mesa_DeleteHashTable(shared->SamplerObjects);<br>
>> + _mesa_DeleteHashTable(shared->BufferObjects);<br>
>> + _mesa_DeleteHashTable(shared->ShaderObjects);<br>
>> + _mesa_DeleteHashTable(shared->ATIShaders);<br>
>> + _mesa_DeleteHashTable(shared->Programs);<br>
>> + _mesa_DeleteHashTable(shared->TexObjects);<br>
>> + _mesa_DeleteHashTable(shared->DisplayList);<br>
>> +<br>
>> + _mesa_reference_vertprog(ctx, &shared->DefaultVertexProgram, NULL);<br>
>> + _mesa_reference_geomprog(ctx, &shared->DefaultGeometryProgram, NULL);<br>
>> + _mesa_reference_fragprog(ctx, &shared->DefaultFragmentProgram, NULL);<br>
>> +<br>
>> + mtx_destroy(&shared->Mutex);<br>
>> + mtx_destroy(&shared->TexMutex);<br>
>> +<br>
>> + free(shared);<br>
>> + return NULL;<br>
>> }<br>
>><br>
>><br>
>> --<br>
>> 1.8.5.1<br>
>><br>
>> _______________________________________________<br>
>> mesa-dev mailing list<br>
>> <a href="javascript:;" onclick="_e(event, 'cvml', 'mesa-dev@lists.freedesktop.org')">mesa-dev@lists.freedesktop.org</a><br>
>> <a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev" target="_blank">http://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
> _______________________________________________<br>
> mesa-dev mailing list<br>
> <a href="javascript:;" onclick="_e(event, 'cvml', 'mesa-dev@lists.freedesktop.org')">mesa-dev@lists.freedesktop.org</a><br>
> <a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev" target="_blank">http://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
><br>
<br>
</blockquote>