I have some Emgu code that was working in both debug and release builds. Somewhere along the way, it quit working, but I was deep into adding something else so I didn't pursue it at the time.
When I did finally getting around to trying to fix it, I find that a release build works, but not a debug build. Between the time it was working, and not, I did not change any references or referenced DLLs. I spent some time investigating that anyhow as I had read somewhere that open CV has some trouble debug vs release somewhere, but never found anything.
I just applied the last version of Emgu, and the same problem exists; works perfect in release, not at all in debug.
The relevant code snippet is;
var filteredFrame =
channels[0].SmoothGaussian(VisionData.SmoothGaussians)
.Erode(VisionData.Erodes)
.Dilate(VisionData.Dialates);
using (MemStorage stor = new MemStorage())
for (
Contour<System.Drawing.Point> contour =
filteredFrame.FindContours(Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_SIMPLE,
Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_EXTERNAL, stor);
contour != null;
contour = contour.HNext)
if ((contour.Area > (VisionData.ContourMinArea * VisionData.ContourMinArea))
&& (contour.Area < (VisionData.ContourMaxArea * VisionData.ContourMaxArea)))
CurrentFrame.Draw(contour.GetMinAreaRect(), RectBrush, 2);
d.InvokeAsync(() =>
{
DataModel.CameraImageSource = Emgu.CV.WPF.BitmapSourceConvert.ToBitmapSource(CurrentFrame);
DataModel.FilteredImageSource = Emgu.CV.WPF.BitmapSourceConvert.ToBitmapSource(filteredFrame);
});
The input filtered frame(image) looks identical in both debug and release.
Related
I am trying to add a MapIcon to my Bing maps control. When I am running the application in my debugging environment on visual studio I don't have any issues. However once I build my app package and run it, adding a map Icon crashes the application and throws this an exception that reads:
"Unable to cast object of type Windows.UI.Xaml.Controls.Maps.MapIcon to type Windows.UI.Xaml.Controls.Maps.IMapElement4"
Here is the simple code that instantiates the MapIcon. It is important to know that I do not have any issues adding these map Icons in debug mode. The problem only exists once the app package has been built and run. I was able to pinpoint the exception using a try/catch to display the exception while the released app is running. If anyone can help me to get rid of this exception, or have any advice for a work around, it would be much appreciated
MapIcon messageicon2_2 = new MapIcon
{
Location = message_position,
NormalizedAnchorPoint = new Point(0.5, 1.0),
ZIndex = 0,
Title = "msg " + count + "(2.2)",
IsEnabled = true,
CollisionBehaviorDesired = MapElementCollisionBehavior.RemainVisible
};
MyWaypoints.Add(messageicon2_2);
messageLayer.MapElements = MyWaypoints;
[EDIT To Clarify]: I know that this bug is coming specifically from the instantiation of the Mapicon. This code works perfectly fine when it is released and run on a Windows 10 17134 machine.... The machine that I need it to run is Windows 10 16299. This machine can not be updated to a newer version of windows. I am in need of a way to display these map icons on this older release of windows.
The exception points to the IsEnabled property which was added to MapElement for Windows OS Version 1803 (17134). See MapElement.IsEnabled Property.
I know the exception is not the most helpful, but maybe there was some other warning about it that got missed?
For errors like this, you can either remove all uses of the missing API and/or make sure to write version adaptive code that can run on the lowest OS version, while also taking advantage of the selected features that are available only on certain OS versions.
Specifically you can do something like:
var messageicon2_2= new MapIcon
{
Location = message_position,
NormalizedAnchorPoint = new Point(0.5, 1.0),
ZIndex = 0,
Title = "msg " + count + "(2.2)",
CollisionBehaviorDesired = MapElementCollisionBehavior.RemainVisible
};
if (ApiInformation.IsPropertyPresent("Windows.UI.Xaml.Controls.Maps.MapElement", "IsEnabled"))
{
messageicon2_2.IsEnabled = true;
}
MyWaypoints.Add(messageicon2_2);
messageLayer.MapElements = MyWaypoints;
I have been at this for quite a while. I am using C# for Serious Game Programing, and am working on the SoundManager code found in Chapter 9 of the book, if you want an exact reference. The Code is setting up a sound manager using OpenAl, and I am having a problem with the Alut interface (if that is the right word for what it is). Here is the code that I am working on:
public void LoadSound(string soundId, string path)
{
int buffer = -1;
Al.alGenBuffers(1, out buffer);
int errorCode = Al.alGetError();
System.Diagnostics.Debug.Assert(errorCode == Al.AL_NO_ERROR);
int format;
float frequency;
int size;
System.Diagnostics.Debug.Assert(File.Exists(path));
IntPtr data = Alut.alutLoadMemoryFromFile(path, out format, out size, out frequency);
int errorCode2 = Alut.alutGetError();
//string errorCodeString = Alut.alutGetErrorString(errorCode2);
//System.Diagnostics.Debug.Assert(errorCode2 != Alut.ALUT_ERROR_NO_ERROR);
//System.Diagnostics.Debug.Assert(data != IntPtr.Zero));
//System.Diagnostics.Debug.Write(errorCode2);
Al.alBufferData(buffer, format, data, size, (int)frequency);
_soundIdentifier.Add(soundId, new SoundSource(buffer, path));
}
The issue is this line right here: System.Diagnostics.Debug.Assert(data != IntPtr.Zero));. When this line is not commented out, it always fails. I did have it work, and do not know what I did to change it, and it stopped working. I have posted about this on another post here: Load sound problem in OpenAL
I have looked all over, and from what I can gather, the issue is with the way that OpenAl is working on my system. To that end, I have uninstalled the Tao Framework that I am using to run OpenAl, and reinstalled. I have also done a system restore to as many points as I have back. I have thought about nuking my whole system, and starting fresh, but a want to avoid this if I can.
I Also have found this link http://distro.ibiblio.org/rootlinux/rootlinux-ports/more/freealut/freealut-1.1.0/doc/alut.html#ErrorHandling that has helped me understand more about Alut, but have been unable to get an alut.dll from it, and cannot get any errors to display. This code:
int errorCode2 = Alut.alutGetError();
//string errorCodeString = Alut.alutGetErrorString(errorCode2);
//System.Diagnostics.Debug.Assert(errorCode2 != Alut.ALUT_ERROR_NO_ERROR);
System.Diagnostics.Debug.Write(errorCode2);
Is my attempt to find out the exact error. If I write the code like:
int errorCode2 = Alut.alutGetError();
//string errorCodeString = Alut.alutGetErrorString(errorCode2);
System.Diagnostics.Debug.Assert(errorCode2 != Alut.ALUT_ERROR_NO_ERROR);
System.Diagnostics.Debug.Write(errorCode2);
I may be using the code all wrong to the find the exact error, as I am still learning c#.
Here is what I am looking for:
1)Is this a syntax error or an error with my system
2)If it is an error in my system, are there files that I am not removing when I try to do an uninstall of OpenAL to refresh all the files.
3)How do I get the alutGetError() code to display in such a way that I can actually read what it is.
Thank you for any help beforehand.
I recently ran into the same problem while going through that book and was able to figure it out by logging the error to the output window, notice I through the console.writeline in there.
After doing that I checked the output window which gave me the error code 519. After looking all over I saw a few forum posts recommending I re-install openAl to fix this issue which did the trick, all the links I found didn't work to the download so I had to hunt around but softTonic had the one that worked for me on my windows 7 machine http://openal.en.softonic.com/download
IntPtr data = Alut.alutLoadMemoryFromFile(path, out format, out size, out frequency);
var error= Alut.alutGetError();
Console.WriteLine(error);
//System.Diagnostics.Debug.Assert(data != IntPtr.Zero);
Hope this helps,
helpdevelop
Okay. Well, I know this question has a good chance of being closed within the first 10 minutes, but I am going to ask it anyways for I have spent almost day and an half trying to find a solution. Still, I can't figure this one out. There is not much info on this on the Internet not even on the HASP (safenet) website although they have demos.
I have a HASP HL USB dongle. I try to convert their demo and test run it but for the life of me I simply can't get it to login even. It keeps raising Aladdin.HASP.HaspStatus.HaspDotNetDllBroken exception.
However, if I run the C version of their demo, it works perfectly.
Here is the Csharp version of my code:
Aladdin.HASP;
HASP myHasp = new HASP();
var thestatus = myHasp.Login(vender_code);
myHasp.Logout;
I would like to login to USB HASP and get its HaspID and the settings in its memory.
Thanks in advance,
It might be that you aren't having all dependencies for the HASP runtime. I'm packing with the app:
hasp_windows_NNNNN.dll (NNNNN = your number)
hasp_net_windows.dll
MSVCR71.DLL (added manually)
msvc runtime 80
One runtime library is required by HASP and it doesn't tell you which one unless you put it in the DEPENDS.EXE utility (you probably have you on your Visual Studio installation).
To log in (and read some bytes):
byte[] key = new byte[16];
HaspFeature feature = HaspFeature.FromFeature(4);
string vendorCode = "your vendor string, get it from your tools";
Hasp hasp = new Hasp(feature);
HaspStatus status = hasp.Login(vendorCode);
if (HaspStatus.StatusOk != status)
{
// no license to run
return false;
}
else
{
// read some memory here
HaspFile mem = hasp.GetFile(HaspFileId.ReadOnly);
mem.Read(key, 0, 16);
status = hasp.Logout();
if (HaspStatus.StatusOk != status)
{
//handle error
}
}
Hope it helps. My HASPed software works like a charm. BTW, wasn't able to put envelope around .NET app under no combination of settings.
I'm using Unity (3.4) Monodevelop (2.4.2) and it's not executing the code properly when I step through it in the debugger. Here's a link to the video that shows it, please run it at 720p and fullscreen it...
http://www.youtube.com/watch?v=LGN7kxMUqjA
Also, here are some screenshots showing the debugger displaying really strange values when I mouseover a variable. Here's what it looks like when it correctly shows the value of the xSectionPixel in the first if block...
And here's what it looks like when it incorrectly shows the value of the xSectionPixel in the second if block...
This is also the line of code where it starts executing code incorrectly.
What would cause this?
I've tried reinstalling the tools, using a fresh copy of the code from the repository, I even set it all up on a different computer with a different OS (Win 7) and it always does the same thing. Doesn't that mean it has to be my code then?
It's also worth noting that I'm using SVN to push/pull the code from a repository and my local copy exists in my Dropbox folder.
Thanks so much in advance for your wisdom! Here's the code as well if you can spot anything that might be breaking things (i.e. the way I'm using floats and ints maybe?)
Vector2 textureCoordToHexGridCoord(int textX, int textY)
{
Vector2 hexGridCoord = new Vector2();
float m = hexH / hexR;
int xsection = (int)(textX / (hexH + hexS));
int ysection = (int)(textY / (2 * hexR));
int xSectionPixel = (int)(textX - xsection * (hexH + hexS));
int ySectionPixel = (int)(textY - ysection * (2 * hexR));
//A Section
if(xsection % 2 == 0)
{
hexGridCoord.x = xsection;
hexGridCoord.y = ysection;
if(xSectionPixel < (hexH - ySectionPixel * m))
{
hexGridCoord.x--;
hexGridCoord.y--;
}
if(xSectionPixel < (-hexH + ySectionPixel * m))
{
hexGridCoord.x--;
}
}
//B Section
else
{
if(xSectionPixel >= hexR)
{
if(ySectionPixel < (2 * hexH - xSectionPixel * m))
{
hexGridCoord.x = xsection - 1;
hexGridCoord.y = ysection - 1;
}
else
{
hexGridCoord.x = xsection;
//hexGridCoord.y = ysection;
hexGridCoord.y = ysection - 1;
}
}
if(xSectionPixel < hexR)
{
if(ySectionPixel < (xSectionPixel * m))
{
hexGridCoord.x = xsection;
//hexGridCoord.y = ysection - 1;
hexGridCoord.y = ysection;
}
else
{
hexGridCoord.x = xsection - 1;
hexGridCoord.y = ysection;
}
}
}
return hexGridCoord;
}
I have no specific experience with the frameworks you use, but I do have a lot of experience with debuggers.
The debugger behavior you see can happen in one of two scenarios (that I can think of...)
The symbol files and executing code are not synchronized with your source code, usually the IDE should detect that, but it some cases it doesn't, the solution is to delete all binaries, recompile and try again.
A bug in the debugger or the debugger extension (used to debug in the specific environment your are in, i.e. unity/monodevelop).
If you are unable to resolve it, I would add logging to your code and use it to really understand what happens.
I saw similar behavior on MonoDevelop with WinForms applications, solved with reinstalling debugger.
Have you tried that or using Visual Studio to verify that the problem is in the code?
Do you have optimizations turned on? If so, does disabling them make stepping any less erratic?
Enabling optimizations is one thing I can think of that no one else has mentioned yet that could potentially cause what you are seeing.
Can you try removing you breakpoints, setting a new one, and stepping through the code?
The reason I ask is there are ways that you can set values using breakpoints. A very similar thing happened to me and was convinced that there was a compiler bug. After stepping through the CLR and number of other things with no answer, we stumbled across a breakpoint that was set earlier for testing, and never removed.
That kind of behavior usually happens to me when I'm debugging a multithreaded part of an application.
What happens is that while you debug several threads at once, the debugger in visual studio keeps switching between them without notifying you by default.
Now since threads are not executing the same lines at the same time, you got unexpected "jumps".
I believe it is widely used in game developpement, so in your case you got two choices:
1) Make only one thread run while you make your debugging.
2) Make unit tests <= That's the "best practice".
You can start by having a look at NUnit
The first issue most likely has something to do with the sequence points in the JITed code. These are the points where the debugger can stop. They're computed by the runtime based on the IL and debug symbols generated by the compiler, therefore this is most likely a runtime or compiler bug. I don't know what version of the Mono runtime and compiler is being used by Unity, but it's quite that this has been fixed in a newer version. If you can reproduce this using a "normal" console app using the latest official MonoDevelop and Mono 2.10.x, please file a bug at http://bugzilla.xamarin.com with a test case. If not, please ask Unity to upgrade their version of Mono.
The second issue looks like an issue in MonoDevelop's expression resolver that's used to resolve the symbol under the mouse. This may have been fixed in a newer version of MonoDevelop - likewise, please try to repro with the official MonoDevelop 2.8.4, and file a bug if it's still an issue.
My plan:
I'm trying to setup my C# project to communicate with Nodebox to call a certain function which populates a graph and draws it in a new window.
Current situation: [fixed... see Update2]
I have already included all python-modules needed, but im still getting a
Library 'GL' not found
it seems that the pyglet module needs a reference to GL/gl.h, but can't find it due to IronPython behaviour.
Requirement:
The project needs to stay as small as possible without installing new packages. Thats why i have copied all my modules into the project-folder and would like to keep it that or a similar way.
My question:
Is there a certain workaround for my problem or a fix for the library-folder missmatch.
Have read some articles about Tao-Opengl and OpenTK but can't find a good solution.
Update1:
Updated my sourcecode with a small pyglet window-rendering example. Problem is in pyglet and referenced c-Objects. How do i include them in my c# project to be called? No idea so far... experimenting alittle now. Keeping you updated.
SampleCode C#:
ScriptRuntimeSetup setup = Python.CreateRuntimeSetup(null);
ScriptRuntime runtime = new ScriptRuntime(setup);
ScriptEngine engine = Python.GetEngine(runtime);
ScriptSource source = engine.CreateScriptSourceFromFile("test.py");
ScriptScope scope = engine.CreateScope();
source.Execute(scope);
SampleCode Python (test.py):
from nodebox.graphics import *
from nodebox.graphics.physics import Vector, Boid, Flock, Obstacle
flock = Flock(50, x=-50, y=-50, width=700, height=400)
flock.sight(80)
def draw(canvas):
canvas.clear()
flock.update(separation=0.4, cohesion=0.6, alignment=0.1, teleport=True)
for boid in flock:
push()
translate(boid.x, boid.y)
scale(0.5 + boid.depth)
rotate(boid.heading)
arrow(0, 0, 15)
pop()
canvas.size = 600, 300
def main(canvas):
canvas.run(draw)
Update2:
Line 139 [pyglet/lib.py] sys.platform is not win32... there was the error. Fixed it by just using the line:
from pyglet.gl.lib_wgl import link_GL, link_GLU, link_WGL
Now the following Error:
'module' object has no attribute '_getframe'
Kind of a pain to fix it. Updating with results...
Update3:
Fixed by adding following line right after first line in C#-Code:
setup.Options["Frames"] = true;
Current Problem:
No module named unicodedata, but in Python26/DLLs is only a *.pyd file`. So.. how do i implement it now?!
Update4:
Fixed by surfing: link text and adding unicodedata.py and '.pyd to C# Projectfolder.
Current Problem:
'libGL.so not found'... guys.. im almost giving up on nodebox for C#.. to be continued
Update5:
i gave up :/ workaround: c# communicating with nodebox over xml and filesystemwatchers. Not optimal, but case solved.
-X:Frames enables the frames option as runtime (it slows code down a little to have access to the Python frames all the time).
To enable frames when hosting you just need to do:
ScriptRuntimeSetup setup = Python.CreateRuntimeSetup(new Dictionary<string, object>() {
{ "Frames", true }
});
Instead of the null that you're passing now. That's just creating a new dictionary for the options dictionary w/ the contents "Frames" set to true. You can set other options in there as well and in general the -X:Name option is the same here as it is for the command line.