Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Failure in Draw call in multithreaded WinForms app  (Read 3546 times)

0 Members and 1 Guest are viewing this topic.

Conduit

  • Newbie
  • *
  • Posts: 30
    • View Profile
Failure in Draw call in multithreaded WinForms app
« on: March 16, 2015, 06:20:21 am »
I'm building a visualization application using SFML.Net which uses the main thread to process a GUI interface, and a separate thread for rendering. Currently the rendering thread is throwing an exception when attempting to draw a VertexArray (PrimitiveType.Quads) to a RenderTexture.

The exception is an AccessViolationException occurring in sfmlnet-graphics-2.dll, stating
Quote
Attempted to read or write protected memory. This is often an indication that other memory is corrupt
The exception occurs on a line containing the following code:
Quote
//target is a RenderTarget - the RenderTexture in this case, m_BorderVertices is the VertexArray, and states will always be
//RenderStates.Default
target.Draw(this.m_BorderVertices, states);

The RenderTexture and VertexArray are both created by the rendering thread, all other RenderTargets in the program are marked inactive during the Draw call, and the RenderTexture is marked active within the rendering thread just prior to the Draw call. I have thoroughly tested the way my shared resources are locked.

I've noticed a couple other questions floating around online regarding this error, but they haven't led me to any solutions... are there any common causes for this exception that any of you are aware of? I'm a little wary of posting code, since the source isn't exactly simple... I might be able to create an MCVE, but if this has a common cause then I'd rather not waste my time. Thanks!

EDIT using a copy of sfmlnet-graphics-2.dll compiled for debugging, I have found that the error is thrown on line 182 of VertexArray.cs:
Quote
sfRenderTexture_drawVertexArray(((RenderTexture)target).CPointer, CPointer, ref marshaledStates);
« Last Edit: March 16, 2015, 07:26:21 am by Conduit »

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Failure in Draw call in multithreaded WinForms app
« Reply #1 on: March 16, 2015, 01:34:47 pm »
Post a complete and minimal code example. Also where did you get CSFML and SFML.NET from?
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Conduit

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Failure in Draw call in multithreaded WinForms app
« Reply #2 on: March 16, 2015, 04:57:19 pm »
I'm working on a test case, but it might be a minute... Making a minimal, complete subset of the code that's giving me trouble is a nontrivial matter. What's the preferred method for posting VS projects here?

I'm currently using the most recent version of CSFML that I could find, and a copy of SFML.Net compiled from source just prior to the current release. I'll try using the copy that was uploaded the other day to see if it makes a difference, but I have a feeling that this is a problem with my code and not the library.
« Last Edit: March 16, 2015, 05:02:09 pm by Conduit »

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Failure in Draw call in multithreaded WinForms app
« Reply #3 on: March 16, 2015, 05:27:44 pm »
You don't need to upload an entire project, if its a problem with SFML you should be able to reproduce it with just a few functions - and then post it here in [ code=csharp ] [ /code ] tags. Remove anything that doesn't cause the problem.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Conduit

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Failure in Draw call in multithreaded WinForms app
« Reply #4 on: March 20, 2015, 07:51:01 pm »
Spent a good portion of yesterday creating a self-contained subset of the code, and accidentally ran across the solution to my problem. Last time I work off a version of CSFML I've compiled myself, I think *sigh*

 

anything