New print_screen bugs - General Discussion and Assistance - CHDK Forum supplierdeeply

New print_screen bugs

  • 7 Replies
  • 4875 Views
*

Offline lapser

  • *****
  • 1093
New print_screen bugs
« on: 27 / November / 2012, 20:49:40 »
Advertisements
The print_screen function was recently changed to allow appending. Great idea, but it introduced 2 new problems, which should be easy to fix.

I use this method to create a unique file:

print_screen(os.date("%H%M"))

Unfortunately, it now throws an error saying it's not an integer type. A line in luascript.c was change from:

    script_print_screen_statement( luaL_checknumber( L, 1 )+1000);
to
    script_print_screen_statement( luaL_checknumber( L, 1 ));

Apparently, the old way converts the argument to (int) before calling the function, while the new way doesn't.
====
Another bug is that a line feed screen character appears at the end of lines in the camera console when print_screen is active. There may be an extra line feed in the file too. I think the bug comes from this code in script.c:

void script_console_add_line(const char *str)
{
    console_add_line(str);

    if (print_screen_p && (print_screen_d >= 0)) {
        char nl = '\n';

It may be something else, but it's probably in this area.

But as long as you're changing print_screen, it would be nice if you could add the option to specify the complete file name, and not just 4 digits. Maybe if you enter a string more than 4 characters, it could use that for the file name instead of pre-pending "log_" and ending with ".txt".

I'm working on shot_histo right now, but I could probably figure this out and add it when I finish, if needed.
EOS-M3_120f / SX50_100b / SX260_101a / G1X_100g / D20_100b
https://www.youtube.com/user/DrLapser/videos

Re: New print_screen bugs
« Reply #1 on: 27 / November / 2012, 21:48:20 »
Unfortunately, it now throws an error saying it's not an integer type. A line in luascript.c was change from:
    script_print_screen_statement( luaL_checknumber( L, 1 )+1000);
to
    script_print_screen_statement( luaL_checknumber( L, 1 ));

Apparently, the old way converts the argument to (int) before calling the function, while the new way doesn't.
With all due respect,  it looks like you were passing a string to a function expecting an integer,  and a bug / side effect in the old code allowed that ?  Reyalp can probably better explain how mixed types are handled in Lua ...

Ported :   A1200    SD940   G10    Powershot N    G16

*

Offline reyalp

  • ******
  • 14118
Re: New print_screen bugs
« Reply #2 on: 28 / November / 2012, 00:42:02 »
Unfortunately, it now throws an error saying it's not an integer type. A line in luascript.c was change from:
    script_print_screen_statement( luaL_checknumber( L, 1 )+1000);
to
    script_print_screen_statement( luaL_checknumber( L, 1 ));

Apparently, the old way converts the argument to (int) before calling the function, while the new way doesn't.
With all due respect,  it looks like you were passing a string to a function expecting an integer,  and a bug / side effect in the old code allowed that ?  Reyalp can probably better explain how mixed types are handled in Lua ...
Whatever the source of the changed behavior, this code quote above isn't it. In both cases, checknumber is checking the same value. Adding 1000 it in C code cannot possibly have any effect on that.

Lua generally accepts a string convertible to a number as a number. While the docs don't spell it out, this applies to luaL_checknumber as well. If you want to force a string to number conversion, you can use tonumber() in lua code.

edit
Code: [Select]
connected: Canon PowerShot D10, max packet size 512
con 15> =print_screen(os.date('%H%M')) ; print('hi') print_screen(0)
con 1> ls CHDK/LOGS
...
LOG_2208.TXT
con 2> =r='';for s in io.lines('A/CHDK/LOGS/LOG_2208.TXT') do r=r..s end return r
3:return:'hi'
con 3>
« Last Edit: 28 / November / 2012, 01:07:49 by reyalp »
Don't forget what the H stands for.

*

Offline lapser

  • *****
  • 1093
Re: New print_screen bugs
« Reply #3 on: 28 / November / 2012, 13:29:03 »
OK, you guys are right, that line couldn't be the problem. I can't reproduce the bug with a simple script. Everything works fine, including:
print_screen(os.date("%H%M")) and print_screen(-os.date("%H%M"))

So checknumber must be returning an int when passed a string that can be converted to a valid number. No type casting is needed.

I probably triggered something by closing and reopening the file too much, using the new append mode, to avoid losing the log with battery shut down. I did try all the tonumber stuff, and nothing worked, when I saw the bug. Sorry for assuming it was in the C code.

The script that triggered the "problem" went something like this. Unfortunately, I've already removed the print statements since I'm using Lua writes anyway. Maybe the problem comes from trying to re-open a file before it's finished closing? I do "flush" before closing my lua log file. Does the new print_screen do that?

repeat
  --take picture
  print_screen(-1)
  print("lots of picture data")
  print_screen(false)
until false

If and when I can reproduce the problem, I'll check it out completely before posting.
EOS-M3_120f / SX50_100b / SX260_101a / G1X_100g / D20_100b
https://www.youtube.com/user/DrLapser/videos


Re: New print_screen bugs
« Reply #4 on: 28 / November / 2012, 21:21:20 »
I probably triggered something by closing and reopening the file too much, using the new append mode, to avoid losing the log with battery shut down. I did try all the tonumber stuff, and nothing worked, when I saw the bug.
I ran into the same problem with some similar code.  In discussion with reyalp on IRC, he pointed out that its the same problem SticK was having.  Its an issue with doing the shoot() and print_screen print() too close together - the system apparently runs out of file handles. When I slowed down the shooting loop by about 1 second (from 3 seconds to 4) then the crash stopped.   And I'm doing thousands of write operations like that over a 4 to 8 hour period so its not the quantity - its the timing.
Ported :   A1200    SD940   G10    Powershot N    G16

*

Offline lapser

  • *****
  • 1093
Re: New print_screen bugs
« Reply #5 on: 28 / November / 2012, 23:20:11 »
I ran into the same problem with some similar code.  In discussion with reyalp on IRC, he pointed out that its the same problem SticK was having.  Its an issue with doing the shoot() and print_screen print() too close together - the system apparently runs out of file handles. When I slowed down the shooting loop by about 1 second (from 3 seconds to 4) then the crash stopped.   And I'm doing thousands of write operations like that over a 4 to 8 hour period so its not the quantity - its the timing.
I'm also saving hundreds of files for testing, so I end up with several thousand on the card. This could have been related too. I recall a discussion of memory problems when leaving a camera running for days at a time. Canon uses memory for each picture on the card, and didn't expect multi gigabyte card, I suppose. I noticed the system slowing down with too many picture on card. Also, 2 weird bugs showed up that went away when I deleted pictures:

1. The USB connection fails. This also happened without CHDK, and a Canon note said it could be from too many pictures on the card.

2. The time stamp of new log and other files is always 01/01/2000 0000 hours (or 12:00 am 12/31/2000). The time stamp bug went away when I deleted all the pictures off the card.
EOS-M3_120f / SX50_100b / SX260_101a / G1X_100g / D20_100b
https://www.youtube.com/user/DrLapser/videos

*

Offline reyalp

  • ******
  • 14118
Re: New print_screen bugs
« Reply #6 on: 28 / November / 2012, 23:26:41 »
I probably triggered something by closing and reopening the file too much, using the new append mode, to avoid losing the log with battery shut down. I did try all the tonumber stuff, and nothing worked, when I saw the bug.
I ran into the same problem with some similar code.  In discussion with reyalp on IRC, he pointed out that its the same problem SticK was having.  Its an issue with doing the shoot() and print_screen print() too close together - the system apparently runs out of file handles.
This specific problem will cause the camera to shut down with an assert. It's highly unlikely to produce other symptoms.
Don't forget what the H stands for.

Re: New print_screen bugs
« Reply #7 on: 28 / November / 2012, 23:30:33 »
I recall a discussion of memory problems when leaving a camera running for days at a time. Canon uses memory for each picture on the card, and didn't expect multi gigabyte card, I suppose. I noticed the system slowing down with too many picture on card. Also, 2 weird bugs showed up that went away when I deleted pictures:
There is also this hack :

Code: [Select]
#define CAM_STARTUP_CRASH_FILE_OPEN_FIX 1 in platform_camera.h which I needed on some of my cameras only when there are a lot of jpg's in the SD card.  It introduces a start-up delay that I believe gives the Canon startup code time to figure out what's on the SD card - a process that gets slower as the more files are added to the card.

Ported :   A1200    SD940   G10    Powershot N    G16


 

Related Topics


SimplePortal 2.3.6 © 2008-2014, SimplePortal