-fixed many memory initialization issues

-fixed deadlock on previews thread
-fixed compilation errors on unix
This commit is contained in:
Juan Linietsky 2015-06-06 22:06:58 -03:00
parent 14c4c1b568
commit b524b40fdc
23 changed files with 80 additions and 41 deletions

View File

@ -34,6 +34,7 @@
#include "os/mutex.h"
#include "os/memory.h"
#include "simple_type.h"
#include "print_string.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
@ -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>
@ -675,6 +676,7 @@ public:
if (sync) sync->post();
ss->sem->wait();
print_line("wait");
}
template<class T, class M, class P1, class P2,class R>

View File

@ -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;

View File

@ -324,6 +324,7 @@ int MessageQueue::get_max_buffer_usage() const {
void MessageQueue::flush() {
if (buffer_max_used<buffer_end); {
buffer_max_used=buffer_end;
//statistics();
@ -331,10 +332,15 @@ void MessageQueue::flush() {
uint32_t read_pos=0;
while (read_pos < buffer_end ) {
//lock on each interation, so a call can re-add itself to the message queue
//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
Message *message = (Message*)&buffer[ read_pos ];
Object *target = ObjectDB::get_instance(message->instance_ID);
@ -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_

View File

@ -104,7 +104,7 @@ public:
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;
@ -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)

View File

@ -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()) {
@ -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())

View File

@ -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();

View File

@ -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) {
@ -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;
}

View File

@ -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);
@ -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;

View File

@ -7358,7 +7358,7 @@ void VisualServerRaster::_draw_cursors_and_margins() {
rasterizer->canvas_end_rect();
};
void VisualServerRaster::flush() {
void VisualServerRaster::sync() {
//do none
}

View File

@ -1237,7 +1237,7 @@ public:
/* EVENT QUEUING */
virtual void draw();
virtual void flush();
virtual void sync();
virtual void init();
virtual void finish();

View File

@ -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
@ -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();
}
}

View File

@ -681,7 +681,7 @@ public:
virtual void init();
virtual void finish();
virtual void draw();
virtual void flush();
virtual void sync();
FUNC0RC(bool,has_changed);
/* RENDER INFO */

View File

@ -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);

View File

@ -1097,7 +1097,7 @@ public:
/* 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;

View File

@ -348,7 +348,6 @@ void EditorFileDialog::_push_history() {
}
}
void EditorFileDialog::_item_dc_selected(int p_item) {
@ -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();
}
@ -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;
@ -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;
@ -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);

View File

@ -98,7 +98,7 @@ void EditorResourcePreview::_thread() {
if (queue.size()) {
//print_line("pop from queue");
QueueItem item = queue.front()->get();
queue.pop_front();
@ -106,6 +106,7 @@ void EditorResourcePreview::_thread() {
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");
@ -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();

View File

@ -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");

View File

@ -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();

View File

@ -533,6 +533,7 @@ void CollisionPolygonEditor::_bind_methods() {
CollisionPolygonEditor::CollisionPolygonEditor(EditorNode *p_editor) {
node=NULL;
editor=p_editor;
undo_redo = editor->get_undo_redo();

View File

@ -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();

View File

@ -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();

View File

@ -459,7 +459,7 @@ void NavigationPolygonEditor::_bind_methods() {
}
NavigationPolygonEditor::NavigationPolygonEditor(EditorNode *p_editor) {
node=NULL;
canvas_item_editor=NULL;
editor=p_editor;
undo_redo = editor->get_undo_redo();

View File

@ -2216,6 +2216,14 @@ void SpatialEditorViewport::reset() {
SpatialEditorViewport::SpatialEditorViewport(SpatialEditor *p_spatial_editor, EditorNode *p_editor, int p_index) {
_edit.mode=TRANSFORM_NONE;
_edit.plane=TRANSFORM_VIEW;
_edit.edited_gizmo=0;
_edit.snap=1;
_edit.gizmo_handle=0;
index=p_index;
editor=p_editor;
editor_selection=editor->get_editor_selection();;
@ -3615,6 +3623,8 @@ void SpatialEditor::_default_light_angle_input(const InputEvent& p_event) {
SpatialEditor::SpatialEditor(EditorNode *p_editor) {
gizmo.visible=true;
gizmo.scale=1.0;
viewport_environment = Ref<Environment>( memnew( Environment ) );
undo_redo=p_editor->get_undo_redo();