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

Author Topic: Exception-throwing in destruction  (Read 6747 times)

0 Members and 1 Guest are viewing this topic.

RobotGymnast

  • Jr. Member
  • **
  • Posts: 56
    • View Profile
Exception-throwing in destruction
« on: February 03, 2011, 03:08:50 am »
Code: [Select]

module main;

import dsfml.graphics.all;
import dsfml.window.all;
import std.stdio;

class ImageWrapper
{
private Image image;

this()
{
image = new Image(200, 200, Color.WHITE);
}

~this()
{
image.dispose();
}
}

void main()
{
try
{
try
auto img = new ImageWrapper;
catch(Exception e)
writeln(e.msg);
}
catch(Error e)
writeln(e.msg);
}


I'm guessing this throws an exception because the libraries are unloaded at the end of main(), and destruction occurs by the garbage collector after. If that's the case, then does that mean any wrappers I create need to be structs? Or am I misdiagnosing?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Exception-throwing in destruction
« Reply #1 on: February 03, 2011, 07:48:55 am »
Looks like the same problem that I had for the .Net binding. Apparently the GC is running in a thread that is not the main thread, which still runs after the latter has ended.
To solve this, the binding has to instanciate a dummy sf::Context in the GC thread.
Laurent Gomila - SFML developer

RobotGymnast

  • Jr. Member
  • **
  • Posts: 56
    • View Profile
Exception-throwing in destruction
« Reply #2 on: February 03, 2011, 12:50:56 pm »
Quote from: "Laurent"
Looks like the same problem that I had for the .Net binding. Apparently the GC is running in a thread that is not the main thread, which still runs after the latter has ended.
To solve this, the binding has to instanciate a dummy sf::Context in the GC thread.


I tried putting
Code: [Select]

auto context = new Context;


At the beginning of my thread, and it didn't like that one bit. What should I do?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Exception-throwing in destruction
« Reply #3 on: February 03, 2011, 01:24:57 pm »
Nothing, this has to be handled in the binding directly (if the problem is similar).
Laurent Gomila - SFML developer

RobotGymnast

  • Jr. Member
  • **
  • Posts: 56
    • View Profile
Exception-throwing in destruction
« Reply #4 on: February 03, 2011, 09:44:12 pm »
Quote from: "Laurent"
Nothing, this has to be handled in the binding directly (if the problem is similar).


So, for now, my solution has to be to put all wrappers inside scoped-destruction objects (i.e. structs)?

 

anything