Skip to content

Commit

Permalink
-fixed many memory initialization issues
Browse files Browse the repository at this point in the history
-fixed deadlock on previews thread
-fixed compilation errors on unix
  • Loading branch information
reduz committed Jun 7, 2015
1 parent 14c4c1b commit b524b40
Show file tree
Hide file tree
Showing 23 changed files with 80 additions and 41 deletions.
4 changes: 3 additions & 1 deletion core/command_queue_mt.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "os/mutex.h"
#include "os/memory.h"
#include "simple_type.h"
#include "print_string.h"
/**
@author Juan Linietsky <[email protected]>
*/
Expand Down Expand Up @@ -174,7 +175,7 @@ class CommandQueueMT {
R* ret;
SyncSemaphore *sync;

virtual void call() { *ret = (instance->*method)(p1); sync->sem->post(); sync->in_use=false; ; }
virtual void call() { *ret = (instance->*method)(p1); sync->sem->post(); print_line("post"); sync->in_use=false; ; }
};

template<class T,class M,class P1,class P2,class R>
Expand Down Expand Up @@ -675,6 +676,7 @@ class CommandQueueMT {

if (sync) sync->post();
ss->sem->wait();
print_line("wait");
}

template<class T, class M, class P1, class P2,class R>
Expand Down
1 change: 1 addition & 0 deletions core/io/resource_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ RES ResourceLoader::load(const String &p_path,const String& p_type_hint,bool p_n
Ref<ResourceImportMetadata> ResourceLoader::load_import_metadata(const String &p_path) {



String local_path;
if (p_path.is_rel_path())
local_path="res://"+p_path;
Expand Down
19 changes: 13 additions & 6 deletions core/message_queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,16 +324,22 @@ int MessageQueue::get_max_buffer_usage() const {

void MessageQueue::flush() {


if (buffer_max_used<buffer_end); {
buffer_max_used=buffer_end;
//statistics();
}

uint32_t read_pos=0;

while (read_pos < buffer_end ) {
//using reverse locking strategy
_THREAD_SAFE_LOCK_

while (read_pos<buffer_end) {

_THREAD_SAFE_UNLOCK_

//lock on each interation, so a call can re-add itself to the message queue
_THREAD_SAFE_LOCK_

Message *message = (Message*)&buffer[ read_pos ];

Expand Down Expand Up @@ -379,16 +385,17 @@ void MessageQueue::flush() {

}

read_pos+=sizeof(Message);
uint32_t advance = sizeof(Message);
if (message->type!=TYPE_NOTIFICATION)
read_pos+=sizeof(Variant)*message->args;
advance+=sizeof(Variant)*message->args;
message->~Message();

_THREAD_SAFE_UNLOCK_
_THREAD_SAFE_LOCK_
read_pos+=advance;

}

_THREAD_SAFE_LOCK_

buffer_end=0; // reset buffer
_THREAD_SAFE_UNLOCK_

Expand Down
4 changes: 2 additions & 2 deletions core/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class Vector {


template <class T_val>
int find(T_val& p_val) const;
int find(const T_val& p_val) const;

void set(int p_index,T p_elem);
T get(int p_index) const;
Expand Down Expand Up @@ -221,7 +221,7 @@ void Vector<T>::_copy_on_write() {
}

template<class T> template<class T_val>
int Vector<T>::find(T_val& p_val) const {
int Vector<T>::find(const T_val &p_val) const {

int ret = -1;
if (size() == 0)
Expand Down
4 changes: 2 additions & 2 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1380,6 +1380,8 @@ bool Main::iteration() {
SpatialSound2DServer::get_singleton()->update( step*time_scale );


VisualServer::get_singleton()->sync(); //sync if still drawing from previous frames.

if (OS::get_singleton()->can_draw()) {

if ((!force_redraw_requested) && OS::get_singleton()->is_in_low_processor_usage_mode()) {
Expand All @@ -1392,8 +1394,6 @@ bool Main::iteration() {
OS::get_singleton()->frames_drawn++;
force_redraw_requested = false;
}
} else {
VisualServer::get_singleton()->flush(); // flush visual commands
}

if (AudioServer::get_singleton())
Expand Down
4 changes: 4 additions & 0 deletions scene/gui/text_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3601,6 +3601,10 @@ TextEdit::TextEdit() {
set_focus_mode(FOCUS_ALL);
_update_caches();
cache.size=Size2(1,1);
cache.row_height=1;
cache.line_spacing=1;
cache.line_number_w=1;

tab_size=4;
text.set_tab_size(tab_size);
text.clear();
Expand Down
3 changes: 2 additions & 1 deletion scene/resources/shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

Shader::Mode Shader::get_mode() const {

return (Mode)VisualServer::get_singleton()->shader_get_mode(shader);
return mode;
}

void Shader::set_code( const String& p_vertex, const String& p_fragment, const String& p_light,int p_fragment_ofs,int p_light_ofs) {
Expand Down Expand Up @@ -203,6 +203,7 @@ void Shader::_bind_methods() {

Shader::Shader(Mode p_mode) {

mode=p_mode;
shader = VisualServer::get_singleton()->shader_create(VS::ShaderMode(p_mode));
params_cache_dirty=true;
}
Expand Down
19 changes: 12 additions & 7 deletions scene/resources/shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,18 @@ class Shader : public Resource {
OBJ_TYPE(Shader,Resource);
OBJ_SAVE_TYPE( Shader );
RES_BASE_EXTENSION("shd");
RID shader;

public:
enum Mode {

MODE_MATERIAL,
MODE_CANVAS_ITEM,
MODE_POST_PROCESS,
MODE_MAX
};
private:
RID shader;
Mode mode;
Dictionary _get_code();
void _set_code(const Dictionary& p_string);

Expand All @@ -55,15 +65,10 @@ class Shader : public Resource {
protected:



static void _bind_methods();
public:
enum Mode {

MODE_MATERIAL,
MODE_CANVAS_ITEM,
MODE_POST_PROCESS,
MODE_MAX
};

//void set_mode(Mode p_mode);
Mode get_mode() const;
Expand Down
2 changes: 1 addition & 1 deletion servers/visual/visual_server_raster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7358,7 +7358,7 @@ void VisualServerRaster::_draw_cursors_and_margins() {
rasterizer->canvas_end_rect();
};

void VisualServerRaster::flush() {
void VisualServerRaster::sync() {
//do none
}

Expand Down
2 changes: 1 addition & 1 deletion servers/visual/visual_server_raster.h
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,7 @@ class VisualServerRaster : public VisualServer {
/* EVENT QUEUING */

virtual void draw();
virtual void flush();
virtual void sync();

virtual void init();
virtual void finish();
Expand Down
12 changes: 8 additions & 4 deletions servers/visual/visual_server_wrap_mt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,19 @@ void VisualServerWrapMT::thread_loop() {

/* EVENT QUEUING */

void VisualServerWrapMT::flush() {
void VisualServerWrapMT::sync() {

if (create_thread) {

/* TODO: sync with the thread */

/*
ERR_FAIL_COND(!draw_mutex);
draw_mutex->lock();
draw_pending++; //cambiar por un saferefcount
draw_mutex->unlock();

command_queue.push( this, &VisualServerWrapMT::thread_flush);
*/
//command_queue.push( this, &VisualServerWrapMT::thread_flush);
} else {

command_queue.flush_all(); //flush all pending from other threads
Expand All @@ -118,15 +121,16 @@ void VisualServerWrapMT::draw() {

if (create_thread) {

/* TODO: Make it draw
ERR_FAIL_COND(!draw_mutex);
draw_mutex->lock();
draw_pending++; //cambiar por un saferefcount
draw_mutex->unlock();
command_queue.push( this, &VisualServerWrapMT::thread_draw);
*/
} else {

command_queue.flush_all(); //flush all pending from other threads
visual_server->draw();
}
}
Expand Down
2 changes: 1 addition & 1 deletion servers/visual/visual_server_wrap_mt.h
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ class VisualServerWrapMT : public VisualServer {
virtual void init();
virtual void finish();
virtual void draw();
virtual void flush();
virtual void sync();
FUNC0RC(bool,has_changed);

/* RENDER INFO */
Expand Down
2 changes: 1 addition & 1 deletion servers/visual_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ void VisualServer::_bind_methods() {
ObjectTypeDB::bind_method(_MD("mesh_add_surface_from_planes"),&VisualServer::mesh_add_surface_from_planes);

ObjectTypeDB::bind_method(_MD("draw"),&VisualServer::draw);
ObjectTypeDB::bind_method(_MD("flush"),&VisualServer::flush);
ObjectTypeDB::bind_method(_MD("sync"),&VisualServer::sync);
ObjectTypeDB::bind_method(_MD("free"),&VisualServer::free);

ObjectTypeDB::bind_method(_MD("set_default_clear_color"),&VisualServer::set_default_clear_color);
Expand Down
2 changes: 1 addition & 1 deletion servers/visual_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,7 @@ class VisualServer : public Object {
/* EVENT QUEUING */

virtual void draw()=0;
virtual void flush()=0;
virtual void sync()=0;
virtual bool has_changed() const=0;
virtual void init()=0;
virtual void finish()=0;
Expand Down
12 changes: 6 additions & 6 deletions tools/editor/editor_file_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,6 @@ void EditorFileDialog::_push_history() {
}

}

void EditorFileDialog::_item_dc_selected(int p_item) {


Expand Down Expand Up @@ -672,7 +671,7 @@ void EditorFileDialog::set_current_dir(const String& p_dir) {
dir_access->change_dir(p_dir);
update_dir();
invalidate();
_push_history();
//_push_history();


}
Expand Down Expand Up @@ -852,8 +851,8 @@ void EditorFileDialog::_favorite_move_up(){
if (current>0 && current<favorites->get_item_count()) {
Vector<String> favorited = EditorSettings::get_singleton()->get_favorite_dirs();

int a_idx=favorited.find(favorites->get_item_metadata(current-1));
int b_idx=favorited.find(favorites->get_item_metadata(current));
int a_idx=favorited.find(String(favorites->get_item_metadata(current-1)));
int b_idx=favorited.find(String(favorites->get_item_metadata(current)));

if (a_idx==-1 || b_idx==-1)
return;
Expand All @@ -873,8 +872,8 @@ void EditorFileDialog::_favorite_move_down(){
if (current>=0 && current<favorites->get_item_count()-1) {
Vector<String> favorited = EditorSettings::get_singleton()->get_favorite_dirs();

int a_idx=favorited.find(favorites->get_item_metadata(current+1));
int b_idx=favorited.find(favorites->get_item_metadata(current));
int a_idx=favorited.find(String(favorites->get_item_metadata(current+1)));
int b_idx=favorited.find(String(favorites->get_item_metadata(current)));

if (a_idx==-1 || b_idx==-1)
return;
Expand Down Expand Up @@ -1143,6 +1142,7 @@ EditorFileDialog::EditorFileDialog() {

show_hidden_files=true;
display_mode=DISPLAY_THUMBNAILS;
local_history_pos=0;

VBoxContainer *vbc = memnew( VBoxContainer );
add_child(vbc);
Expand Down
5 changes: 3 additions & 2 deletions tools/editor/editor_resource_preview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,15 @@ void EditorResourcePreview::_thread() {

if (queue.size()) {

//print_line("pop from queue");


QueueItem item = queue.front()->get();
queue.pop_front();
preview_mutex->unlock();

Ref<Texture> texture;

//print_line("pop from queue "+item.path);

uint64_t modtime = FileAccess::get_modified_time(item.path);
int thumbnail_size = EditorSettings::get_singleton()->get("file_dialog/thumbnail_size");
Expand Down Expand Up @@ -206,7 +207,7 @@ void EditorResourcePreview::queue_resource_preview(const String& p_path, Object*

}

//print_line("send to thread");
//print_line("send to thread "+p_path);
QueueItem item;
item.function=p_receiver_func;
item.id=p_receiver->get_instance_ID();
Expand Down
4 changes: 2 additions & 2 deletions tools/editor/io_plugins/editor_texture_import_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -600,9 +600,9 @@ EditorTextureImportDialog::EditorTextureImportDialog(EditorTextureImportPlugin*
file_select->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
add_child(file_select);
if (!large)
file_select->set_mode(FileDialog::MODE_OPEN_FILES);
file_select->set_mode(EditorFileDialog::MODE_OPEN_FILES);
else
file_select->set_mode(FileDialog::MODE_OPEN_FILE);
file_select->set_mode(EditorFileDialog::MODE_OPEN_FILE);
file_select->connect("files_selected", this,"_choose_files");
file_select->connect("file_selected", this,"_choose_file");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ void CollisionPolygon2DEditor::_bind_methods() {

CollisionPolygon2DEditor::CollisionPolygon2DEditor(EditorNode *p_editor) {

node=NULL;
canvas_item_editor=NULL;
editor=p_editor;
undo_redo = editor->get_undo_redo();
Expand Down
1 change: 1 addition & 0 deletions tools/editor/plugins/collision_polygon_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,7 @@ void CollisionPolygonEditor::_bind_methods() {
CollisionPolygonEditor::CollisionPolygonEditor(EditorNode *p_editor) {


node=NULL;
editor=p_editor;
undo_redo = editor->get_undo_redo();

Expand Down
5 changes: 3 additions & 2 deletions tools/editor/plugins/editor_preview_plugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,15 @@ EditorTexturePreviewPlugin::EditorTexturePreviewPlugin() {

Ref<Texture> EditorPackedScenePreviewPlugin::_gen_from_imd(Ref<ResourceImportMetadata> p_imd) {

if (p_imd.is_null())
if (p_imd.is_null()) {
return Ref<Texture>();
}

if (!p_imd->has_option("thumbnail"))
return Ref<Texture>();

Variant tn = p_imd->get_option("thumbnail");
print_line(Variant::get_type_name(tn.get_type()));
//print_line(Variant::get_type_name(tn.get_type()));
DVector<uint8_t> thumbnail = tn;

int len = thumbnail.size();
Expand Down
1 change: 1 addition & 0 deletions tools/editor/plugins/light_occluder_2d_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ void LightOccluder2DEditor::_bind_methods() {

LightOccluder2DEditor::LightOccluder2DEditor(EditorNode *p_editor) {

node=NULL;
canvas_item_editor=NULL;
editor=p_editor;
undo_redo = editor->get_undo_redo();
Expand Down
Loading

0 comments on commit b524b40

Please sign in to comment.