Browse Source

Refining the Core API: Now interfaces and instancers are passed as raw pointers to RmlUi, and considered non-owning. It is the user's responsibility to keep the objects alive until after Core::Shutdown and then release these objects at their discretion.

Michael Ragazzon 6 years ago
parent
commit
130674a7b2
36 changed files with 327 additions and 306 deletions
  1. 4 4
      Include/RmlUi/Core/Context.h
  2. 13 15
      Include/RmlUi/Core/Core.h
  3. 1 5
      Include/RmlUi/Core/EventListenerInstancer.h
  4. 18 16
      Include/RmlUi/Core/Factory.h
  5. 1 0
      Include/RmlUi/Core/Types.h
  6. 8 9
      Samples/basic/animation/src/main.cpp
  7. 8 9
      Samples/basic/benchmark/src/main.cpp
  8. 5 4
      Samples/basic/bitmapfont/src/main.cpp
  9. 6 5
      Samples/basic/customlog/src/main.cpp
  10. 6 5
      Samples/basic/drag/src/main.cpp
  11. 5 4
      Samples/basic/loaddocument/src/main.cpp
  12. 11 11
      Samples/basic/sdl2/src/main.cpp
  13. 16 16
      Samples/basic/sfml2/src/main.cpp
  14. 5 5
      Samples/basic/transform/src/main.cpp
  15. 6 5
      Samples/basic/treeview/src/main.cpp
  16. 0 6
      Samples/invaders/src/EventInstancer.cpp
  17. 0 3
      Samples/invaders/src/EventInstancer.h
  18. 14 9
      Samples/invaders/src/main.cpp
  19. 3 3
      Samples/shell/src/macosx/ShellMacOSX.cpp
  20. 3 3
      Samples/shell/src/win32/ShellWin32.cpp
  21. 3 3
      Samples/shell/src/x11/ShellX11.cpp
  22. 0 12
      Samples/tutorial/datagrid/src/DecoratorInstancerDefender.cpp
  23. 0 7
      Samples/tutorial/datagrid/src/DecoratorInstancerDefender.h
  24. 8 6
      Samples/tutorial/datagrid/src/main.cpp
  25. 1 13
      Samples/tutorial/datagrid_tree/src/DecoratorInstancerDefender.cpp
  26. 0 7
      Samples/tutorial/datagrid_tree/src/DecoratorInstancerDefender.h
  27. 8 6
      Samples/tutorial/datagrid_tree/src/main.cpp
  28. 6 5
      Samples/tutorial/drag/src/main.cpp
  29. 6 5
      Samples/tutorial/template/src/main.cpp
  30. 38 13
      Source/Controls/Controls.cpp
  31. 5 5
      Source/Core/Context.cpp
  32. 23 22
      Source/Core/Core.cpp
  33. 1 2
      Source/Core/Element.cpp
  34. 77 54
      Source/Core/Factory.cpp
  35. 14 7
      Source/Debugger/Plugin.cpp
  36. 4 2
      Source/Debugger/Plugin.h

+ 4 - 4
Include/RmlUi/Core/Context.h

@@ -219,7 +219,7 @@ public:
 
 
 	/// Sets the instancer to use for releasing this object.
 	/// Sets the instancer to use for releasing this object.
 	/// @param[in] instancer The context's instancer.
 	/// @param[in] instancer The context's instancer.
-	void SetInstancer(SharedPtr<ContextInstancer> instancer);
+	void SetInstancer(ContextInstancer* instancer);
 
 
 protected:
 protected:
 	void Release() override;
 	void Release() override;
@@ -229,7 +229,7 @@ private:
 	Vector2i dimensions;
 	Vector2i dimensions;
 	float density_independent_pixel_ratio;
 	float density_independent_pixel_ratio;
 
 
-	SharedPtr<ContextInstancer> instancer;
+	ContextInstancer* instancer;
 
 
 	using ElementSet = SmallOrderedSet< Element* > ;
 	using ElementSet = SmallOrderedSet< Element* > ;
 	using ElementList = std::vector< Element* >;
 	using ElementList = std::vector< Element* >;
@@ -283,7 +283,7 @@ private:
 	Vector2i mouse_position;
 	Vector2i mouse_position;
 
 
 	// The render interface this context renders through.
 	// The render interface this context renders through.
-	SharedPtr<RenderInterface> render_interface;
+	RenderInterface* render_interface;
 	Vector2i clip_origin;
 	Vector2i clip_origin;
 	Vector2i clip_dimensions;
 	Vector2i clip_dimensions;
 
 
@@ -330,7 +330,7 @@ private:
 	static void SendEvents(const ElementSet& old_items, const ElementSet& new_items, EventId id, const Dictionary& parameters);
 	static void SendEvents(const ElementSet& old_items, const ElementSet& new_items, EventId id, const Dictionary& parameters);
 
 
 	friend class Element;
 	friend class Element;
-	friend RMLUICORE_API Context* CreateContext(const String&, const Vector2i&, SharedPtr<RenderInterface>);
+	friend RMLUICORE_API Context* CreateContext(const String&, const Vector2i&, RenderInterface*);
 };
 };
 
 
 }
 }

+ 13 - 15
Include/RmlUi/Core/Core.h

@@ -103,39 +103,37 @@ RMLUICORE_API void Shutdown();
 RMLUICORE_API String GetVersion();
 RMLUICORE_API String GetVersion();
 
 
 /// Sets the interface through which all system requests are made. This must be called before Initialise().
 /// Sets the interface through which all system requests are made. This must be called before Initialise().
-/// @param[in] system_interface The application-specified logging interface.
-/// @return The previously set system interface.
-RMLUICORE_API void SetSystemInterface(SharedPtr<SystemInterface> system_interface);
+/// @param[in] system_interface A non-owning pointer to the application-specified logging interface.
+/// @lifetime The interface must be kept alive until after the call to Core::Shutdown.
+RMLUICORE_API void SetSystemInterface(SystemInterface* system_interface);
 /// Returns RmlUi's system interface.
 /// Returns RmlUi's system interface.
-/// @return RmlUi's system interface.
 RMLUICORE_API SystemInterface* GetSystemInterface();
 RMLUICORE_API SystemInterface* GetSystemInterface();
-/// Returns a copy of the shared pointer to the system interface.
-RMLUICORE_API SharedPtr<SystemInterface> GetSystemInterfaceSharedPtr();
 
 
 /// Sets the interface through which all rendering requests are made. This is not required to be called, but if it is
 /// Sets the interface through which all rendering requests are made. This is not required to be called, but if it is
 /// it must be called before Initialise(). If no render interface is specified, then all contexts must have a custom
 /// it must be called before Initialise(). If no render interface is specified, then all contexts must have a custom
 /// render interface.
 /// render interface.
-/// @param[in] render_interface Render interface implementation.
-RMLUICORE_API void SetRenderInterface(SharedPtr<RenderInterface> render_interface);
+/// @param[in] render_interface A non-owning pointer to the render interface implementation.
+/// @lifetime The interface must be kept alive until after the call to Core::Shutdown.
+RMLUICORE_API void SetRenderInterface(RenderInterface* render_interface);
 /// Returns RmlUi's default's render interface.
 /// Returns RmlUi's default's render interface.
-/// @return RmlUi's render interface.
 RMLUICORE_API RenderInterface* GetRenderInterface();
 RMLUICORE_API RenderInterface* GetRenderInterface();
 
 
 /// Sets the interface through which all file I/O requests are made. This is not required to be called, but if it is it
 /// Sets the interface through which all file I/O requests are made. This is not required to be called, but if it is it
 /// must be called before Initialise().
 /// must be called before Initialise().
-/// @param[in] file_interface The application-specified file interface
-RMLUICORE_API void SetFileInterface(SharedPtr<FileInterface> file_interface);
+/// @param[in] file_interface A non-owning pointer to the application-specified file interface.
+/// @lifetime The interface must be kept alive until after the call to Core::Shutdown.
+RMLUICORE_API void SetFileInterface(FileInterface* file_interface);
 /// Returns RmlUi's file interface.
 /// Returns RmlUi's file interface.
-/// @return RmlUi's file interface.
 RMLUICORE_API FileInterface* GetFileInterface();
 RMLUICORE_API FileInterface* GetFileInterface();
 
 
 /// Creates a new element context.
 /// Creates a new element context.
 /// @param[in] name The new name of the context. This must be unique.
 /// @param[in] name The new name of the context. This must be unique.
 /// @param[in] dimensions The initial dimensions of the new context.
 /// @param[in] dimensions The initial dimensions of the new context.
 /// @param[in] render_interface The custom render interface to use, or NULL to use the default.
 /// @param[in] render_interface The custom render interface to use, or NULL to use the default.
-/// @return The new context, or NULL if the context could not be created.
-RMLUICORE_API Context* CreateContext(const String& name, const Vector2i& dimensions, SharedPtr<RenderInterface> render_interface = nullptr);
-/// Removes a context.
+/// @lifetime If specified, the render interface must be kept alive until after the context is destroyed or the call to Core::Shutdown.
+/// @return A non-owning pointer to the new context, or NULL if the context could not be created.
+RMLUICORE_API Context* CreateContext(const String& name, const Vector2i& dimensions, RenderInterface* render_interface = nullptr);
+/// Removes and destroys a context.
 /// @param[in] name The name of the context to remove.
 /// @param[in] name The name of the context to remove.
 /// @return True if name is a valid context, false otherwise.
 /// @return True if name is a valid context, false otherwise.
 RMLUICORE_API bool RemoveContext(const String& name);
 RMLUICORE_API bool RemoveContext(const String& name);

+ 1 - 5
Include/RmlUi/Core/EventListenerInstancer.h

@@ -46,7 +46,7 @@ class EventListener;
 	@author Lloyd Weehuizen
 	@author Lloyd Weehuizen
  */
  */
 
 
-class RMLUICORE_API EventListenerInstancer : public Releasable
+class RMLUICORE_API EventListenerInstancer
 {
 {
 public:
 public:
 	virtual ~EventListenerInstancer();
 	virtual ~EventListenerInstancer();
@@ -55,10 +55,6 @@ public:
 	/// @param value Value of the event.
 	/// @param value Value of the event.
 	/// @param element Element that triggers the events.
 	/// @param element Element that triggers the events.
 	virtual EventListener* InstanceEventListener(const String& value, Element* element) = 0;
 	virtual EventListener* InstanceEventListener(const String& value, Element* element) = 0;
-
-protected:
-	/// Releases this event listener instancer.
-	virtual void Release() = 0;
 };
 };
 
 
 }
 }

+ 18 - 16
Include/RmlUi/Core/Factory.h

@@ -71,19 +71,20 @@ public:
 	/// Cleanup and shutdown the factory
 	/// Cleanup and shutdown the factory
 	static void Shutdown();
 	static void Shutdown();
 
 
-	/// Registers the instancer to use when instancing contexts.
+	/// Registers a non-owning pointer to the instancer used to instance contexts.
 	/// @param[in] instancer The new context instancer.
 	/// @param[in] instancer The new context instancer.
-	static ContextInstancer* RegisterContextInstancer(SharedPtr<ContextInstancer> instancer);
+	/// @lifetime The instancer must be kept alive until after the call to Core::Shutdown.
+	static void RegisterContextInstancer(ContextInstancer* instancer);
 	/// Instances a new context.
 	/// Instances a new context.
 	/// @param[in] name The name of the new context.
 	/// @param[in] name The name of the new context.
 	/// @return The new context, or NULL if no context could be created.
 	/// @return The new context, or NULL if no context could be created.
 	static UniquePtr<Context> InstanceContext(const String& name);
 	static UniquePtr<Context> InstanceContext(const String& name);
 
 
-	/// Registers an element instancer that will be used to instance an element when the specified tag is encountered.
+	/// Registers a non-owning pointer to the element instancer that will be used to instance an element when the specified tag is encountered.
 	/// @param[in] name Name of the instancer; elements with this as their tag will use this instancer.
 	/// @param[in] name Name of the instancer; elements with this as their tag will use this instancer.
 	/// @param[in] instancer The instancer to call when the tag is encountered.
 	/// @param[in] instancer The instancer to call when the tag is encountered.
-	/// @return The added instancer if the registration was successful, NULL otherwise.
-	static ElementInstancer* RegisterElementInstancer(const String& name, ElementInstancerPtr instancer);
+	/// @lifetime The instancer must be kept alive until after the call to Core::Shutdown.
+	static void RegisterElementInstancer(const String& name, ElementInstancer* instancer);
 	/// Returns the element instancer for the specified tag.
 	/// Returns the element instancer for the specified tag.
 	/// @param[in] tag Name of the tag to get the instancer for.
 	/// @param[in] tag Name of the tag to get the instancer for.
 	/// @return The requested element instancer, or NULL if no such instancer is registered.
 	/// @return The requested element instancer, or NULL if no such instancer is registered.
@@ -113,27 +114,29 @@ public:
 	/// @return The instanced document, or NULL if an error occurred.
 	/// @return The instanced document, or NULL if an error occurred.
 	static ElementPtr InstanceDocumentStream(Rml::Core::Context* context, Stream* stream);
 	static ElementPtr InstanceDocumentStream(Rml::Core::Context* context, Stream* stream);
 
 
-	/// Registers an instancer that will be used to instance decorators.
+	/// Registers a non-owning pointer to an instancer that will be used to instance decorators.
 	/// @param[in] name The name of the decorator the instancer will be called for.
 	/// @param[in] name The name of the decorator the instancer will be called for.
 	/// @param[in] instancer The instancer to call when the decorator name is encountered.
 	/// @param[in] instancer The instancer to call when the decorator name is encountered.
+	/// @lifetime The instancer must be kept alive until after the call to Core::Shutdown.
 	/// @return The added instancer if the registration was successful, NULL otherwise.
 	/// @return The added instancer if the registration was successful, NULL otherwise.
-	static void RegisterDecoratorInstancer(const String& name, std::unique_ptr<DecoratorInstancer> instancer);
+	static void RegisterDecoratorInstancer(const String& name, DecoratorInstancer* instancer);
 	/// Retrieves a decorator instancer registered with the factory.
 	/// Retrieves a decorator instancer registered with the factory.
 	/// @param[in] name The name of the desired decorator type.
 	/// @param[in] name The name of the desired decorator type.
 	/// @return The decorator instancer it it exists, NULL otherwise.
 	/// @return The decorator instancer it it exists, NULL otherwise.
 	static DecoratorInstancer* GetDecoratorInstancer(const String& name);
 	static DecoratorInstancer* GetDecoratorInstancer(const String& name);
 
 
-	/// Registers an instancer that will be used to instance font effects.
+	/// Registers a non-owning pointer to an instancer that will be used to instance font effects.
 	/// @param[in] name The name of the font effect the instancer will be called for.
 	/// @param[in] name The name of the font effect the instancer will be called for.
 	/// @param[in] instancer The instancer to call when the font effect name is encountered.
 	/// @param[in] instancer The instancer to call when the font effect name is encountered.
+	/// @lifetime The instancer must be kept alive until after the call to Core::Shutdown.
 	/// @return The added instancer if the registration was successful, NULL otherwise.
 	/// @return The added instancer if the registration was successful, NULL otherwise.
-	static void RegisterFontEffectInstancer(const String& name, std::unique_ptr<FontEffectInstancer> instancer);
+	static void RegisterFontEffectInstancer(const String& name, FontEffectInstancer* instancer);
 	/// Retrieves a font-effect instancer registered with the factory.
 	/// Retrieves a font-effect instancer registered with the factory.
 	/// @param[in] name The name of the desired font-effect type.
 	/// @param[in] name The name of the desired font-effect type.
 	/// @return The font-effect instancer it it exists, NULL otherwise.
 	/// @return The font-effect instancer it it exists, NULL otherwise.
 	static FontEffectInstancer* GetFontEffectInstancer(const String& name);
 	static FontEffectInstancer* GetFontEffectInstancer(const String& name);
 
 
-/// Creates a style sheet from a user-generated string.
+	/// Creates a style sheet from a user-generated string.
 	/// @param[in] string The contents of the style sheet.
 	/// @param[in] string The contents of the style sheet.
 	/// @return A pointer to the newly created style sheet.
 	/// @return A pointer to the newly created style sheet.
 	static SharedPtr<StyleSheet> InstanceStyleSheetString(const String& string);
 	static SharedPtr<StyleSheet> InstanceStyleSheetString(const String& string);
@@ -152,8 +155,8 @@ public:
 
 
 	/// Registers an instancer for all events.
 	/// Registers an instancer for all events.
 	/// @param[in] instancer The instancer to be called.
 	/// @param[in] instancer The instancer to be called.
-	/// @return The registered instanced on success, NULL on failure.
-	static EventInstancer* RegisterEventInstancer(UniquePtr<EventInstancer> instancer);
+	/// @lifetime The instancer must be kept alive until after the call to Core::Shutdown.
+	static void RegisterEventInstancer(EventInstancer* instancer);
 	/// Instance and event object
 	/// Instance and event object
 	/// @param[in] target Target element of this event.
 	/// @param[in] target Target element of this event.
 	/// @param[in] name Name of this event.
 	/// @param[in] name Name of this event.
@@ -163,10 +166,9 @@ public:
 	static UniquePtr<Event> InstanceEvent(Element* target, EventId id, const String& type, const Dictionary& parameters, bool interruptible);
 	static UniquePtr<Event> InstanceEvent(Element* target, EventId id, const String& type, const Dictionary& parameters, bool interruptible);
 
 
 	/// Register the instancer to be used for all event listeners.
 	/// Register the instancer to be used for all event listeners.
-	/// @return The registered instancer on success, NULL on failure.
-	static EventListenerInstancer* RegisterEventListenerInstancer(UniquePtr<EventListenerInstancer> instancer);
-	/// Instance an event listener with the given string. This is used for instancing listeners for the on* events from
-	/// RML.
+	/// @lifetime The instancer must be kept alive until after the call to Core::Shutdown.
+	static void RegisterEventListenerInstancer(EventListenerInstancer* instancer);
+	/// Instance an event listener with the given string. This is used for instancing listeners for the on* events from RML.
 	/// @param[in] value The parameters to the event listener.
 	/// @param[in] value The parameters to the event listener.
 	/// @return The instanced event listener.
 	/// @return The instanced event listener.
 	static EventListener* InstanceEventListener(const String& value, Element* element);
 	static EventListener* InstanceEventListener(const String& value, Element* element);

+ 1 - 0
Include/RmlUi/Core/Types.h

@@ -103,6 +103,7 @@ using UniquePtr = std::unique_ptr<T, Releaser<T>>;
 template<typename T>
 template<typename T>
 using SharedPtr = std::shared_ptr<T>;
 using SharedPtr = std::shared_ptr<T>;
 
 
+
 class Element;
 class Element;
 class ElementInstancer;
 class ElementInstancer;
 using ElementPtr = UniquePtr<Element>;
 using ElementPtr = UniquePtr<Element>;

+ 8 - 9
Samples/basic/animation/src/main.cpp

@@ -300,9 +300,6 @@ public:
 	{
 	{
 		return new Event(value);
 		return new Event(value);
 	}
 	}
-
-	/// Destroys the instancer.
-	void Release() override { delete this; }
 };
 };
 
 
 
 
@@ -327,8 +324,8 @@ int main(int RMLUI_UNUSED_PARAMETER(argc), char** RMLUI_UNUSED_PARAMETER(argv))
 	const int height = 1000;
 	const int height = 1000;
 
 
 
 
-	auto opengl_renderer = std::make_shared<ShellRenderInterfaceOpenGL>();
-	shell_renderer = opengl_renderer.get();
+	ShellRenderInterfaceOpenGL opengl_renderer;
+	shell_renderer = &opengl_renderer;
 
 
 	// Generic OS initialisation, creates a window and attaches OpenGL.
 	// Generic OS initialisation, creates a window and attaches OpenGL.
 	if (!Shell::Initialise() ||
 	if (!Shell::Initialise() ||
@@ -339,10 +336,11 @@ int main(int RMLUI_UNUSED_PARAMETER(argc), char** RMLUI_UNUSED_PARAMETER(argv))
 	}
 	}
 
 
 	// RmlUi initialisation.
 	// RmlUi initialisation.
-	Rml::Core::SetRenderInterface(opengl_renderer);
-	opengl_renderer->SetViewport(width, height);
+	Rml::Core::SetRenderInterface(&opengl_renderer);
+	opengl_renderer.SetViewport(width, height);
 
 
-	Rml::Core::SetSystemInterface(std::make_shared<ShellSystemInterface>());
+	ShellSystemInterface system_interface;
+	Rml::Core::SetSystemInterface(&system_interface);
 
 
 	Rml::Core::Initialise();
 	Rml::Core::Initialise();
 
 
@@ -360,7 +358,8 @@ int main(int RMLUI_UNUSED_PARAMETER(argc), char** RMLUI_UNUSED_PARAMETER(argv))
 	Input::SetContext(context);
 	Input::SetContext(context);
 	shell_renderer->SetContext(context);
 	shell_renderer->SetContext(context);
 
 
-	Rml::Core::Factory::RegisterEventListenerInstancer(Rml::Core::UniquePtr<Rml::Core::EventListenerInstancer>(new EventInstancer));
+	EventInstancer event_listener_instancer;
+	Rml::Core::Factory::RegisterEventListenerInstancer(&event_listener_instancer);
 
 
 	Shell::LoadFonts("assets/");
 	Shell::LoadFonts("assets/");
 
 

+ 8 - 9
Samples/basic/benchmark/src/main.cpp

@@ -261,9 +261,6 @@ public:
 	{
 	{
 		return new Event(value);
 		return new Event(value);
 	}
 	}
-
-	/// Destroys the instancer.
-	void Release() override { delete this; }
 };
 };
 
 
 
 
@@ -287,8 +284,8 @@ int main(int RMLUI_UNUSED_PARAMETER(argc), char** RMLUI_UNUSED_PARAMETER(argv))
 	const int width = 1800;
 	const int width = 1800;
 	const int height = 1000;
 	const int height = 1000;
 
 
-	auto opengl_renderer = std::make_shared<ShellRenderInterfaceOpenGL>();
-	shell_renderer = opengl_renderer.get();
+	ShellRenderInterfaceOpenGL opengl_renderer;
+	shell_renderer = &opengl_renderer;
 
 
 	// Generic OS initialisation, creates a window and attaches OpenGL.
 	// Generic OS initialisation, creates a window and attaches OpenGL.
 	if (!Shell::Initialise() ||
 	if (!Shell::Initialise() ||
@@ -299,10 +296,11 @@ int main(int RMLUI_UNUSED_PARAMETER(argc), char** RMLUI_UNUSED_PARAMETER(argv))
 	}
 	}
 
 
 	// RmlUi initialisation.
 	// RmlUi initialisation.
-	Rml::Core::SetRenderInterface(opengl_renderer);
-	opengl_renderer->SetViewport(width, height);
+	Rml::Core::SetRenderInterface(&opengl_renderer);
+	opengl_renderer.SetViewport(width, height);
 
 
-	Rml::Core::SetSystemInterface(std::make_shared<ShellSystemInterface>());
+	ShellSystemInterface system_interface;
+	Rml::Core::SetSystemInterface(&system_interface);
 
 
 	Rml::Core::Initialise();
 	Rml::Core::Initialise();
 
 
@@ -320,7 +318,8 @@ int main(int RMLUI_UNUSED_PARAMETER(argc), char** RMLUI_UNUSED_PARAMETER(argv))
 	Input::SetContext(context);
 	Input::SetContext(context);
 	shell_renderer->SetContext(context);
 	shell_renderer->SetContext(context);
 
 
-	Rml::Core::Factory::RegisterEventListenerInstancer(Rml::Core::UniquePtr<Rml::Core::EventListenerInstancer>(new EventInstancer));
+	EventInstancer event_listener_instancer;
+	Rml::Core::Factory::RegisterEventListenerInstancer(&event_listener_instancer);
 
 
 	Shell::LoadFonts("assets/");
 	Shell::LoadFonts("assets/");
 
 

+ 5 - 4
Samples/basic/bitmapfont/src/main.cpp

@@ -69,8 +69,8 @@ int main(int RMLUI_UNUSED_PARAMETER(argc), char** RMLUI_UNUSED_PARAMETER(argv))
     int window_width = 1024;
     int window_width = 1024;
     int window_height = 768;
     int window_height = 768;
 
 
-	auto opengl_renderer = std::make_shared<ShellRenderInterfaceOpenGL>();
-	shell_renderer = opengl_renderer.get();
+	ShellRenderInterfaceOpenGL opengl_renderer;
+	shell_renderer = &opengl_renderer;
 
 
 	// Generic OS initialisation, creates a window and attaches OpenGL.
 	// Generic OS initialisation, creates a window and attaches OpenGL.
 	if (!Shell::Initialise() ||
 	if (!Shell::Initialise() ||
@@ -81,10 +81,11 @@ int main(int RMLUI_UNUSED_PARAMETER(argc), char** RMLUI_UNUSED_PARAMETER(argv))
 	}
 	}
 
 
 	// RmlUi initialisation.
 	// RmlUi initialisation.
-	Rml::Core::SetRenderInterface(opengl_renderer);
+	Rml::Core::SetRenderInterface(&opengl_renderer);
 	shell_renderer->SetViewport(window_width, window_height);
 	shell_renderer->SetViewport(window_width, window_height);
 
 
-	Rml::Core::SetSystemInterface(std::make_shared<ShellSystemInterface>());
+	ShellSystemInterface system_interface;
+	Rml::Core::SetSystemInterface(&system_interface);
 
 
 	Rml::Core::Initialise();
 	Rml::Core::Initialise();
 
 

+ 6 - 5
Samples/basic/customlog/src/main.cpp

@@ -70,8 +70,8 @@ int main(int RMLUI_UNUSED_PARAMETER(argc), char** RMLUI_UNUSED_PARAMETER(argv))
 	int window_width = 1024;
 	int window_width = 1024;
 	int window_height = 768;
 	int window_height = 768;
 
 
-	auto opengl_renderer = std::make_shared<ShellRenderInterfaceOpenGL>();
-	shell_renderer = opengl_renderer.get();
+	ShellRenderInterfaceOpenGL opengl_renderer;
+	shell_renderer = &opengl_renderer;
 
 
 	// Generic OS initialisation, creates a window and attaches OpenGL.
 	// Generic OS initialisation, creates a window and attaches OpenGL.
 	if (!Shell::Initialise() ||
 	if (!Shell::Initialise() ||
@@ -82,11 +82,12 @@ int main(int RMLUI_UNUSED_PARAMETER(argc), char** RMLUI_UNUSED_PARAMETER(argv))
 	}
 	}
 
 
 	// RmlUi initialisation.
 	// RmlUi initialisation.
-	Rml::Core::SetRenderInterface(opengl_renderer);
-	opengl_renderer->SetViewport(window_width, window_height);
+	Rml::Core::SetRenderInterface(&opengl_renderer);
+	opengl_renderer.SetViewport(window_width, window_height);
 
 
 	// Initialise our system interface to write the log messages to file.
 	// Initialise our system interface to write the log messages to file.
-	Rml::Core::SetSystemInterface(std::make_shared<ShellSystemInterface>());
+	ShellSystemInterface system_interface;
+	Rml::Core::SetSystemInterface(&system_interface);
 
 
 	Rml::Core::Initialise();
 	Rml::Core::Initialise();
 
 

+ 6 - 5
Samples/basic/drag/src/main.cpp

@@ -76,8 +76,8 @@ int main(int RMLUI_UNUSED_PARAMETER(argc), char** RMLUI_UNUSED_PARAMETER(argv))
     int window_width = 1024;
     int window_width = 1024;
     int window_height = 768;
     int window_height = 768;
 
 
-	auto opengl_renderer = std::make_shared<ShellRenderInterfaceOpenGL>();
-	shell_renderer = opengl_renderer.get();
+	ShellRenderInterfaceOpenGL opengl_renderer;
+	shell_renderer = &opengl_renderer;
 
 
 	// Generic OS initialisation, creates a window and attaches OpenGL.
 	// Generic OS initialisation, creates a window and attaches OpenGL.
 	if (!Shell::Initialise() ||
 	if (!Shell::Initialise() ||
@@ -88,10 +88,11 @@ int main(int RMLUI_UNUSED_PARAMETER(argc), char** RMLUI_UNUSED_PARAMETER(argv))
 	}
 	}
 
 
 	// RmlUi initialisation.
 	// RmlUi initialisation.
-	Rml::Core::SetRenderInterface(opengl_renderer);
-	opengl_renderer->SetViewport(window_width, window_height);
+	Rml::Core::SetRenderInterface(&opengl_renderer);
+	opengl_renderer.SetViewport(window_width, window_height);
 
 
-	Rml::Core::SetSystemInterface(std::make_shared<ShellSystemInterface>());
+	ShellSystemInterface system_interface;
+	Rml::Core::SetSystemInterface(&system_interface);
 
 
 	Rml::Core::Initialise();
 	Rml::Core::Initialise();
 
 

+ 5 - 4
Samples/basic/loaddocument/src/main.cpp

@@ -69,8 +69,8 @@ int main(int RMLUI_UNUSED_PARAMETER(argc), char** RMLUI_UNUSED_PARAMETER(argv))
     int window_width = 1024;
     int window_width = 1024;
     int window_height = 768;
     int window_height = 768;
 
 
-	auto opengl_renderer = std::make_shared<ShellRenderInterfaceOpenGL>();
-	shell_renderer = opengl_renderer.get();
+	ShellRenderInterfaceOpenGL opengl_renderer;
+	shell_renderer = &opengl_renderer;
 
 
 	// Generic OS initialisation, creates a window and attaches OpenGL.
 	// Generic OS initialisation, creates a window and attaches OpenGL.
 	if (!Shell::Initialise() ||
 	if (!Shell::Initialise() ||
@@ -81,10 +81,11 @@ int main(int RMLUI_UNUSED_PARAMETER(argc), char** RMLUI_UNUSED_PARAMETER(argv))
 	}
 	}
 
 
 	// RmlUi initialisation.
 	// RmlUi initialisation.
-	Rml::Core::SetRenderInterface(opengl_renderer);
+	Rml::Core::SetRenderInterface(&opengl_renderer);
 	shell_renderer->SetViewport(window_width, window_height);
 	shell_renderer->SetViewport(window_width, window_height);
 
 
-	Rml::Core::SetSystemInterface(std::make_shared<ShellSystemInterface>());
+	ShellSystemInterface system_interface;
+	Rml::Core::SetSystemInterface(&system_interface);
 
 
 	Rml::Core::Initialise();
 	Rml::Core::Initialise();
 
 

+ 11 - 11
Samples/basic/sdl2/src/main.cpp

@@ -76,15 +76,15 @@ int main(int argc, char **argv)
     glLoadIdentity();
     glLoadIdentity();
     glOrtho(0, window_width, window_height, 0, 0, 1);
     glOrtho(0, window_width, window_height, 0, 0, 1);
  
  
-	auto Renderer = std::make_shared<RmlUiSDL2Renderer>(renderer, screen);
-	auto SystemInterface = std::make_shared<RmlUiSDL2SystemInterface>();
+	RmlUiSDL2Renderer Renderer(renderer, screen);
+	RmlUiSDL2SystemInterface SystemInterface;
 	
 	
 	Rml::Core::String root = Shell::FindSamplesRoot();
 	Rml::Core::String root = Shell::FindSamplesRoot();
-	auto FileInterface = std::make_shared<ShellFileInterface>(root);
+	ShellFileInterface FileInterface(root);
 
 
-	Rml::Core::SetFileInterface(FileInterface);
-	Rml::Core::SetRenderInterface(Renderer);
-    Rml::Core::SetSystemInterface(SystemInterface);
+	Rml::Core::SetFileInterface(&FileInterface);
+	Rml::Core::SetRenderInterface(&Renderer);
+    Rml::Core::SetSystemInterface(&SystemInterface);
 
 
 	if(!Rml::Core::Initialise())
 	if(!Rml::Core::Initialise())
 		return 1;
 		return 1;
@@ -132,18 +132,18 @@ int main(int argc, char **argv)
                     break;
                     break;
 
 
                 case SDL_MOUSEMOTION:
                 case SDL_MOUSEMOTION:
-                    Context->ProcessMouseMove(event.motion.x, event.motion.y, SystemInterface->GetKeyModifiers());
+                    Context->ProcessMouseMove(event.motion.x, event.motion.y, SystemInterface.GetKeyModifiers());
                     break;
                     break;
                 case SDL_MOUSEBUTTONDOWN:
                 case SDL_MOUSEBUTTONDOWN:
-                    Context->ProcessMouseButtonDown(SystemInterface->TranslateMouseButton(event.button.button), SystemInterface->GetKeyModifiers());
+                    Context->ProcessMouseButtonDown(SystemInterface.TranslateMouseButton(event.button.button), SystemInterface.GetKeyModifiers());
                     break;
                     break;
 
 
                 case SDL_MOUSEBUTTONUP:
                 case SDL_MOUSEBUTTONUP:
-                    Context->ProcessMouseButtonUp(SystemInterface->TranslateMouseButton(event.button.button), SystemInterface->GetKeyModifiers());
+                    Context->ProcessMouseButtonUp(SystemInterface.TranslateMouseButton(event.button.button), SystemInterface.GetKeyModifiers());
                     break;
                     break;
 
 
                 case SDL_MOUSEWHEEL:
                 case SDL_MOUSEWHEEL:
-                    Context->ProcessMouseWheel(event.wheel.y, SystemInterface->GetKeyModifiers());
+                    Context->ProcessMouseWheel(event.wheel.y, SystemInterface.GetKeyModifiers());
                     break;
                     break;
 
 
                 case SDL_KEYDOWN:
                 case SDL_KEYDOWN:
@@ -155,7 +155,7 @@ int main(int argc, char **argv)
                         break;
                         break;
                     }
                     }
                     
                     
-                    Context->ProcessKeyDown(SystemInterface->TranslateKey(event.key.keysym.sym), SystemInterface->GetKeyModifiers());
+                    Context->ProcessKeyDown(SystemInterface.TranslateKey(event.key.keysym.sym), SystemInterface.GetKeyModifiers());
                     break;
                     break;
                 }
                 }
                 
                 

+ 16 - 16
Samples/basic/sfml2/src/main.cpp

@@ -68,22 +68,22 @@ int main(int argc, char **argv)
 	fprintf(stdout, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION));
 	fprintf(stdout, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION));
 #endif
 #endif
 
 
-	auto Renderer = std::make_shared<RmlUiSFMLRenderer>();
-	auto SystemInterface = std::make_shared<RmlUiSFMLSystemInterface>();
+	RmlUiSFMLRenderer Renderer;
+	RmlUiSFMLSystemInterface SystemInterface;
 
 
 	// NOTE: if fonts and rml are not found you'll probably have to adjust
 	// NOTE: if fonts and rml are not found you'll probably have to adjust
 	// the path information in the string
 	// the path information in the string
 	Rml::Core::String root = Shell::FindSamplesRoot();
 	Rml::Core::String root = Shell::FindSamplesRoot();
-	auto FileInterface = std::make_shared<ShellFileInterface>(root);
+	ShellFileInterface FileInterface(root);
 
 
 	if(!MyWindow.isOpen())
 	if(!MyWindow.isOpen())
 		return 1;
 		return 1;
 
 
-	Renderer->SetWindow(&MyWindow);
+	Renderer.SetWindow(&MyWindow);
 
 
-	Rml::Core::SetFileInterface(FileInterface);
-	Rml::Core::SetRenderInterface(Renderer);
-	Rml::Core::SetSystemInterface(SystemInterface);
+	Rml::Core::SetFileInterface(&FileInterface);
+	Rml::Core::SetRenderInterface(&Renderer);
+	Rml::Core::SetSystemInterface(&SystemInterface);
 
 
 
 
 	if(!Rml::Core::Initialise())
 	if(!Rml::Core::Initialise())
@@ -124,31 +124,31 @@ int main(int argc, char **argv)
 			switch(event.type)
 			switch(event.type)
 			{
 			{
 			case sf::Event::Resized:
 			case sf::Event::Resized:
-				Renderer->Resize();
+				Renderer.Resize();
 				break;
 				break;
 			case sf::Event::MouseMoved:
 			case sf::Event::MouseMoved:
 				Context->ProcessMouseMove(event.mouseMove.x, event.mouseMove.y,
 				Context->ProcessMouseMove(event.mouseMove.x, event.mouseMove.y,
-					SystemInterface->GetKeyModifiers(&MyWindow));
+					SystemInterface.GetKeyModifiers(&MyWindow));
 				break;
 				break;
 			case sf::Event::MouseButtonPressed:
 			case sf::Event::MouseButtonPressed:
 				Context->ProcessMouseButtonDown(event.mouseButton.button,
 				Context->ProcessMouseButtonDown(event.mouseButton.button,
-					SystemInterface->GetKeyModifiers(&MyWindow));
+					SystemInterface.GetKeyModifiers(&MyWindow));
 				break;
 				break;
 			case sf::Event::MouseButtonReleased:
 			case sf::Event::MouseButtonReleased:
 				Context->ProcessMouseButtonUp(event.mouseButton.button,
 				Context->ProcessMouseButtonUp(event.mouseButton.button,
-					SystemInterface->GetKeyModifiers(&MyWindow));
+					SystemInterface.GetKeyModifiers(&MyWindow));
 				break;
 				break;
 			case sf::Event::MouseWheelMoved:
 			case sf::Event::MouseWheelMoved:
 				Context->ProcessMouseWheel(-event.mouseWheel.delta,
 				Context->ProcessMouseWheel(-event.mouseWheel.delta,
-					SystemInterface->GetKeyModifiers(&MyWindow));
+					SystemInterface.GetKeyModifiers(&MyWindow));
 				break;
 				break;
 			case sf::Event::TextEntered:
 			case sf::Event::TextEntered:
 				if (event.text.unicode > 32)
 				if (event.text.unicode > 32)
 					Context->ProcessTextInput(event.text.unicode);
 					Context->ProcessTextInput(event.text.unicode);
 				break;
 				break;
 			case sf::Event::KeyPressed:
 			case sf::Event::KeyPressed:
-				Context->ProcessKeyDown(SystemInterface->TranslateKey(event.key.code),
-					SystemInterface->GetKeyModifiers(&MyWindow));
+				Context->ProcessKeyDown(SystemInterface.TranslateKey(event.key.code),
+					SystemInterface.GetKeyModifiers(&MyWindow));
 				break;
 				break;
 			case sf::Event::KeyReleased:
 			case sf::Event::KeyReleased:
 				if(event.key.code == sf::Keyboard::F8)
 				if(event.key.code == sf::Keyboard::F8)
@@ -160,8 +160,8 @@ int main(int argc, char **argv)
 					MyWindow.close();
 					MyWindow.close();
 				}
 				}
 
 
-				Context->ProcessKeyUp(SystemInterface->TranslateKey(event.key.code),
-					SystemInterface->GetKeyModifiers(&MyWindow));
+				Context->ProcessKeyUp(SystemInterface.TranslateKey(event.key.code),
+					SystemInterface.GetKeyModifiers(&MyWindow));
 				break;
 				break;
 			case sf::Event::Closed:
 			case sf::Event::Closed:
 				MyWindow.close();
 				MyWindow.close();

+ 5 - 5
Samples/basic/transform/src/main.cpp

@@ -134,8 +134,8 @@ int main(int RMLUI_UNUSED_PARAMETER(argc), char** RMLUI_UNUSED_PARAMETER(argv))
 	RMLUI_UNUSED(argv);
 	RMLUI_UNUSED(argv);
 #endif
 #endif
 
 
-	auto opengl_renderer = std::make_shared<ShellRenderInterfaceOpenGL>();
-	shell_renderer = opengl_renderer.get();
+	ShellRenderInterfaceOpenGL opengl_renderer;
+	shell_renderer = &opengl_renderer;
 
 
 	// Generic OS initialisation, creates a window and attaches OpenGL.
 	// Generic OS initialisation, creates a window and attaches OpenGL.
 	if (!Shell::Initialise() ||
 	if (!Shell::Initialise() ||
@@ -146,11 +146,11 @@ int main(int RMLUI_UNUSED_PARAMETER(argc), char** RMLUI_UNUSED_PARAMETER(argv))
 	}
 	}
 
 
 	// RmlUi initialisation.
 	// RmlUi initialisation.
-	Rml::Core::SetRenderInterface(opengl_renderer);
-	opengl_renderer->SetViewport(1024,768);
+	Rml::Core::SetRenderInterface(&opengl_renderer);
+	opengl_renderer.SetViewport(1024,768);
 
 
 	ShellSystemInterface system_interface;
 	ShellSystemInterface system_interface;
-	Rml::Core::SetSystemInterface(std::make_shared<ShellSystemInterface>());
+	Rml::Core::SetSystemInterface(&system_interface);
 
 
 	Rml::Core::Initialise();
 	Rml::Core::Initialise();
 
 

+ 6 - 5
Samples/basic/treeview/src/main.cpp

@@ -72,8 +72,8 @@ int main(int RMLUI_UNUSED_PARAMETER(argc), char** RMLUI_UNUSED_PARAMETER(argv))
 	int window_width = 1024;
 	int window_width = 1024;
 	int window_height = 768;
 	int window_height = 768;
 
 
-	auto opengl_renderer = std::make_shared<ShellRenderInterfaceOpenGL>();
-	shell_renderer = opengl_renderer.get();
+	ShellRenderInterfaceOpenGL opengl_renderer;
+	shell_renderer = &opengl_renderer;
 
 
 	// Generic OS initialisation, creates a window and attaches OpenGL.
 	// Generic OS initialisation, creates a window and attaches OpenGL.
 	if (!Shell::Initialise() ||
 	if (!Shell::Initialise() ||
@@ -84,10 +84,11 @@ int main(int RMLUI_UNUSED_PARAMETER(argc), char** RMLUI_UNUSED_PARAMETER(argv))
 	}
 	}
 
 
 	// RmlUi initialisation.
 	// RmlUi initialisation.
-	Rml::Core::SetRenderInterface(opengl_renderer);
-	opengl_renderer->SetViewport(window_width, window_height);
+	Rml::Core::SetRenderInterface(&opengl_renderer);
+	opengl_renderer.SetViewport(window_width, window_height);
 
 
-	Rml::Core::SetSystemInterface(std::make_shared<ShellSystemInterface>());
+	ShellSystemInterface system_interface;
+	Rml::Core::SetSystemInterface(&system_interface);
 
 
 	Rml::Core::Initialise();
 	Rml::Core::Initialise();
 
 

+ 0 - 6
Samples/invaders/src/EventInstancer.cpp

@@ -42,9 +42,3 @@ Rml::Core::EventListener* EventInstancer::InstanceEventListener(const Rml::Core:
 {
 {
 	return new Event(value);
 	return new Event(value);
 }
 }
-
-// Destroys the instancer.
-void EventInstancer::Release()
-{
-	delete this;
-}

+ 0 - 3
Samples/invaders/src/EventInstancer.h

@@ -44,9 +44,6 @@ public:
 	/// Instances a new event handle for Invaders.
 	/// Instances a new event handle for Invaders.
 	Rml::Core::EventListener* InstanceEventListener(const Rml::Core::String& value, Rml::Core::Element* element) override;
 	Rml::Core::EventListener* InstanceEventListener(const Rml::Core::String& value, Rml::Core::Element* element) override;
 
 
-protected:
-	/// Destroys the instancer.
-	void Release() override;
 };
 };
 
 
 #endif
 #endif

+ 14 - 9
Samples/invaders/src/main.cpp

@@ -81,8 +81,8 @@ int main(int RMLUI_UNUSED_PARAMETER(argc), char** RMLUI_UNUSED_PARAMETER(argv))
 	int window_width = 1024;
 	int window_width = 1024;
 	int window_height = 768;
 	int window_height = 768;
 
 
-	auto opengl_renderer = std::make_shared<ShellRenderInterfaceOpenGL>();
-	shell_renderer = opengl_renderer.get();
+	ShellRenderInterfaceOpenGL opengl_renderer;
+	shell_renderer = &opengl_renderer;
 
 
 	// Generic OS initialisation, creates a window and attaches OpenGL.
 	// Generic OS initialisation, creates a window and attaches OpenGL.
 	if (!Shell::Initialise() ||
 	if (!Shell::Initialise() ||
@@ -93,10 +93,11 @@ int main(int RMLUI_UNUSED_PARAMETER(argc), char** RMLUI_UNUSED_PARAMETER(argv))
 	}
 	}
 
 
 	// RmlUi initialisation.
 	// RmlUi initialisation.
-	Rml::Core::SetRenderInterface(opengl_renderer);
-	opengl_renderer->SetViewport(window_width, window_height);
+	Rml::Core::SetRenderInterface(&opengl_renderer);
+	opengl_renderer.SetViewport(window_width, window_height);
 
 
-	Rml::Core::SetSystemInterface(std::make_shared<ShellSystemInterface>());
+	ShellSystemInterface system_interface;
+	Rml::Core::SetSystemInterface(&system_interface);
 
 
 	Rml::Core::Initialise();
 	Rml::Core::Initialise();
 	// Initialise the RmlUi Controls library.
 	// Initialise the RmlUi Controls library.
@@ -120,10 +121,13 @@ int main(int RMLUI_UNUSED_PARAMETER(argc), char** RMLUI_UNUSED_PARAMETER(argv))
 	Shell::LoadFonts("assets/");
 	Shell::LoadFonts("assets/");
 
 
 	// Register Invader's custom element and decorator instancers.
 	// Register Invader's custom element and decorator instancers.
-	Rml::Core::Factory::RegisterElementInstancer("game", Rml::Core::ElementInstancerPtr(new Rml::Core::ElementInstancerGeneric< ElementGame >));
+	Rml::Core::ElementInstancerGeneric< ElementGame > element_instancer_game;
+	Rml::Core::Factory::RegisterElementInstancer("game", &element_instancer_game);
 
 
-	Rml::Core::Factory::RegisterDecoratorInstancer("starfield", std::make_unique<DecoratorInstancerStarfield>());
-	Rml::Core::Factory::RegisterDecoratorInstancer("defender", std::make_unique<DecoratorInstancerDefender>());
+	DecoratorInstancerStarfield decorator_instancer_starfield;
+	DecoratorInstancerDefender decorator_instancer_defender;
+	Rml::Core::Factory::RegisterDecoratorInstancer("starfield", &decorator_instancer_starfield);
+	Rml::Core::Factory::RegisterDecoratorInstancer("defender", &decorator_instancer_defender);
 
 
 	// Register Invader's data formatters
 	// Register Invader's data formatters
 	HighScoresNameFormatter name_formatter;
 	HighScoresNameFormatter name_formatter;
@@ -133,7 +137,8 @@ int main(int RMLUI_UNUSED_PARAMETER(argc), char** RMLUI_UNUSED_PARAMETER(argv))
 	HighScores::Initialise();
 	HighScores::Initialise();
 
 
 	// Initialise the event instancer and handlers.
 	// Initialise the event instancer and handlers.
-	Rml::Core::Factory::RegisterEventListenerInstancer(Rml::Core::UniquePtr<Rml::Core::EventListenerInstancer>(new EventInstancer));
+	EventInstancer event_listener_instancer;
+	Rml::Core::Factory::RegisterEventListenerInstancer(&event_listener_instancer);
 
 
 	EventManager::RegisterEventHandler("start_game", new EventHandlerStartGame());
 	EventManager::RegisterEventHandler("start_game", new EventHandlerStartGame());
 	EventManager::RegisterEventHandler("high_score", new EventHandlerHighScore());
 	EventManager::RegisterEventHandler("high_score", new EventHandlerHighScore());

+ 3 - 3
Samples/shell/src/macosx/ShellMacOSX.cpp

@@ -57,7 +57,7 @@ static WindowRef window;
 static timeval start_time;
 static timeval start_time;
 static Rml::Core::WString clipboard_text;
 static Rml::Core::WString clipboard_text;
 
 
-static Rml::Core::SharedPtr<ShellFileInterface> file_interface;
+static std::unique_ptr<ShellFileInterface> file_interface;
 
 
 static void IdleTimerCallback(EventLoopTimerRef timer, EventLoopIdleTimerMessage inState, void* p);
 static void IdleTimerCallback(EventLoopTimerRef timer, EventLoopIdleTimerMessage inState, void* p);
 static OSStatus EventHandler(EventHandlerCallRef next_handler, EventRef event, void* p);
 static OSStatus EventHandler(EventHandlerCallRef next_handler, EventRef event, void* p);
@@ -70,8 +70,8 @@ bool Shell::Initialise()
 
 
 	Rml::Core::String root = FindSamplesRoot();
 	Rml::Core::String root = FindSamplesRoot();
 
 
-	file_interface = std::make_shared<ShellFileInterface>(root);
-	Rml::Core::SetFileInterface(file_interface);
+	file_interface = std::make_unique<ShellFileInterface>(root);
+	Rml::Core::SetFileInterface(file_interface.get());
 
 
 	return true;
 	return true;
 }
 }

+ 3 - 3
Samples/shell/src/win32/ShellWin32.cpp

@@ -45,7 +45,7 @@ static HINSTANCE instance_handle = NULL;
 static double time_frequency;
 static double time_frequency;
 static LARGE_INTEGER time_startup;
 static LARGE_INTEGER time_startup;
 
 
-static Rml::Core::SharedPtr<ShellFileInterface> file_interface;
+static std::unique_ptr<ShellFileInterface> file_interface;
 
 
 static HCURSOR cursor_default = NULL;
 static HCURSOR cursor_default = NULL;
 static HCURSOR cursor_move = NULL;
 static HCURSOR cursor_move = NULL;
@@ -72,8 +72,8 @@ bool Shell::Initialise()
 
 
 	Rml::Core::String root = FindSamplesRoot();
 	Rml::Core::String root = FindSamplesRoot();
 	
 	
-	file_interface = std::make_shared<ShellFileInterface>(root);
-	Rml::Core::SetFileInterface(file_interface);
+	file_interface = std::make_unique<ShellFileInterface>(root);
+	Rml::Core::SetFileInterface(file_interface.get());
 
 
 	return true;
 	return true;
 }
 }

+ 3 - 3
Samples/shell/src/x11/ShellX11.cpp

@@ -48,7 +48,7 @@ static int screen = -1;
 static timeval start_time;
 static timeval start_time;
 static Rml::Core::WString clipboard_text;
 static Rml::Core::WString clipboard_text;
 
 
-static Rml::Core::SharedPtr<ShellFileInterface> file_interface;
+static std::unique_ptr<ShellFileInterface> file_interface;
 
 
 static bool isDirectory(const Rml::Core::String &path)
 static bool isDirectory(const Rml::Core::String &path)
 {
 {
@@ -63,8 +63,8 @@ bool Shell::Initialise()
 
 
 	Rml::Core::String root = FindSamplesRoot();
 	Rml::Core::String root = FindSamplesRoot();
 
 
-	file_interface = std::make_shared<ShellFileInterface>(root);
-	Rml::Core::SetFileInterface(file_interface);
+	file_interface = std::make_unique<ShellFileInterface>(root);
+	Rml::Core::SetFileInterface(file_interface.get());
 
 
 	return true;
 	return true;
 }
 }

+ 0 - 12
Samples/tutorial/datagrid/src/DecoratorInstancerDefender.cpp

@@ -38,15 +38,3 @@ std::shared_ptr<Rml::Core::Decorator> DecoratorInstancerDefender::InstanceDecora
 
 
 	return nullptr;
 	return nullptr;
 }
 }
-
-// Releases the given decorator.
-void DecoratorInstancerDefender::ReleaseDecorator(Rml::Core::Decorator* decorator)
-{
-	delete decorator;
-}
-
-// Releases the instancer.
-void DecoratorInstancerDefender::Release()
-{
-	delete this;
-}

+ 0 - 7
Samples/tutorial/datagrid/src/DecoratorInstancerDefender.h

@@ -32,13 +32,6 @@ public:
 	/// @return A shared_ptr to the decorator if it was instanced successfully.
 	/// @return A shared_ptr to the decorator if it was instanced successfully.
 	std::shared_ptr<Rml::Core::Decorator> InstanceDecorator(const Rml::Core::String& name, const Rml::Core::PropertyDictionary& properties, const Rml::Core::DecoratorInstancerInterface& interface) override;
 	std::shared_ptr<Rml::Core::Decorator> InstanceDecorator(const Rml::Core::String& name, const Rml::Core::PropertyDictionary& properties, const Rml::Core::DecoratorInstancerInterface& interface) override;
 
 
-	/// Releases the given decorator.
-	/// @param decorator Decorator to release. This is guaranteed to have been constructed by this instancer.
-	void ReleaseDecorator(Rml::Core::Decorator* decorator);
-
-	/// Releases the instancer.
-	void Release();
-
 private:
 private:
 	Rml::Core::PropertyId id_image_src;
 	Rml::Core::PropertyId id_image_src;
 };
 };

+ 8 - 6
Samples/tutorial/datagrid/src/main.cpp

@@ -52,8 +52,8 @@ int main(int RMLUI_UNUSED_PARAMETER(argc), char** RMLUI_UNUSED_PARAMETER(argv))
         AllocConsole();
         AllocConsole();
 #endif
 #endif
 
 
-	auto opengl_renderer = std::make_shared<ShellRenderInterfaceOpenGL>();
-	shell_renderer = opengl_renderer.get();
+	ShellRenderInterfaceOpenGL opengl_renderer;
+	shell_renderer = &opengl_renderer;
 
 
 	// Generic OS initialisation, creates a window and attaches OpenGL.
 	// Generic OS initialisation, creates a window and attaches OpenGL.
 	if (!Shell::Initialise() ||
 	if (!Shell::Initialise() ||
@@ -64,10 +64,11 @@ int main(int RMLUI_UNUSED_PARAMETER(argc), char** RMLUI_UNUSED_PARAMETER(argv))
 	}
 	}
 
 
 	// RmlUi initialisation.
 	// RmlUi initialisation.
-	Rml::Core::SetRenderInterface(opengl_renderer);
-	opengl_renderer->SetViewport(1024,768);
+	Rml::Core::SetRenderInterface(&opengl_renderer);
+	opengl_renderer.SetViewport(1024,768);
 
 
-	Rml::Core::SetSystemInterface(std::make_shared<ShellSystemInterface>());
+	ShellSystemInterface system_interface;
+	Rml::Core::SetSystemInterface(&system_interface);
 
 
 	Rml::Core::Initialise();
 	Rml::Core::Initialise();
 	Rml::Controls::Initialise();
 	Rml::Controls::Initialise();
@@ -88,7 +89,8 @@ int main(int RMLUI_UNUSED_PARAMETER(argc), char** RMLUI_UNUSED_PARAMETER(argv))
 	Shell::LoadFonts("assets/");
 	Shell::LoadFonts("assets/");
 
 
 	// Load the defender decorator.
 	// Load the defender decorator.
-	Rml::Core::Factory::RegisterDecoratorInstancer("defender", std::make_unique<DecoratorInstancerDefender>());
+	DecoratorInstancerDefender decorator_instancer_defender;
+	Rml::Core::Factory::RegisterDecoratorInstancer("defender", &decorator_instancer_defender);
 
 
 	// Construct the high scores.
 	// Construct the high scores.
 	HighScores::Initialise();
 	HighScores::Initialise();

+ 1 - 13
Samples/tutorial/datagrid_tree/src/DecoratorInstancerDefender.cpp

@@ -37,16 +37,4 @@ std::shared_ptr<Rml::Core::Decorator> DecoratorInstancerDefender::InstanceDecora
 		return decorator;
 		return decorator;
 
 
 	return nullptr;
 	return nullptr;
-}
-
-// Releases the given decorator.
-void DecoratorInstancerDefender::ReleaseDecorator(Rml::Core::Decorator* decorator)
-{
-	delete decorator;
-}
-
-// Releases the instancer.
-void DecoratorInstancerDefender::Release()
-{
-	delete this;
-}
+}

+ 0 - 7
Samples/tutorial/datagrid_tree/src/DecoratorInstancerDefender.h

@@ -32,13 +32,6 @@ public:
 	/// @return A shared_ptr to the decorator if it was instanced successfully.
 	/// @return A shared_ptr to the decorator if it was instanced successfully.
 	std::shared_ptr<Rml::Core::Decorator> InstanceDecorator(const Rml::Core::String& name, const Rml::Core::PropertyDictionary& properties, const Rml::Core::DecoratorInstancerInterface& interface) override;
 	std::shared_ptr<Rml::Core::Decorator> InstanceDecorator(const Rml::Core::String& name, const Rml::Core::PropertyDictionary& properties, const Rml::Core::DecoratorInstancerInterface& interface) override;
 
 
-	/// Releases the given decorator.
-	/// @param decorator Decorator to release. This is guaranteed to have been constructed by this instancer.
-	void ReleaseDecorator(Rml::Core::Decorator* decorator);
-
-	/// Releases the instancer.
-	void Release();
-
 private:
 private:
 	Rml::Core::PropertyId id_image_src;
 	Rml::Core::PropertyId id_image_src;
 };
 };

+ 8 - 6
Samples/tutorial/datagrid_tree/src/main.cpp

@@ -56,8 +56,8 @@ int main(int RMLUI_UNUSED_PARAMETER(argc), char** RMLUI_UNUSED_PARAMETER(argv))
 	int window_width = 1024;
 	int window_width = 1024;
 	int window_height = 768;
 	int window_height = 768;
 
 
-	auto opengl_renderer = std::make_shared<ShellRenderInterfaceOpenGL>();
-	shell_renderer = opengl_renderer.get();
+	ShellRenderInterfaceOpenGL opengl_renderer;
+	shell_renderer = &opengl_renderer;
 
 
 	// Generic OS initialisation, creates a window and attaches OpenGL.
 	// Generic OS initialisation, creates a window and attaches OpenGL.
 	if (!Shell::Initialise() ||
 	if (!Shell::Initialise() ||
@@ -68,10 +68,11 @@ int main(int RMLUI_UNUSED_PARAMETER(argc), char** RMLUI_UNUSED_PARAMETER(argv))
 	}
 	}
 
 
 	// RmlUi initialisation.
 	// RmlUi initialisation.
-	Rml::Core::SetRenderInterface(opengl_renderer);
-	opengl_renderer->SetViewport(window_width, window_height);
+	Rml::Core::SetRenderInterface(&opengl_renderer);
+	opengl_renderer.SetViewport(window_width, window_height);
 
 
-	Rml::Core::SetSystemInterface(std::make_shared<ShellSystemInterface>());
+	ShellSystemInterface system_interface;
+	Rml::Core::SetSystemInterface(&system_interface);
 
 
 	Rml::Core::Initialise();
 	Rml::Core::Initialise();
 	Rml::Controls::Initialise();
 	Rml::Controls::Initialise();
@@ -92,7 +93,8 @@ int main(int RMLUI_UNUSED_PARAMETER(argc), char** RMLUI_UNUSED_PARAMETER(argv))
 	Shell::LoadFonts("assets/");
 	Shell::LoadFonts("assets/");
 
 
 	// Load the defender decorator.
 	// Load the defender decorator.
-	Rml::Core::Factory::RegisterDecoratorInstancer("defender", std::make_unique<DecoratorInstancerDefender>());
+	DecoratorInstancerDefender decorator_instancer_defender;
+	Rml::Core::Factory::RegisterDecoratorInstancer("defender", &decorator_instancer_defender);
 
 
 	// Add the ship formatter.
 	// Add the ship formatter.
 	HighScoresShipFormatter ship_formatter;
 	HighScoresShipFormatter ship_formatter;

+ 6 - 5
Samples/tutorial/drag/src/main.cpp

@@ -53,8 +53,8 @@ int main(int RMLUI_UNUSED_PARAMETER(argc), char** RMLUI_UNUSED_PARAMETER(argv))
 	int window_width = 1024;
 	int window_width = 1024;
 	int window_height = 768;
 	int window_height = 768;
 
 
-	auto opengl_renderer = std::make_shared<ShellRenderInterfaceOpenGL>();
-	shell_renderer = opengl_renderer.get();
+	ShellRenderInterfaceOpenGL opengl_renderer;
+	shell_renderer = &opengl_renderer;
 
 
 	// Generic OS initialisation, creates a window and attaches OpenGL.
 	// Generic OS initialisation, creates a window and attaches OpenGL.
 	if (!Shell::Initialise() ||
 	if (!Shell::Initialise() ||
@@ -65,10 +65,11 @@ int main(int RMLUI_UNUSED_PARAMETER(argc), char** RMLUI_UNUSED_PARAMETER(argv))
 	}
 	}
 
 
 	// RmlUi initialisation.
 	// RmlUi initialisation.
-	Rml::Core::SetRenderInterface(opengl_renderer);
-	opengl_renderer->SetViewport(window_width, window_height);
+	Rml::Core::SetRenderInterface(&opengl_renderer);
+	opengl_renderer.SetViewport(window_width, window_height);
 
 
-	Rml::Core::SetSystemInterface(std::make_shared<ShellSystemInterface>());
+	ShellSystemInterface system_interface;
+	Rml::Core::SetSystemInterface(&system_interface);
 
 
 	Rml::Core::Initialise();
 	Rml::Core::Initialise();
 
 

+ 6 - 5
Samples/tutorial/template/src/main.cpp

@@ -52,8 +52,8 @@ int main(int RMLUI_UNUSED_PARAMETER(argc), char** RMLUI_UNUSED_PARAMETER(argv))
 	int window_width = 1024;
 	int window_width = 1024;
 	int window_height = 768;
 	int window_height = 768;
 
 
-	auto opengl_renderer = std::make_shared<ShellRenderInterfaceOpenGL>();
-	shell_renderer = opengl_renderer.get();
+	ShellRenderInterfaceOpenGL opengl_renderer;
+	shell_renderer = &opengl_renderer;
 
 
 	// Generic OS initialisation, creates a window and attaches OpenGL.
 	// Generic OS initialisation, creates a window and attaches OpenGL.
 	if (!Shell::Initialise() ||
 	if (!Shell::Initialise() ||
@@ -64,10 +64,11 @@ int main(int RMLUI_UNUSED_PARAMETER(argc), char** RMLUI_UNUSED_PARAMETER(argv))
 	}
 	}
 
 
 	// RmlUi initialisation.
 	// RmlUi initialisation.
-	Rml::Core::SetRenderInterface(opengl_renderer);
-	opengl_renderer->SetViewport(window_width, window_height);
+	Rml::Core::SetRenderInterface(&opengl_renderer);
+	opengl_renderer.SetViewport(window_width, window_height);
 
 
-	Rml::Core::SetSystemInterface(std::make_shared<ShellSystemInterface>());
+	ShellSystemInterface system_interface;
+	Rml::Core::SetSystemInterface(&system_interface);
 
 
 	Rml::Core::Initialise();
 	Rml::Core::Initialise();
 
 

+ 38 - 13
Source/Controls/Controls.cpp

@@ -42,22 +42,46 @@
 namespace Rml {
 namespace Rml {
 namespace Controls {
 namespace Controls {
 
 
+struct ElementInstancers {
+	using Ptr = std::unique_ptr<Core::ElementInstancer>;
+	template<typename T> using ElementInstancerGeneric = Core::ElementInstancerGeneric<T>;
+
+	Ptr form = std::make_unique<ElementInstancerGeneric<ElementForm>>();
+	Ptr input = std::make_unique<ElementInstancerGeneric<ElementFormControlInput>>();
+	Ptr dataselect = std::make_unique<ElementInstancerGeneric<ElementFormControlDataSelect>>();
+	Ptr select = std::make_unique<ElementInstancerGeneric<ElementFormControlSelect>>();
+	
+	Ptr textarea = std::make_unique<ElementInstancerGeneric<ElementFormControlTextArea>>();
+	Ptr selection = std::make_unique<ElementInstancerGeneric<ElementTextSelection>>();
+	Ptr tabset  = std::make_unique<ElementInstancerGeneric<ElementTabSet>>();
+	
+	Ptr datagrid = std::make_unique<ElementInstancerGeneric<ElementDataGrid>>();
+	Ptr datagrid_expand = std::make_unique<ElementInstancerGeneric<ElementDataGridExpandButton>>();
+	Ptr datagrid_cell = std::make_unique<ElementInstancerGeneric<ElementDataGridCell>>();
+	Ptr datagrid_row = std::make_unique<ElementInstancerGeneric<ElementDataGridRow>>();
+};
+
+static std::unique_ptr<ElementInstancers> element_instancers;
+
+
 // Registers the custom element instancers.
 // Registers the custom element instancers.
 void RegisterElementInstancers()
 void RegisterElementInstancers()
 {
 {
-	Core::Factory::RegisterElementInstancer("form", Core::ElementInstancerPtr(new Core::ElementInstancerGeneric< ElementForm >));
-	Core::Factory::RegisterElementInstancer("input", Core::ElementInstancerPtr(new Core::ElementInstancerGeneric< ElementFormControlInput >));
-	Core::Factory::RegisterElementInstancer("dataselect", Core::ElementInstancerPtr(new Core::ElementInstancerGeneric< ElementFormControlDataSelect >));
-	Core::Factory::RegisterElementInstancer("select", Core::ElementInstancerPtr(new Core::ElementInstancerGeneric< ElementFormControlSelect >));
-
-	Core::Factory::RegisterElementInstancer("textarea", Core::ElementInstancerPtr(new Core::ElementInstancerGeneric< ElementFormControlTextArea >));
-	Core::Factory::RegisterElementInstancer("#selection", Core::ElementInstancerPtr(new Core::ElementInstancerGeneric< ElementTextSelection >));
-	Core::Factory::RegisterElementInstancer("tabset", Core::ElementInstancerPtr(new Core::ElementInstancerGeneric< ElementTabSet >));
-
-	Core::Factory::RegisterElementInstancer("datagrid", Core::ElementInstancerPtr(new Core::ElementInstancerGeneric< ElementDataGrid >));
-	Core::Factory::RegisterElementInstancer("datagridexpand", Core::ElementInstancerPtr(new Core::ElementInstancerGeneric< ElementDataGridExpandButton >));
-	Core::Factory::RegisterElementInstancer("#rmlctl_datagridcell", Core::ElementInstancerPtr(new Core::ElementInstancerGeneric< ElementDataGridCell >));
-	Core::Factory::RegisterElementInstancer("#rmlctl_datagridrow", Core::ElementInstancerPtr(new Core::ElementInstancerGeneric< ElementDataGridRow >));
+	element_instancers = std::make_unique<ElementInstancers>();
+
+	Core::Factory::RegisterElementInstancer("form", element_instancers->form.get());
+	Core::Factory::RegisterElementInstancer("input", element_instancers->input.get());
+	Core::Factory::RegisterElementInstancer("dataselect", element_instancers->dataselect.get());
+	Core::Factory::RegisterElementInstancer("select", element_instancers->select.get());
+
+	Core::Factory::RegisterElementInstancer("textarea", element_instancers->textarea.get());
+	Core::Factory::RegisterElementInstancer("#selection", element_instancers->selection.get());
+	Core::Factory::RegisterElementInstancer("tabset", element_instancers->tabset.get());
+
+	Core::Factory::RegisterElementInstancer("datagrid", element_instancers->datagrid.get());
+	Core::Factory::RegisterElementInstancer("datagridexpand", element_instancers->datagrid_expand.get());
+	Core::Factory::RegisterElementInstancer("#rmlctl_datagridcell", element_instancers->datagrid_cell.get());
+	Core::Factory::RegisterElementInstancer("#rmlctl_datagridrow", element_instancers->datagrid_row.get());
 }
 }
 
 
 void RegisterXMLNodeHandlers()
 void RegisterXMLNodeHandlers()
@@ -74,6 +98,7 @@ class ControlsPlugin : public Rml::Core::Plugin
 public:
 public:
 	void OnShutdown()
 	void OnShutdown()
 	{
 	{
+		element_instancers.reset();
 		initialised = false;
 		initialised = false;
 		delete this;
 		delete this;
 	}
 	}

+ 5 - 5
Source/Core/Context.cpp

@@ -92,9 +92,9 @@ Context::~Context()
 
 
 	root.reset();
 	root.reset();
 
 
-	instancer.reset();
+	instancer = nullptr;
 
 
-	render_interface.reset();
+	render_interface = nullptr;
 }
 }
 
 
 // Returns the name of the context.
 // Returns the name of the context.
@@ -764,7 +764,7 @@ void Context::ProcessViewChange(const Matrix4f &view)
 // Gets the context's render interface.
 // Gets the context's render interface.
 RenderInterface* Context::GetRenderInterface() const
 RenderInterface* Context::GetRenderInterface() const
 {
 {
-	return render_interface.get();
+	return render_interface;
 }
 }
 	
 	
 // Gets the current clipping region for the render traversal
 // Gets the current clipping region for the render traversal
@@ -787,10 +787,10 @@ void Context::SetActiveClipRegion(const Vector2i& origin, const Vector2i& dimens
 }
 }
 
 
 // Sets the instancer to use for releasing this object.
 // Sets the instancer to use for releasing this object.
-void Context::SetInstancer(SharedPtr<ContextInstancer> _instancer)
+void Context::SetInstancer(ContextInstancer* _instancer)
 {
 {
 	RMLUI_ASSERT(instancer == nullptr);
 	RMLUI_ASSERT(instancer == nullptr);
-	instancer = std::move(_instancer);
+	instancer = _instancer;
 }
 }
 
 
 // Internal callback for when an element is removed from the hierarchy.
 // Internal callback for when an element is removed from the hierarchy.

+ 23 - 22
Source/Core/Core.cpp

@@ -41,11 +41,14 @@ namespace Rml {
 namespace Core {
 namespace Core {
 
 
 // RmlUi's renderer interface.
 // RmlUi's renderer interface.
-static SharedPtr<RenderInterface> render_interface = nullptr;
+static RenderInterface* render_interface = nullptr;
 /// RmlUi's system interface.
 /// RmlUi's system interface.
-static SharedPtr<SystemInterface> system_interface = nullptr;
+static SystemInterface* system_interface = nullptr;
 // RmlUi's file I/O interface.
 // RmlUi's file I/O interface.
-static SharedPtr<FileInterface> file_interface = nullptr;
+static FileInterface* file_interface = nullptr;
+
+// Default interfaces should be created and destroyed on Initialise and Shutdown, respectively.
+static std::unique_ptr<FileInterface> default_file_interface;
 
 
 static bool initialised = false;
 static bool initialised = false;
 
 
@@ -69,7 +72,8 @@ bool Initialise()
 	if (!file_interface)
 	if (!file_interface)
 	{		
 	{		
 #ifndef RMLUI_NO_FILE_INTERFACE_DEFAULT
 #ifndef RMLUI_NO_FILE_INTERFACE_DEFAULT
-		file_interface = std::make_shared<FileInterfaceDefault>();
+		default_file_interface = std::make_unique<FileInterfaceDefault>();
+		file_interface = default_file_interface.get();
 #else
 #else
 		Log::Message(Log::LT_ERROR, "No file interface set!");
 		Log::Message(Log::LT_ERROR, "No file interface set!");
 		return false;
 		return false;
@@ -118,9 +122,11 @@ void Shutdown()
 
 
 	initialised = false;
 	initialised = false;
 
 
-	render_interface.reset();
-	file_interface.reset();
-	system_interface.reset();
+	render_interface = nullptr;
+	file_interface = nullptr;
+	system_interface = nullptr;
+
+	default_file_interface.reset();
 }
 }
 
 
 // Returns the version of this RmlUi library.
 // Returns the version of this RmlUi library.
@@ -130,48 +136,43 @@ String GetVersion()
 }
 }
 
 
 // Sets the interface through which all RmlUi messages will be routed.
 // Sets the interface through which all RmlUi messages will be routed.
-void SetSystemInterface(SharedPtr<SystemInterface> _system_interface)
+void SetSystemInterface(SystemInterface* _system_interface)
 {
 {
-	system_interface = std::move(_system_interface);
+	system_interface = _system_interface;
 }
 }
 
 
 // Returns RmlUi's system interface.
 // Returns RmlUi's system interface.
 SystemInterface* GetSystemInterface()
 SystemInterface* GetSystemInterface()
-{
-	return system_interface.get();
-}
-
-SharedPtr<SystemInterface> GetSystemInterfaceSharedPtr()
 {
 {
 	return system_interface;
 	return system_interface;
 }
 }
 
 
 // Sets the interface through which all rendering requests are made.
 // Sets the interface through which all rendering requests are made.
-void SetRenderInterface(SharedPtr<RenderInterface> _render_interface)
+void SetRenderInterface(RenderInterface* _render_interface)
 {
 {
-	render_interface = std::move(_render_interface);
+	render_interface = _render_interface;
 }
 }
 
 
 // Returns RmlUi's render interface.
 // Returns RmlUi's render interface.
 RenderInterface* GetRenderInterface()
 RenderInterface* GetRenderInterface()
 {
 {
-	return render_interface.get();
+	return render_interface;
 }
 }
 
 
 // Sets the interface through which all file I/O requests are made.
 // Sets the interface through which all file I/O requests are made.
-void SetFileInterface(SharedPtr<FileInterface> _file_interface)
+void SetFileInterface(FileInterface* _file_interface)
 {
 {
-	file_interface = std::move(_file_interface);
+	file_interface = _file_interface;
 }
 }
 
 
 // Returns RmlUi's file interface.
 // Returns RmlUi's file interface.
 FileInterface* GetFileInterface()
 FileInterface* GetFileInterface()
 {
 {
-	return file_interface.get();
+	return file_interface;
 }
 }
 
 
 // Creates a new element context.
 // Creates a new element context.
-Context* CreateContext(const String& name, const Vector2i& dimensions, SharedPtr<RenderInterface> custom_render_interface)
+Context* CreateContext(const String& name, const Vector2i& dimensions, RenderInterface* custom_render_interface)
 {
 {
 	if (!initialised)
 	if (!initialised)
 		return nullptr;
 		return nullptr;
@@ -197,7 +198,7 @@ Context* CreateContext(const String& name, const Vector2i& dimensions, SharedPtr
 
 
 	// Set the render interface on the context, and add a reference onto it.
 	// Set the render interface on the context, and add a reference onto it.
 	if (custom_render_interface)
 	if (custom_render_interface)
-		new_context->render_interface = std::move(custom_render_interface);
+		new_context->render_interface = custom_render_interface;
 	else
 	else
 		new_context->render_interface = render_interface;
 		new_context->render_interface = render_interface;
 
 

+ 1 - 2
Source/Core/Element.cpp

@@ -1671,8 +1671,7 @@ bool Element::IsClippingEnabled()
 // Gets the render interface owned by this element's context.
 // Gets the render interface owned by this element's context.
 RenderInterface* Element::GetRenderInterface()
 RenderInterface* Element::GetRenderInterface()
 {
 {
-	Context* context = GetContext();
-	if (context)
+	if (Context* context = GetContext())
 		return context->GetRenderInterface();
 		return context->GetRenderInterface();
 
 
 	return Rml::Core::GetRenderInterface();
 	return Rml::Core::GetRenderInterface();

+ 77 - 54
Source/Core/Factory.cpp

@@ -55,25 +55,51 @@ namespace Rml {
 namespace Core {
 namespace Core {
 
 
 // Element instancers.
 // Element instancers.
-typedef UnorderedMap< String, ElementInstancerPtr > ElementInstancerMap;
+typedef UnorderedMap< String, ElementInstancer* > ElementInstancerMap;
 static ElementInstancerMap element_instancers;
 static ElementInstancerMap element_instancers;
 
 
 // Decorator instancers.
 // Decorator instancers.
-typedef UnorderedMap< String, std::unique_ptr<DecoratorInstancer> > DecoratorInstancerMap;
+typedef UnorderedMap< String, DecoratorInstancer* > DecoratorInstancerMap;
 static DecoratorInstancerMap decorator_instancers;
 static DecoratorInstancerMap decorator_instancers;
 
 
 // Font effect instancers.
 // Font effect instancers.
-typedef UnorderedMap< String, std::unique_ptr<FontEffectInstancer> > FontEffectInstancerMap;
+typedef UnorderedMap< String, FontEffectInstancer* > FontEffectInstancerMap;
 static FontEffectInstancerMap font_effect_instancers;
 static FontEffectInstancerMap font_effect_instancers;
 
 
 // The context instancer.
 // The context instancer.
-static SharedPtr<ContextInstancer> context_instancer;
+static ContextInstancer* context_instancer = nullptr;;
 
 
 // The event instancer
 // The event instancer
-static UniquePtr<EventInstancer> event_instancer;
+static EventInstancer* event_instancer = nullptr;;
 
 
 // Event listener instancer.
 // Event listener instancer.
-static UniquePtr<EventListenerInstancer> event_listener_instancer;
+static EventListenerInstancer* event_listener_instancer = nullptr;
+
+
+// Default instancers are constructed and destroyed on Initialise and Shutdown, respectively.
+struct DefaultInstancers {
+	template<typename T> using Ptr = std::unique_ptr<T>;
+
+	Ptr<ContextInstancer> context_default;
+	Ptr<EventInstancer> event_default;
+
+	Ptr<ElementInstancer> element_default = std::make_unique<ElementInstancerGeneric<Element>>();
+	Ptr<ElementInstancer> element_img = std::make_unique<ElementInstancerGeneric<ElementImage>>();
+	Ptr<ElementInstancer> element_text_default = std::make_unique<ElementInstancerGeneric<ElementTextDefault>>();
+	Ptr<ElementInstancer> element_handle = std::make_unique<ElementInstancerGeneric<ElementHandle>>();
+	Ptr<ElementInstancer> element_body = std::make_unique<ElementInstancerGeneric<ElementDocument>>();
+
+	Ptr<DecoratorInstancer> decorator_tiled_horizontal = std::make_unique<DecoratorTiledHorizontalInstancer>();
+	Ptr<DecoratorInstancer> decorator_tiled_vertical = std::make_unique<DecoratorTiledVerticalInstancer>();
+	Ptr<DecoratorInstancer> decorator_tiled_box = std::make_unique<DecoratorTiledBoxInstancer>();
+	Ptr<DecoratorInstancer> decorator_image = std::make_unique<DecoratorTiledImageInstancer>();
+
+	Ptr<FontEffectInstancer> font_effect_shadow = std::make_unique<FontEffectShadowInstancer>();
+	Ptr<FontEffectInstancer> font_effect_outline = std::make_unique<FontEffectOutlineInstancer>();
+};
+
+static std::unique_ptr<DefaultInstancers> default_instancers;
+
 
 
 Factory::Factory()
 Factory::Factory()
 {
 {
@@ -83,35 +109,44 @@ Factory::~Factory()
 {
 {
 }
 }
 
 
+
 bool Factory::Initialise()
 bool Factory::Initialise()
 {
 {
+	default_instancers = std::make_unique<DefaultInstancers>();
+
 	// Bind the default context instancer.
 	// Bind the default context instancer.
 	if (!context_instancer)
 	if (!context_instancer)
-		context_instancer = std::make_shared<ContextInstancerDefault>();
+	{
+		default_instancers->context_default = std::make_unique<ContextInstancerDefault>();
+		context_instancer = default_instancers->context_default.get();
+	}
 
 
 	// Bind default event instancer
 	// Bind default event instancer
 	if (!event_instancer)
 	if (!event_instancer)
-		event_instancer = UniquePtr<EventInstancer>(new EventInstancerDefault);
+	{
+		default_instancers->event_default = std::make_unique<EventInstancerDefault>();
+		event_instancer = default_instancers->event_default.get();
+	}
 
 
 	// No default event listener instancer
 	// No default event listener instancer
 	if (!event_listener_instancer)
 	if (!event_listener_instancer)
 		event_listener_instancer = nullptr;
 		event_listener_instancer = nullptr;
 
 
 	// Bind the default element instancers
 	// Bind the default element instancers
-	RegisterElementInstancer("*", ElementInstancerPtr(new ElementInstancerGeneric< Element >));
-	RegisterElementInstancer("img", ElementInstancerPtr(new ElementInstancerGeneric< ElementImage >));
-	RegisterElementInstancer("#text", ElementInstancerPtr(new ElementInstancerGeneric< ElementTextDefault >));
-	RegisterElementInstancer("handle", ElementInstancerPtr(new ElementInstancerGeneric< ElementHandle >));
-	RegisterElementInstancer("body", ElementInstancerPtr(new ElementInstancerGeneric< ElementDocument >));
+	RegisterElementInstancer("*", default_instancers->element_default.get());
+	RegisterElementInstancer("img", default_instancers->element_img.get());
+	RegisterElementInstancer("#text", default_instancers->element_text_default.get());
+	RegisterElementInstancer("handle", default_instancers->element_handle.get());
+	RegisterElementInstancer("body", default_instancers->element_body.get());
 
 
 	// Bind the default decorator instancers
 	// Bind the default decorator instancers
-	RegisterDecoratorInstancer("tiled-horizontal", std::make_unique<DecoratorTiledHorizontalInstancer>());
-	RegisterDecoratorInstancer("tiled-vertical", std::make_unique<DecoratorTiledVerticalInstancer>());
-	RegisterDecoratorInstancer("tiled-box", std::make_unique<DecoratorTiledBoxInstancer>());
-	RegisterDecoratorInstancer("image", std::make_unique<DecoratorTiledImageInstancer>());
+	RegisterDecoratorInstancer("tiled-horizontal", default_instancers->decorator_tiled_horizontal.get());
+	RegisterDecoratorInstancer("tiled-vertical", default_instancers->decorator_tiled_vertical.get());
+	RegisterDecoratorInstancer("tiled-box", default_instancers->decorator_tiled_box.get());
+	RegisterDecoratorInstancer("image", default_instancers->decorator_image.get());
 
 
-	RegisterFontEffectInstancer("shadow", std::make_unique<FontEffectShadowInstancer>());
-	RegisterFontEffectInstancer("outline", std::make_unique<FontEffectOutlineInstancer>());
+	RegisterFontEffectInstancer("shadow", default_instancers->font_effect_shadow.get());
+	RegisterFontEffectInstancer("outline", default_instancers->font_effect_outline.get());
 
 
 	// Register the core XML node handlers.
 	// Register the core XML node handlers.
 	XMLParser::RegisterNodeHandler("", std::make_shared<XMLNodeHandlerDefault>());
 	XMLParser::RegisterNodeHandler("", std::make_shared<XMLNodeHandlerDefault>());
@@ -130,21 +165,21 @@ void Factory::Shutdown()
 
 
 	font_effect_instancers.clear();
 	font_effect_instancers.clear();
 
 
-	context_instancer.reset();
+	context_instancer = nullptr;
 
 
-	event_listener_instancer.reset();
+	event_listener_instancer = nullptr;
 
 
-	event_instancer.reset();
+	event_instancer = nullptr;
 
 
 	XMLParser::ReleaseHandlers();
 	XMLParser::ReleaseHandlers();
+
+	default_instancers.reset();
 }
 }
 
 
 // Registers the instancer to use when instancing contexts.
 // Registers the instancer to use when instancing contexts.
-ContextInstancer* Factory::RegisterContextInstancer(SharedPtr<ContextInstancer> instancer)
+void Factory::RegisterContextInstancer(ContextInstancer* instancer)
 {
 {
-	ContextInstancer* result = instancer.get();
-	context_instancer = std::move(instancer);
-	return result;
+	context_instancer = instancer;
 }
 }
 
 
 // Instances a new context.
 // Instances a new context.
@@ -156,12 +191,9 @@ UniquePtr<Context> Factory::InstanceContext(const String& name)
 	return new_context;
 	return new_context;
 }
 }
 
 
-ElementInstancer* Factory::RegisterElementInstancer(const String& name, ElementInstancerPtr instancer)
+void Factory::RegisterElementInstancer(const String& name, ElementInstancer* instancer)
 {
 {
-	ElementInstancer* result = instancer.get();
-	String lower_case_name = ToLower(name);
-	element_instancers[lower_case_name] = std::move(instancer);
-	return result;
+	element_instancers[ToLower(name)] = instancer;
 }
 }
 
 
 // Looks up the instancer for the given element
 // Looks up the instancer for the given element
@@ -175,7 +207,7 @@ ElementInstancer* Factory::GetElementInstancer(const String& tag)
 			return nullptr;
 			return nullptr;
 	}
 	}
 
 
-	return instancer_iterator->second.get();
+	return instancer_iterator->second;
 }
 }
 
 
 // Instances a single element.
 // Instances a single element.
@@ -300,13 +332,10 @@ ElementPtr Factory::InstanceDocumentStream(Rml::Core::Context* context, Stream*
 
 
 
 
 // Registers an instancer that will be used to instance decorators.
 // Registers an instancer that will be used to instance decorators.
-void Factory::RegisterDecoratorInstancer(const String& name, std::unique_ptr<DecoratorInstancer> instancer)
+void Factory::RegisterDecoratorInstancer(const String& name, DecoratorInstancer* instancer)
 {
 {
-	if (!instancer)
-		return;
-
-	String lower_case_name = ToLower(name);
-	decorator_instancers[lower_case_name] = std::move(instancer);
+	RMLUI_ASSERT(instancer);
+	decorator_instancers[ToLower(name)] = instancer;
 }
 }
 
 
 // Retrieves a decorator instancer registered with the factory.
 // Retrieves a decorator instancer registered with the factory.
@@ -316,17 +345,14 @@ DecoratorInstancer* Factory::GetDecoratorInstancer(const String& name)
 	if (iterator == decorator_instancers.end())
 	if (iterator == decorator_instancers.end())
 		return nullptr;
 		return nullptr;
 	
 	
-	return iterator->second.get();
+	return iterator->second;
 }
 }
 
 
 // Registers an instancer that will be used to instance font effects.
 // Registers an instancer that will be used to instance font effects.
-void Factory::RegisterFontEffectInstancer(const String& name, std::unique_ptr<FontEffectInstancer> instancer)
+void Factory::RegisterFontEffectInstancer(const String& name, FontEffectInstancer* instancer)
 {
 {
-	if (!instancer)
-		return;
-
-	String lower_case_name = ToLower(name);
-	font_effect_instancers[lower_case_name] = std::move(instancer);
+	RMLUI_ASSERT(instancer);
+	font_effect_instancers[ToLower(name)] = instancer;
 }
 }
 
 
 FontEffectInstancer* Factory::GetFontEffectInstancer(const String& name)
 FontEffectInstancer* Factory::GetFontEffectInstancer(const String& name)
@@ -335,7 +361,7 @@ FontEffectInstancer* Factory::GetFontEffectInstancer(const String& name)
 	if (iterator == font_effect_instancers.end())
 	if (iterator == font_effect_instancers.end())
 		return nullptr;
 		return nullptr;
 
 
-	return iterator->second.get();
+	return iterator->second;
 }
 }
 
 
 
 
@@ -378,10 +404,9 @@ void Factory::ClearTemplateCache()
 }
 }
 
 
 // Registers an instancer for all RmlEvents
 // Registers an instancer for all RmlEvents
-EventInstancer* Factory::RegisterEventInstancer(UniquePtr<EventInstancer> instancer)
+void Factory::RegisterEventInstancer(EventInstancer* instancer)
 {
 {
-	event_instancer = std::move(instancer);
-	return event_instancer.get();
+	event_instancer = instancer;
 }
 }
 
 
 // Instance an event object.
 // Instance an event object.
@@ -389,16 +414,14 @@ UniquePtr<Event> Factory::InstanceEvent(Element* target, EventId id, const Strin
 {
 {
 	UniquePtr<Event> event = event_instancer->InstanceEvent(target, id, type, parameters, interruptible);
 	UniquePtr<Event> event = event_instancer->InstanceEvent(target, id, type, parameters, interruptible);
 	if (event)
 	if (event)
-		event->instancer = event_instancer.get();
-
+		event->instancer = event_instancer;
 	return event;
 	return event;
 }
 }
 
 
 // Register an instancer for all event listeners
 // Register an instancer for all event listeners
-EventListenerInstancer* Factory::RegisterEventListenerInstancer(UniquePtr<EventListenerInstancer> instancer)
+void Factory::RegisterEventListenerInstancer(EventListenerInstancer* instancer)
 {
 {
-	event_listener_instancer = std::move(instancer);
-	return event_listener_instancer.get();
+	event_listener_instancer = instancer;
 }
 }
 
 
 // Instance an event listener with the given string
 // Instance an event listener with the given string

+ 14 - 7
Source/Debugger/Plugin.cpp

@@ -57,6 +57,8 @@ Plugin::Plugin()
 	hook_element = nullptr;
 	hook_element = nullptr;
 
 
 	render_outlines = false;
 	render_outlines = false;
+
+	application_interface = nullptr;
 }
 }
 
 
 Plugin::~Plugin()
 Plugin::~Plugin()
@@ -84,7 +86,8 @@ bool Plugin::Initialise(Core::Context* context)
 		return false;
 		return false;
 	}
 	}
 
 
-	Core::Factory::RegisterElementInstancer("debug-hook", Core::ElementInstancerPtr(new Core::ElementInstancerGeneric< ElementContextHook >));
+	hook_element_instancer = std::make_unique< Core::ElementInstancerGeneric<ElementContextHook> >();
+	Core::Factory::RegisterElementInstancer("debug-hook", hook_element_instancer.get());
 
 
 	return true;
 	return true;
 }
 }
@@ -211,6 +214,8 @@ void Plugin::OnShutdown()
 	// and that we don't try send the messages to the debug log window
 	// and that we don't try send the messages to the debug log window
 	ReleaseElements();
 	ReleaseElements();
 
 
+	hook_element_instancer.reset();
+
 	delete this;
 	delete this;
 }
 }
 
 
@@ -316,7 +321,8 @@ bool Plugin::LoadMenuElement()
 
 
 bool Plugin::LoadInfoElement()
 bool Plugin::LoadInfoElement()
 {
 {
-	Core::Factory::RegisterElementInstancer("debug-info", Core::ElementInstancerPtr(new Core::ElementInstancerGeneric< ElementInfo >));
+	info_element_instancer = std::make_unique< Core::ElementInstancerGeneric<ElementInfo> >();
+	Core::Factory::RegisterElementInstancer("debug-info", info_element_instancer.get());
 	info_element = dynamic_cast< ElementInfo* >(host_context->CreateDocument("debug-info"));
 	info_element = dynamic_cast< ElementInfo* >(host_context->CreateDocument("debug-info"));
 	if (!info_element)
 	if (!info_element)
 		return false;
 		return false;
@@ -336,7 +342,8 @@ bool Plugin::LoadInfoElement()
 
 
 bool Plugin::LoadLogElement()
 bool Plugin::LoadLogElement()
 {
 {
-	Core::Factory::RegisterElementInstancer("debug-log", Core::ElementInstancerPtr(new Core::ElementInstancerGeneric< ElementLog >));
+	log_element_instancer = std::make_unique< Core::ElementInstancerGeneric<ElementLog> >();
+	Core::Factory::RegisterElementInstancer("debug-log", log_element_instancer.get());
 	log_element = dynamic_cast< ElementLog* >(host_context->CreateDocument("debug-log"));
 	log_element = dynamic_cast< ElementLog* >(host_context->CreateDocument("debug-log"));
 	if (!log_element)
 	if (!log_element)
 		return false;
 		return false;
@@ -352,9 +359,9 @@ bool Plugin::LoadLogElement()
 	}
 	}
 
 
 	// Make the system interface; this will trap the log messages for us.
 	// Make the system interface; this will trap the log messages for us.
-	application_interface = Core::GetSystemInterfaceSharedPtr();
-	log_interface = std::make_shared<SystemInterface>(application_interface.get(), log_element);
-	Core::SetSystemInterface(log_interface);
+	application_interface = Core::GetSystemInterface();
+	log_interface = std::make_unique<SystemInterface>(application_interface, log_element);
+	Core::SetSystemInterface(log_interface.get());
 
 
 	return true;
 	return true;
 }
 }
@@ -380,7 +387,7 @@ void Plugin::ReleaseElements()
 			host_context->UnloadDocument(log_element);
 			host_context->UnloadDocument(log_element);
 			log_element = nullptr;
 			log_element = nullptr;
 			Core::SetSystemInterface(application_interface);
 			Core::SetSystemInterface(application_interface);
-			application_interface.reset();
+			application_interface = nullptr;
 			log_interface.reset();
 			log_interface.reset();
 		}
 		}
 	}
 	}

+ 4 - 2
Source/Debugger/Plugin.h

@@ -119,8 +119,10 @@ private:
 	ElementLog* log_element;
 	ElementLog* log_element;
 	ElementContextHook* hook_element;
 	ElementContextHook* hook_element;
 
 
-	Core::SharedPtr<Core::SystemInterface> application_interface;
-	Core::SharedPtr<SystemInterface> log_interface;
+	Core::SystemInterface* application_interface;
+	std::unique_ptr<SystemInterface> log_interface;
+
+	std::unique_ptr<Core::ElementInstancer> hook_element_instancer, info_element_instancer, log_element_instancer;
 
 
 	bool render_outlines;
 	bool render_outlines;